|
|
@@ -11,7 +11,7 @@ import { newSortByFields } from "@utils/constants";
|
|
|
import { isArray } from "@/utils/type-guards";
|
|
|
import { useRouter, usePathname } from "next/navigation";
|
|
|
import { useApolloClient } from "@apollo/client/react";
|
|
|
-import { CategoryProductsResult } from "@components/catalog/type";
|
|
|
+import type{ CategoryProductsResult,PageInfo,CategoryProductNode,CategoryAttrFilterItem } from "@components/catalog/type";
|
|
|
import {CATEGORY_PRODUCTS} from "@/graphql";
|
|
|
interface QueryState {
|
|
|
// search: string;
|
|
|
@@ -27,11 +27,11 @@ interface ProductListingProps {
|
|
|
slug:string;
|
|
|
categoryId: string;
|
|
|
|
|
|
- filterAttributes: any[];
|
|
|
+ filterAttributes:Array<{ node: CategoryAttrFilterItem }>;
|
|
|
|
|
|
- initialProducts: any[];
|
|
|
+ initialProducts: CategoryProductNode[];
|
|
|
|
|
|
- initialPageInfo: any;
|
|
|
+ initialPageInfo: PageInfo;
|
|
|
|
|
|
initialTotal: number;
|
|
|
|
|
|
@@ -114,9 +114,9 @@ export default function ProductListing({
|
|
|
res.data?.categoryProducts?.products.map((e: any) => e.node) || [];
|
|
|
|
|
|
setProducts(newProducts);
|
|
|
-
|
|
|
- setPageInfo(res.data?.categoryProducts?.pageInfo);
|
|
|
-
|
|
|
+ if(res.data?.categoryProducts?.pageInfo){
|
|
|
+ setPageInfo(res.data.categoryProducts.pageInfo);
|
|
|
+ }
|
|
|
setTotal(res.data?.categoryProducts?.totalCount || 0);
|
|
|
} catch (error) {
|
|
|
console.error("fetch products error", error);
|
|
|
@@ -212,8 +212,9 @@ export default function ProductListing({
|
|
|
res.data?.categoryProducts?.products.map((e: any) => e.node) || [];
|
|
|
|
|
|
setProducts((prev) => [...prev, ...moreProducts]);
|
|
|
-
|
|
|
- setPageInfo(res.data?.categoryProducts?.pageInfo);
|
|
|
+ if(res.data?.categoryProducts?.pageInfo){
|
|
|
+ setPageInfo(res.data?.categoryProducts?.pageInfo);
|
|
|
+ }
|
|
|
};
|
|
|
return (
|
|
|
<>
|