From 9057ae0d77e5e13214dbdbb9cf9ff9f5320087fb Mon Sep 17 00:00:00 2001 From: samwisekind Date: Sun, 27 Oct 2024 12:43:03 +0000 Subject: [PATCH] Update --- src/pages/research/catalogues/index.tsx | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/pages/research/catalogues/index.tsx b/src/pages/research/catalogues/index.tsx index b41de2a..021d6ba 100644 --- a/src/pages/research/catalogues/index.tsx +++ b/src/pages/research/catalogues/index.tsx @@ -25,12 +25,17 @@ interface PageProps { const Page: NextPage = ({ pageData, }: PageProps) => { + let initCatalogue = Catalogues.BottlenoseDolphin; let initPage = 1; let initSearch = ''; - let initCatalogue = Catalogues.BottlenoseDolphin; const searchParams = useSearchParams(); + const paramCatalogue = searchParams.get('catalogue'); + if (paramCatalogue && Object.values(Catalogues).includes(paramCatalogue as any)) { + initCatalogue = paramCatalogue as Catalogues; + } + const paramPage = searchParams.get('page'); if (paramPage) { initPage = parseInt(paramPage) @@ -41,14 +46,9 @@ const Page: NextPage = ({ initSearch = paramSearch; } - const paramCatalogue = searchParams.get('catalogue'); - if (paramCatalogue && Object.values(Catalogues).includes(paramCatalogue as any)) { - initCatalogue = paramCatalogue as Catalogues; - } - + const [catalogue, setCatalogue] = useState(initCatalogue); const [page, setPage] = useState(initPage); const [search, setSearch] = useState(initSearch); - const [catalogue, setCatalogue] = useState(initCatalogue); const [searchText, setSearchText] = useState(''); const [data, setData] = useState(null); const [loading, setLoading] = useState(true); @@ -77,8 +77,8 @@ const Page: NextPage = ({ useEffect(() => { let newURL: URL | string = new URL(location.toString()); - newURL.searchParams.set('page', String(page)); newURL.searchParams.set('catalogue', catalogue); + newURL.searchParams.set('page', String(page)); if (search !== '') { newURL.searchParams.set('search', search); }