From 69204e9e625b79831ee205f3e85f2723ad1a0f86 Mon Sep 17 00:00:00 2001 From: Luis Gomez Date: Thu, 25 Aug 2022 14:59:05 -0500 Subject: [PATCH] Updates --- site/components/search.tsx | 55 +++++++++++++++++++++++--------------- site/lib/search.tsx | 5 ++++ 2 files changed, 39 insertions(+), 21 deletions(-) diff --git a/site/components/search.tsx b/site/components/search.tsx index 75b5b0416..73b1ed868 100644 --- a/site/components/search.tsx +++ b/site/components/search.tsx @@ -25,21 +25,21 @@ import { filterQuery, getCategoryPath, getDesignerPath, + getPaginationPath, useSearchMeta, } from '@lib/search' export default function Search({ categories, brands }: SearchPropsType) { const [activeFilter, setActiveFilter] = useState('') const [toggleFilter, setToggleFilter] = useState(false) - const [page, SetPage] = useState(1) const router = useRouter() const { asPath, locale } = router - const { q, sort } = router.query + const { q, sort, page } = router.query // `q` can be included but because categories and designers can't be searched // in the same way of products, it's better to ignore the search input if one // of those is selected - const query = filterQuery({ sort }) + const query = filterQuery({ sort, page }) const { pathname, category, brand } = useSearchMeta(asPath) const activeCategory = categories.find((cat: any) => cat.slug === category) @@ -52,7 +52,7 @@ export default function Search({ categories, brands }: SearchPropsType) { categoryId: activeCategory?.id, brandId: (activeBrand as any)?.entityId, sort: typeof sort === 'string' ? sort : '', - page: page, + page: typeof page === 'string' ? page : '', locale, }) @@ -343,25 +343,38 @@ export default function Search({ categories, brands }: SearchPropsType) { )}{' '}
- {page !== 1 && ( - - )} {data?.pagination.total_pages !== data?.pagination.current_page && ( - + + + )} + + {data?.pagination.current_page !== 1 && ( + + + )}
diff --git a/site/lib/search.tsx b/site/lib/search.tsx index eaeaf66fc..7d8287519 100644 --- a/site/lib/search.tsx +++ b/site/lib/search.tsx @@ -50,3 +50,8 @@ export const getDesignerPath = (path: string, category?: string) => { category ? `/${category}` : '' }` } + +export const getPaginationPath = (path: string, currentPage?: number) => { + const category = getSlug(path) + return `${category ? `/${category}` : ''}?page=${currentPage}` +}