Skip to content

Commit 128c27e

Browse files
committed
chore(docs): add collection page recipe
Signed-off-by: Frederik Bußmann <frederik@bussmann.io>
1 parent ff3323a commit 128c27e

3 files changed

Lines changed: 378 additions & 9 deletions

File tree

docs/app/components/recipes/CollectionPage.vue

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ const props = defineProps<{
33
handle: string
44
}>()
55
6+
const route = useRoute()
7+
68
const key = `collection-${props.handle}`
79
810
const { data: collection } = await useStorefrontData(key, `#graphql
@@ -27,16 +29,28 @@ const { data: collection } = await useStorefrontData(key, `#graphql
2729
${COLLECTION_FRAGMENT}
2830
${PRODUCT_CONNECTION_FRAGMENT}
2931
`, {
30-
variables: {
32+
variables: computed(() => ({
3133
handle: props.handle,
32-
first: 4,
3334
language: 'EN',
3435
country: 'US',
35-
},
36+
first: route.query.before ? undefined : 4,
37+
last: route.query.before ? 4 : undefined,
38+
after: route.query.after,
39+
before: route.query.before,
40+
})),
3641
transform: data => data.collection,
42+
watch: [
43+
() => route.query.after,
44+
() => route.query.before,
45+
],
3746
})
3847
3948
const products = computed(() => flattenConnection(collection.value?.products))
49+
50+
const startCursor = computed(() => collection.value?.products.pageInfo.startCursor)
51+
const endCursor = computed(() => collection.value?.products.pageInfo.endCursor)
52+
const hasPreviousPage = computed(() => collection.value?.products.pageInfo.hasPreviousPage)
53+
const hasNextPage = computed(() => collection.value?.products.pageInfo.hasNextPage)
4054
</script>
4155

4256
<template>
@@ -56,5 +70,23 @@ const products = computed(() => flattenConnection(collection.value?.products))
5670
:product="product"
5771
/>
5872
</div>
73+
74+
<div class="flex justify-between mt-8">
75+
<UButton
76+
v-if="hasPreviousPage"
77+
:to="`?before=${startCursor}`"
78+
icon="i-lucide-arrow-left"
79+
>
80+
Previous
81+
</UButton>
82+
83+
<UButton
84+
v-if="hasNextPage"
85+
:to="`?after=${endCursor}`"
86+
trailing-icon="i-lucide-arrow-right"
87+
>
88+
Next
89+
</UButton>
90+
</div>
5991
</div>
6092
</template>

docs/content/3.recipes/1.navigation-tree.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ This recipe will show you how to create a navigation menu for your Shopify store
1414
::card
1515
:::tabs
1616
::::tabs-item{icon="i-lucide-eye" label="Preview"}
17-
:::::navigation-menu{handle="main-menu" .justify-center}
17+
:::::navigation-menu{handle="main-menu" .justify-center .pt-2}
1818
:::::
1919
::::
2020

0 commit comments

Comments
 (0)