feat: persist hydrogen order pages
This commit is contained in:
@@ -12,6 +12,7 @@ export interface HydrogenDrillContext {
|
||||
startDate?: string;
|
||||
endDate?: string;
|
||||
selectedDate?: string;
|
||||
orderPage?: number;
|
||||
}
|
||||
|
||||
interface LocationParts {
|
||||
@@ -74,6 +75,8 @@ export function parseHydrogenDrillContext(search: string): HydrogenDrillContext
|
||||
const rangeEnd = startDate && endDate ? (startDate <= endDate ? endDate : startDate) : undefined;
|
||||
if (selectedDate && (!rangeStart || !rangeEnd || (selectedDate >= rangeStart && selectedDate <= rangeEnd))) {
|
||||
context.selectedDate = selectedDate;
|
||||
const orderPage = positiveInteger(params.get('hydrogenPage'));
|
||||
if (orderPage && orderPage > 1) context.orderPage = orderPage;
|
||||
}
|
||||
return context;
|
||||
}
|
||||
@@ -93,6 +96,7 @@ export function buildHydrogenDrillUrl(
|
||||
'hydrogenStart',
|
||||
'hydrogenEnd',
|
||||
'hydrogenDate',
|
||||
'hydrogenPage',
|
||||
]) {
|
||||
params.delete(key);
|
||||
}
|
||||
@@ -110,6 +114,9 @@ export function buildHydrogenDrillUrl(
|
||||
if (context.startDate) params.set('hydrogenStart', context.startDate);
|
||||
if (context.endDate) params.set('hydrogenEnd', context.endDate);
|
||||
if (context.selectedDate) params.set('hydrogenDate', context.selectedDate);
|
||||
if (context.selectedDate && context.orderPage && context.orderPage > 1) {
|
||||
params.set('hydrogenPage', String(context.orderPage));
|
||||
}
|
||||
|
||||
const query = params.toString();
|
||||
return `${location.pathname}${query ? `?${query}` : ''}${location.hash}`;
|
||||
|
||||
Reference in New Issue
Block a user