Skip to content

Commit 7ced0b4

Browse files
committed
fix(search): preserve pagination on page refresh
1 parent 7d9f03e commit 7ced0b4

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/views/search/context/pagination-context.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
} from 'react';
99
import { useRouter } from 'next/router';
1010
import { defaultQuery } from '../config/defaultQuery';
11-
import { useSearchTabsContext } from './search-tabs-context';
11+
import { DEFAULT_TAB_ID, useSearchTabsContext } from './search-tabs-context';
1212

1313
export type PaginationState = {
1414
from: number;
@@ -59,7 +59,7 @@ export const PaginationProvider = ({ children }: { children: ReactNode }) => {
5959
const urlFrom = parseInt(router.query.from as string);
6060
const urlSize = parseInt(router.query.size as string);
6161
const urlSort = router.query.sort as string;
62-
const urlTab = router.query.tab as string;
62+
const urlTab = (router.query.tab || DEFAULT_TAB_ID) as string;
6363

6464
if (!isNaN(urlFrom) && urlTab) {
6565
setPaginationByTab(prev => ({

src/views/search/context/search-tabs-context.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ interface SearchContextValue {
1212
setFilters: (filters: Record<string, string[]>) => void;
1313
}
1414

15+
export const DEFAULT_TAB_ID = tabs.find(t => t.isDefault)?.id || 'd';
16+
1517
const SearchContext = createContext<SearchContextValue | undefined>(undefined);
1618

1719
/**

0 commit comments

Comments
 (0)