forked from Weaverse/pilot
-
Notifications
You must be signed in to change notification settings - Fork 1
/
all-products.tsx
117 lines (112 loc) · 3.25 KB
/
all-products.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import { useLoaderData } from "@remix-run/react";
import { Pagination } from "@shopify/hydrogen";
import type { HydrogenComponentSchema } from "@weaverse/hydrogen";
import clsx from "clsx";
import { forwardRef } from "react";
import type { AllProductsQuery } from "storefront-api.generated";
import { BreadCrumb } from "~/components/breadcrumb";
import Link from "~/components/link";
import { ProductCard } from "~/components/product/product-card";
import { Section, type SectionProps, layoutInputs } from "~/components/section";
interface AllProductsProps extends SectionProps {
heading: string;
prevPageText: string;
nextPageText: string;
}
let AllProducts = forwardRef<HTMLElement, AllProductsProps>((props, ref) => {
let { heading, prevPageText, nextPageText, ...rest } = props;
let { products } = useLoaderData<AllProductsQuery>();
return (
<Section ref={ref} {...rest}>
<BreadCrumb page={heading} className="justify-center mb-4" />
<h4 className="mb-8 lg:mb-20 font-medium text-center">{heading}</h4>
<Pagination connection={products}>
{({
nodes,
isLoading,
nextPageUrl,
hasNextPage,
previousPageUrl,
hasPreviousPage,
}) => {
return (
<div className="flex w-full flex-col gap-8 items-center">
{hasPreviousPage && (
<Link
to={previousPageUrl}
variant="outline"
className="mx-auto"
>
{isLoading ? "Loading..." : prevPageText}
</Link>
)}
<div
className={clsx([
"w-full gap-x-1.5 gap-y-8 lg:gap-y-10",
"grid grid-cols-1 lg:grid-cols-4",
])}
>
{nodes.map((product) => (
<ProductCard key={product.id} product={product} />
))}
</div>
{hasNextPage && (
<Link to={nextPageUrl} variant="outline" className="mx-auto">
{isLoading ? "Loading..." : nextPageText}
</Link>
)}
</div>
);
}}
</Pagination>
</Section>
);
});
export default AllProducts;
export let schema: HydrogenComponentSchema = {
type: "all-products",
title: "All products",
limit: 1,
enabledOn: {
pages: ["ALL_PRODUCTS"],
},
inspector: [
{
group: "Layout",
inputs: [
...layoutInputs.filter(
(inp) =>
inp.name !== "divider" &&
inp.name !== "borderRadius" &&
inp.name !== "gap",
),
],
},
{
group: "All products",
inputs: [
{
type: "text",
name: "heading",
label: "Heading",
defaultValue: "All Products",
placeholder: "All Products",
},
{
type: "text",
name: "prevPageText",
label: "Previous page text",
defaultValue: "Previous",
placeholder: "Previous",
},
{
type: "text",
name: "nextPageText",
label: "Next page text",
defaultValue: "Next",
placeholder: "Next",
},
],
},
],
};