fix broken PLP page

Signed-off-by: Chloe <pinkcloudvnn@gmail.com>
This commit is contained in:
Chloe
2024-06-22 15:21:30 +07:00
parent 8333eb36fc
commit 7015d1caef
5 changed files with 23 additions and 15 deletions

View File

@@ -64,14 +64,16 @@ const constructFilterInput = (filters: {
export const getProductsInCollection = async ({
searchParams,
afterCursor
afterCursor,
collection
}: {
searchParams?: {
[key: string]: string | string[] | undefined;
};
afterCursor?: string;
collection?: string;
}) => {
const { sort, q, collection, ...rest } = searchParams as { [key: string]: string };
const { sort, q, ...rest } = searchParams as { [key: string]: string };
const { sortKey, reverse } = sorting.find((item) => item.slug === sort) || defaultSort;
const filtersInput = constructFilterInput(rest);

View File

@@ -13,7 +13,7 @@ const ProductsList = ({
initialProducts,
pageInfo,
searchParams,
page
collection
}: {
initialProducts: Product[];
pageInfo: {
@@ -21,7 +21,7 @@ const ProductsList = ({
hasNextPage: boolean;
};
searchParams?: { [key: string]: string | string[] | undefined };
page: 'search' | 'collection';
collection?: string;
}) => {
const [products, setProducts] = useState(initialProducts);
const [_pageInfo, setPageInfo] = useState(pageInfo);
@@ -31,13 +31,13 @@ const ProductsList = ({
try {
const params = {
searchParams,
afterCursor: _pageInfo.endCursor
afterCursor: _pageInfo.endCursor,
collection
};
setIsLoading(true);
const { products, pageInfo } =
page === 'collection'
? await getProductsInCollection(params)
: await searchProducts(params);
const { products, pageInfo } = collection
? await getProductsInCollection(params)
: await searchProducts(params);
setProducts((prev) => [...prev, ...products]);
setPageInfo({