Skip to content

Commit 91945c0

Browse files
committed
chore(template): update filters
Signed-off-by: Frederik Bußmann <frederik@bussmann.io>
1 parent fdc551d commit 91945c0

15 files changed

Lines changed: 115 additions & 136 deletions

File tree

File renamed without changes.

template/app/components/cart/LineItem.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ watch(state, state => update(props.line.id, state.quantity))
6161
</UFormField>
6262
</UForm>
6363

64-
<Price
64+
<ProductPrice
6565
:price="variant.price"
6666
class="font-semibold leading-8"
6767
/>

template/app/components/cart/Modal.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ watch(() => route.path, () => open.value = false)
6565
<div class="flex items-center gap-2">
6666
<p class="font-medium inline-block">
6767
{{ t('cart.subtotal') }}:
68-
<Price :price="total" />
68+
<ProductPrice :price="total" />
6969
</p>
7070

7171
<Icon

template/app/components/collection/Products.vue

Lines changed: 32 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -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)
6464
const pageInfo = computed(() => collection.value?.products.pageInfo)
6565
const products = computed(() => flattenConnection(collection.value?.products))
6666
67-
const toTop = () => {
68-
window.scrollTo({
69-
top: 0,
70-
behavior: 'smooth',
71-
})
72-
}
73-
7467
const 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
8980
const loadNext = async () => {
@@ -94,16 +85,15 @@ const loadNext = async () => {
9485
first: 12,
9586
last: undefined,
9687
} })
97-
98-
toTop()
9988
}
10089
10190
watch(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>

template/app/components/filter/Bar.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ const resetFilters = async () => {
4949
<div class="lg:mt-14 lg:me-16">
5050
<div class="lg:sticky lg:top-24">
5151
<div class="flex justify-between items-center mb-4">
52-
<p class="text-xl font-bold">
52+
<p class="leading-8 text-xl font-bold">
5353
{{ $t('filters.title') }}
5454
</p>
5555

template/app/components/filter/type/List.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
<script setup lang="ts">
2-
import type { ProductFilterFieldsFragment, ProductFilter } from '#shopify/storefront'
2+
import type { Filter, ProductFilter } from '#shopify/storefront'
33
44
const props = defineProps<{
5-
filter: ProductFilterFieldsFragment['filters'][number]
5+
filter: Filter
66
}>()
77
88
const key = computed(() => Object.keys(JSON.parse(props.filter.values.at(0)?.input ?? '{}')).at(0) as keyof ProductFilter)
99
const items = computed(() => props.filter.values.map(v => v.label))
1010
11-
const { get, set } = useFilter(key.value)
11+
const { get, set } = useFilters(key.value)
1212
1313
const componentToFilter = (value: string[]) =>
1414
props.filter.values.filter(v => value.includes(v.label)).map(v => JSON.parse(v.input) as ProductFilter)

template/app/components/filter/type/PriceRange.vue

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
<script setup lang="ts">
2-
import type { ProductFilterFieldsFragment, ProductFilter } from '#shopify/storefront'
2+
import type { Filter, ProductFilter } from '#shopify/storefront'
33
44
import { z } from 'zod'
55
66
type FilterValue = { min?: number, max?: number }
77
88
const props = defineProps<{
9-
filter: ProductFilterFieldsFragment['filters'][number]
9+
filter: Filter
1010
}>()
1111
12-
const { get, set } = useFilter('price')
12+
const { get, set } = useFilters('price')
1313
const { t } = useI18n()
1414
1515
const input = computed(() => JSON.parse(props.filter.values.at(0)?.input ?? '{}')?.price as FilterValue)
1616
17-
const componentToFilter = (value: FilterValue) => [{ price: value } as ProductFilter]
17+
const componentToFilter = (value: FilterValue) =>
18+
[{ price: value } as ProductFilter]
1819
19-
const filterToComponent = (filter: ProductFilter[]) => filter.map(f => f.price).filter(p => p !== undefined).at(0) as FilterValue ?? input.value
20+
const filterToComponent = (filter: ProductFilter[]) =>
21+
filter.map(f => f.price).filter(p => p !== undefined).at(0) as FilterValue ?? input.value
2022
2123
const schema = z.object({
2224
min: z.number().min(0).optional(),

template/app/components/product/Card.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,19 +64,19 @@ const variant = ref(variants.value[0])
6464
{{ props.product.title }}
6565
</p>
6666

67-
<Price
67+
<ProductPrice
6868
v-if="variant"
6969
:price="variant.price"
7070
class="grow text-right"
7171
/>
7272
</NuxtLink>
7373

74-
<ProductChoose
74+
<CartChoose
7575
v-if="variants.length > 1"
7676
:product="props.product"
7777
/>
7878

79-
<ProductAdd
79+
<CartAdd
8080
v-else
8181
:product="props.product"
8282
/>

0 commit comments

Comments
 (0)