schon/storefront/components/store/index.vue
Alexandr SaVBaD Waltz 761fecf67f Features: 1) Add useWishlistOverwrite composable for wishlist mutations, including adding, removing, and bulk actions; 2) Introduce new localized UI texts for cart and wishlist operations; 3) Enhance filtering logic with parseAttributesString and route query synchronization;
Fixes: 1) Replace `ElNotification` calls with `useNotification` utility across all authentication and user-related composables; 2) Add missing semicolons in multiple index exports and styled components; 3) Resolve issues with reactivity in `useStore` composable by renaming and restructuring product variables;

Extra: 1) Refactor localized strings and translations for better readability and maintenance; 2) Tweak styles including scoped styles, z-index adjustments, and SCSS mixins; 3) Remove unused components and imports to streamline storefront layout.
2025-07-06 19:49:26 +03:00

150 lines
No EOL
3.4 KiB
Vue

<template>
<div class="store">
<store-filter
v-if="filters.length"
:filterableAttributes="filters"
:isOpen="showFilter"
@update:selected="onFiltersChange"
@close="showFilter = false"
/>
<store-top
v-model="orderBy"
@toggle-filter="onFilterToggle"
/>
<div
class="store__list"
:class="[
{ 'store__list-grid': productView === 'grid' },
{ 'store__list-list': productView === 'list' }
]"
>
<cards-product
v-if="products.length"
v-for="product in products"
:key="product.node.uuid"
:product="product.node"
:isList="productView === 'list'"
/>
<skeletons-cards-product
v-if="pending"
v-for="idx in 12"
:key="idx"
:isList="productView === 'list'"
/>
</div>
<div class="store__list-observer" ref="observer"></div>
</div>
</template>
<script setup lang="ts">
import {useFilters, useStore} from "~/composables/store";
import {useRouteQuery} from "@vueuse/router";
import {useRouteParams} from "@vueuse/router";
import {useCategoryBySlug} from "~/composables/categories";
import {useAppConfig} from '~/composables/config';
const { COOKIES_PRODUCT_VIEW_KEY } = useAppConfig();
const productView = useCookie<string>(
COOKIES_PRODUCT_VIEW_KEY as string,
{
default: () => 'grid',
path: '/',
}
);
const slug = useRouteParams<string>('slug');
const attributes = useRouteQuery<string>('attributes', '');
const orderBy = useRouteQuery<string>('orderBy', 'created');
const minPrice = useRouteQuery<number>('minPrice', 0);
const maxPrice = useRouteQuery<number>('maxPrice', 50000);
const observer = ref(null);
const { category, filters } = await useCategoryBySlug(slug.value);
watch(
() => category.value,
(cat) => {
if (cat && !useRoute().query.maxPrice) {
maxPrice.value = cat.minMaxPrices.maxPrice;
}
},
{ immediate: true }
);
const { pending, products, pageInfo, variables } = await useStore(
slug.value,
attributes.value,
orderBy.value,
minPrice.value,
maxPrice.value,
''
);
const { buildAttributesString } = useFilters(filters);
const showFilter = ref<boolean>(false);
function onFilterToggle() {
showFilter.value = true;
}
function onFiltersChange(newFilters: Record<string, string[]>) {
const attrString = buildAttributesString(newFilters);
attributes.value = attrString;
variables.attributes = attrString;
}
useIntersectionObserver(
observer,
async ([{ isIntersecting }]) => {
if (isIntersecting && pageInfo.value?.hasNextPage && !pending.value) {
variables.productAfter = pageInfo.value.endCursor;
}
},
);
watch(orderBy, newVal => {
variables.orderBy = newVal || '';
});
watch(attributes, newVal => {
variables.attributes = newVal;
});
watch(minPrice, newVal => {
variables.minPrice = newVal || 0;
});
watch(maxPrice, newVal => {
variables.maxPrice = newVal || 500000;
});
</script>
<style scoped lang="scss">
.store {
position: relative;
&__inner {
width: 100%;
}
&__list {
margin-top: 50px;
&-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
gap: 25px;
}
&-list {
display: flex;
flex-direction: column;
align-items: stretch;
gap: 20px;
}
&-observer {
background-color: transparent;
width: 100%;
height: 10px;
}
}
}
</style>