forked from Weaverse/aspen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
all-products.tsx
137 lines (130 loc) · 3.68 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import {useLoaderData} from '@remix-run/react';
import {Pagination} from '@shopify/hydrogen';
import type {
HydrogenComponentProps,
HydrogenComponentSchema,
} from '@weaverse/hydrogen';
import {forwardRef} from 'react';
import type {AllProductsQuery} from 'storefrontapi.generated';
import {Grid, PageHeader, ProductCard, Section} from '~/components';
import {getImageLoadingPriority} from '~/lib/const';
interface AllProductsProps extends HydrogenComponentProps {
heading: string;
prevPageText: string;
nextPageText: string;
paddingTop: number;
paddingBottom: number;
}
let AllProducts = forwardRef<HTMLElement, AllProductsProps>((props, ref) => {
let {
heading,
prevPageText,
nextPageText,
paddingTop,
paddingBottom,
...rest
} = props;
let {products} = useLoaderData<AllProductsQuery>();
return (
<section ref={ref} {...rest}>
<div
style={{
paddingTop: `${paddingTop}px`,
paddingBottom: `${paddingBottom}px`,
}}
>
<PageHeader heading={heading} variant="allCollections" />
<Section>
<Pagination connection={products}>
{({nodes, isLoading, NextLink, PreviousLink}) => {
let itemsMarkup = nodes.map((product, i) => (
<ProductCard
key={product.id}
product={product}
loading={getImageLoadingPriority(i)}
/>
));
return (
<>
<div className="flex items-center justify-center mt-6">
<PreviousLink className="inline-block rounded font-medium text-center py-3 px-6 border border-bar/10 bg-contrast text-body w-full">
{isLoading ? 'Loading...' : prevPageText}
</PreviousLink>
</div>
<Grid data-test="product-grid">{itemsMarkup}</Grid>
<div className="flex items-center justify-center mt-6">
<NextLink className="inline-block rounded font-medium text-center py-3 px-6 border border-bar/10 bg-contrast text-body w-full">
{isLoading ? 'Loading...' : nextPageText}
</NextLink>
</div>
</>
);
}}
</Pagination>
</Section>
</div>
</section>
);
});
export default AllProducts;
export let schema: HydrogenComponentSchema = {
type: 'all-products',
title: 'All products',
limit: 1,
enabledOn: {
pages: ['ALL_PRODUCTS'],
},
toolbar: ['general-settings'],
inspector: [
{
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',
},
{
type: 'range',
label: 'Top padding',
name: 'paddingTop',
configs: {
min: 0,
max: 100,
step: 4,
unit: 'px',
},
defaultValue: 32,
},
{
type: 'range',
label: 'Bottom padding',
name: 'paddingBottom',
configs: {
min: 0,
max: 100,
step: 4,
unit: 'px',
},
defaultValue: 32,
},
],
},
],
};