@@ -25,8 +25,7 @@ const { data: collection, status } = await useStorefrontData(key, `#graphql
2525 )
2626 @inContext(language: $language, country: $country) {
2727 collection(handle: $handle) {
28- title,
29- description,
28+ ...CollectionFields
3029 products(
3130 after: $after,
3231 before: $before,
@@ -43,6 +42,7 @@ const { data: collection, status } = await useStorefrontData(key, `#graphql
4342 }
4443 ${PRODUCT_CONNECTION_FRAGMENT }
4544 ${PRODUCT_FILTERS_FRAGMENT }
45+ ${COLLECTION_FRAGMENT }
4646 ${IMAGE_FRAGMENT }
4747 ${PRICE_FRAGMENT }
4848` , {
@@ -64,13 +64,6 @@ const filters = computed(() => collection.value?.products.filters)
6464const pageInfo = computed (() => collection .value ?.products .pageInfo )
6565const products = computed (() => flattenConnection (collection .value ?.products ))
6666
67- const toTop = () => {
68- window .scrollTo ({
69- top: 0 ,
70- behavior: ' smooth' ,
71- })
72- }
73-
7467const loadPrevious = async () => {
7568 route .query .after = null
7669 route .query .before = pageInfo .value ?.startCursor ?? null
@@ -82,8 +75,6 @@ const loadPrevious = async () => {
8275 first: undefined ,
8376 last: 12 ,
8477 } })
85-
86- toTop ()
8778}
8879
8980const loadNext = async () => {
@@ -94,16 +85,15 @@ const loadNext = async () => {
9485 first: 12 ,
9586 last: undefined ,
9687 } })
97-
98- toTop ()
9988}
10089
10190watch (locale , () => {
10291 route .query .first = null
10392 route .query .last = null
104-
105- toTop ()
10693})
94+
95+ watch (() => collection .value ?.products .pageInfo , async () => await nextTick ().then (() =>
96+ window .scrollTo ({ top: 0 , behavior: ' smooth' })), { deep: true })
10797 </script >
10898
10999<template >
@@ -154,37 +144,37 @@ watch(locale, () => {
154144 {{ $t('pagination.next') }}
155145 </UButton >
156146 </div >
157- </div >
158147
159- <div
160- v-if =" status === 'pending'"
161- class =" flex justify-center pt-8"
162- >
163- {{ $t('collection.products.loading') }}
164- </div >
148+ <div
149+ v-if =" status === 'pending'"
150+ class =" flex justify-center pt-8"
151+ >
152+ {{ $t('collection.products.loading') }}
153+ </div >
165154
166- <div
167- v-else-if =" !products || products.length === 0"
168- class =" flex flex-col justify-center items-center col-span-full text-center"
169- >
170- <div class =" flex items-center pb-2 gap-2" >
171- <UIcon
172- name =" i-lucide-triangle-alert"
173- class =" text-dimmed size-6"
174- />
155+ <div
156+ v-else-if =" !products || products.length === 0"
157+ class =" flex flex-col justify-center items-center col-span-full text-center"
158+ >
159+ <div class =" flex items-center pb-2 gap-2" >
160+ <UIcon
161+ name =" i-lucide-triangle-alert"
162+ class =" text-dimmed size-6"
163+ />
175164
176- <p class =" text-xl text-dimmed" >
177- {{ $t('collection.products.notFound') }}
178- </p >
179- </div >
165+ <p class =" text-xl text-dimmed" >
166+ {{ $t('collection.products.notFound') }}
167+ </p >
168+ </div >
180169
181- <UButton
182- variant =" subtle"
183- color =" primary"
184- class =" mt-4"
185- :label =" $t('filters.clear')"
186- @click =" router.push({ query: {} })"
187- />
170+ <UButton
171+ variant =" subtle"
172+ color =" primary"
173+ class =" mt-4"
174+ :label =" $t('filters.clear')"
175+ @click =" router.push({ query: {} })"
176+ />
177+ </div >
188178 </div >
189179 </div >
190180</template >
0 commit comments