fix(sessions): preserve date filter on page navigation and reset page on date change
This commit is contained in:
3 files changed
+25
-15
No files matched your search
@@ -56,7 +56,7 @@ export function DataGrid({
|
||||
(page: number) => {
|
||||
router.push(updateParams({ search, page }));
|
||||
},
|
||||
[search],
|
||||
[search, updateParams],
|
||||
);
|
||||
|
||||
const child = data ? (typeof children === 'function' ? children(data) : children) : null;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { usePathname, useRouter, useSearchParams } from 'next/navigation';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useCallback, useEffect, useState } from 'react';
|
||||
import { buildPath } from '@/lib/url';
|
||||
|
||||
export function useNavigation() {
|
||||
@@ -13,20 +13,29 @@ export function useNavigation() {
|
||||
const [, boardId] = pathname.match(/\/boards\/([a-f0-9-]+)/) || [];
|
||||
const [queryParams, setQueryParams] = useState(Object.fromEntries(searchParams));
|
||||
|
||||
const updateParams = (params?: Record<string, string | number>) => {
|
||||
return buildPath(pathname, { ...queryParams, ...params });
|
||||
};
|
||||
const updateParams = useCallback(
|
||||
(params?: Record<string, string | number>) => {
|
||||
return buildPath(pathname, { ...queryParams, ...params });
|
||||
},
|
||||
[pathname, queryParams],
|
||||
);
|
||||
|
||||
const replaceParams = (params?: Record<string, string | number>) => {
|
||||
return buildPath(pathname, params);
|
||||
};
|
||||
const replaceParams = useCallback(
|
||||
(params?: Record<string, string | number>) => {
|
||||
return buildPath(pathname, params);
|
||||
},
|
||||
[pathname],
|
||||
);
|
||||
|
||||
const renderUrl = (path: string, params?: Record<string, string | number> | false) => {
|
||||
return buildPath(
|
||||
teamId ? `/teams/${teamId}${path}` : path,
|
||||
params === false ? {} : { ...queryParams, ...params },
|
||||
);
|
||||
};
|
||||
const renderUrl = useCallback(
|
||||
(path: string, params?: Record<string, string | number> | false) => {
|
||||
return buildPath(
|
||||
teamId ? `/teams/${teamId}${path}` : path,
|
||||
params === false ? {} : { ...queryParams, ...params },
|
||||
);
|
||||
},
|
||||
[teamId, queryParams],
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
setQueryParams(Object.fromEntries(searchParams));
|
||||
|
||||
@@ -40,10 +40,11 @@ export function WebsiteDateFilter({
|
||||
updateParams({
|
||||
date: `${getDateRangeValue(websiteDateRange.startDate, websiteDateRange.endDate)}:all`,
|
||||
offset: undefined,
|
||||
page: 1,
|
||||
}),
|
||||
);
|
||||
} else {
|
||||
router.push(updateParams({ date, offset: undefined, unit: undefined }));
|
||||
router.push(updateParams({ date, offset: undefined, unit: undefined, page: 1 }));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in new issue
Block a user