-
Notifications
You must be signed in to change notification settings - Fork 0
/
($locale).collections.$handle.tsx
65 lines (57 loc) · 1.44 KB
/
($locale).collections.$handle.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
import {useLoaderData} from '@remix-run/react';
import {parseGid} from '@shopify/hydrogen';
import {defer} from '@shopify/remix-oxygen';
import {CustomComponents} from '@sledge-app/core';
import {ProductFilterWidget} from '@sledge-app/react-instant-search';
import {SledgeCustom} from '~/components';
export async function loader({params, context}: any) {
const {handle} = params;
const {collection} = await context.storefront.query(COLLECTION_QUERY, {
variables: {
handle,
},
});
if (!collection && handle !== 'all') {
throw new Response(null, {status: 404});
}
return defer({
collection,
});
}
const seo = ({data}: any) => ({
title: data?.collection?.title,
description: data?.collection?.description.substr(0, 154),
});
export const handle = {
seo,
};
export default function Collection() {
const {collection} = useLoaderData();
return (
<div
key={collection?.id}
className="max-w-[1170px] mx-auto px-5 lg:px-20 xl:px-0"
>
<ProductFilterWidget
query={{
keyword: 'q',
}}
params={{
collectionId: Number(parseGid(collection?.id).id),
}}
>
<CustomComponents productCard={SledgeCustom.SledgeProductCard} />
</ProductFilterWidget>
</div>
);
}
const COLLECTION_QUERY = `#graphql
query CollectionDetails($handle: String!) {
collection(handle: $handle) {
id
title
description
handle
}
}
`;