Refactor catalog filters: remove badges, use select dropdowns
All checks were successful
Build Docker Image / build (push) Successful in 4m21s
All checks were successful
Build Docker Image / build (push) Successful in 4m21s
- Remove filter from suppliers page (not needed) - Offers: show all active offers directly, add product type filter as select - Hubs: change filter from pills to select dropdown - Create CatalogFilterSelect component for dropdown filters - Update useCatalogOffers to always filter active, use product filter
This commit is contained in:
31
app/components/catalog/CatalogFilterSelect.vue
Normal file
31
app/components/catalog/CatalogFilterSelect.vue
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
<template>
|
||||||
|
<select
|
||||||
|
:value="modelValue"
|
||||||
|
class="select select-bordered select-sm w-full max-w-xs"
|
||||||
|
@change="$emit('update:modelValue', ($event.target as HTMLSelectElement).value)"
|
||||||
|
>
|
||||||
|
<option
|
||||||
|
v-for="filter in filters"
|
||||||
|
:key="filter.id"
|
||||||
|
:value="filter.id"
|
||||||
|
>
|
||||||
|
{{ filter.label }}
|
||||||
|
</option>
|
||||||
|
</select>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
interface Filter {
|
||||||
|
id: string
|
||||||
|
label: string
|
||||||
|
}
|
||||||
|
|
||||||
|
defineProps<{
|
||||||
|
filters: Filter[]
|
||||||
|
modelValue: string
|
||||||
|
}>()
|
||||||
|
|
||||||
|
defineEmits<{
|
||||||
|
'update:modelValue': [value: string]
|
||||||
|
}>()
|
||||||
|
</script>
|
||||||
@@ -5,21 +5,14 @@ const PAGE_SIZE = 24
|
|||||||
// Shared state across list and map views
|
// Shared state across list and map views
|
||||||
const items = ref<any[]>([])
|
const items = ref<any[]>([])
|
||||||
const total = ref(0)
|
const total = ref(0)
|
||||||
const selectedFilter = ref('all')
|
const selectedProductUuid = ref<string | null>(null)
|
||||||
const productUuid = ref<string | null>(null)
|
|
||||||
const isLoading = ref(false)
|
const isLoading = ref(false)
|
||||||
const isLoadingMore = ref(false)
|
const isLoadingMore = ref(false)
|
||||||
const isInitialized = ref(false)
|
const isInitialized = ref(false)
|
||||||
|
|
||||||
export function useCatalogOffers() {
|
export function useCatalogOffers() {
|
||||||
const { t } = useI18n()
|
|
||||||
const { execute } = useGraphQL()
|
const { execute } = useGraphQL()
|
||||||
|
|
||||||
const filters = computed(() => [
|
|
||||||
{ id: 'all', label: t('catalogOffersSection.filters.all') },
|
|
||||||
{ id: 'active', label: t('catalogOffersSection.filters.active') }
|
|
||||||
])
|
|
||||||
|
|
||||||
const itemsWithCoords = computed(() =>
|
const itemsWithCoords = computed(() =>
|
||||||
items.value
|
items.value
|
||||||
.filter(offer => offer.locationLatitude && offer.locationLongitude)
|
.filter(offer => offer.locationLatitude && offer.locationLongitude)
|
||||||
@@ -37,14 +30,13 @@ export function useCatalogOffers() {
|
|||||||
const fetchPage = async (offset: number, replace = false) => {
|
const fetchPage = async (offset: number, replace = false) => {
|
||||||
if (replace) isLoading.value = true
|
if (replace) isLoading.value = true
|
||||||
try {
|
try {
|
||||||
const status = selectedFilter.value === 'active' ? 'active' : null
|
|
||||||
const data = await execute(
|
const data = await execute(
|
||||||
GetOffersDocument,
|
GetOffersDocument,
|
||||||
{
|
{
|
||||||
limit: PAGE_SIZE,
|
limit: PAGE_SIZE,
|
||||||
offset,
|
offset,
|
||||||
status,
|
status: 'active',
|
||||||
productUuid: productUuid.value
|
productUuid: selectedProductUuid.value
|
||||||
},
|
},
|
||||||
'public',
|
'public',
|
||||||
'exchange'
|
'exchange'
|
||||||
@@ -59,10 +51,11 @@ export function useCatalogOffers() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const setProductUuid = (uuid: string | null) => {
|
const setProductUuid = (uuid: string | null) => {
|
||||||
if (productUuid.value !== uuid) {
|
if (selectedProductUuid.value !== uuid) {
|
||||||
productUuid.value = uuid
|
selectedProductUuid.value = uuid
|
||||||
isInitialized.value = false
|
if (isInitialized.value) {
|
||||||
items.value = []
|
fetchPage(0, true)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,13 +69,6 @@ export function useCatalogOffers() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// При смене фильтра - перезагрузка
|
|
||||||
watch(selectedFilter, () => {
|
|
||||||
if (isInitialized.value) {
|
|
||||||
fetchPage(0, true)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
// Initialize data if not already loaded
|
// Initialize data if not already loaded
|
||||||
const init = async () => {
|
const init = async () => {
|
||||||
if (!isInitialized.value && items.value.length === 0) {
|
if (!isInitialized.value && items.value.length === 0) {
|
||||||
@@ -93,9 +79,7 @@ export function useCatalogOffers() {
|
|||||||
return {
|
return {
|
||||||
items,
|
items,
|
||||||
total,
|
total,
|
||||||
selectedFilter,
|
selectedProductUuid,
|
||||||
productUuid,
|
|
||||||
filters,
|
|
||||||
isLoading,
|
isLoading,
|
||||||
isLoadingMore,
|
isLoadingMore,
|
||||||
itemsWithCoords,
|
itemsWithCoords,
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
@select="onSelectHub"
|
@select="onSelectHub"
|
||||||
>
|
>
|
||||||
<template #filters>
|
<template #filters>
|
||||||
<CatalogFilters :filters="filters" v-model="selectedFilter" />
|
<CatalogFilterSelect :filters="filters" v-model="selectedFilter" />
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<template #card="{ item }">
|
<template #card="{ item }">
|
||||||
|
|||||||
@@ -1,73 +1,39 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="flex flex-col flex-1 min-h-0">
|
<CatalogPage
|
||||||
<!-- Loading state -->
|
:items="items"
|
||||||
<div v-if="isLoading || productsLoading" class="flex-1 flex items-center justify-center">
|
:loading="isLoading || productsLoading"
|
||||||
<Card padding="lg">
|
map-id="offers-map"
|
||||||
<Stack align="center" justify="center" gap="3">
|
point-color="#f59e0b"
|
||||||
<Spinner />
|
:selected-id="selectedOfferId"
|
||||||
<Text tone="muted">{{ t('catalogLanding.states.loading') }}</Text>
|
@select="onSelectOffer"
|
||||||
</Stack>
|
>
|
||||||
</Card>
|
<template #filters>
|
||||||
</div>
|
<CatalogFilterSelect
|
||||||
|
v-if="productFilters.length > 1"
|
||||||
<!-- Products catalog (when no product selected) -->
|
:filters="productFilters"
|
||||||
<div v-else-if="!selectedProductUuid" class="flex-1 overflow-y-auto py-4">
|
:model-value="selectedProductUuid || 'all'"
|
||||||
<Stack gap="4">
|
@update:model-value="onProductFilterChange"
|
||||||
<Grid :cols="1" :md="2" :lg="3" :gap="4">
|
/>
|
||||||
<Card
|
|
||||||
v-for="product in products"
|
|
||||||
:key="product.uuid"
|
|
||||||
padding="sm"
|
|
||||||
interactive
|
|
||||||
@click="selectProduct(product)"
|
|
||||||
>
|
|
||||||
<Stack gap="2">
|
|
||||||
<Text size="base" weight="semibold">{{ product.name }}</Text>
|
|
||||||
<Text tone="muted">{{ product.categoryName || t('catalogProduct.labels.category_unknown') }}</Text>
|
|
||||||
</Stack>
|
|
||||||
</Card>
|
|
||||||
</Grid>
|
|
||||||
|
|
||||||
<Stack v-if="products.length === 0" align="center" gap="2">
|
|
||||||
<Text tone="muted">{{ t('catalogOffersSection.empty.no_products') }}</Text>
|
|
||||||
</Stack>
|
|
||||||
</Stack>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Offers for selected product -->
|
|
||||||
<template v-else>
|
|
||||||
<CatalogPage
|
|
||||||
:items="items"
|
|
||||||
:loading="isLoading"
|
|
||||||
map-id="offers-map"
|
|
||||||
point-color="#f59e0b"
|
|
||||||
:selected-id="selectedOfferId"
|
|
||||||
@select="onSelectOffer"
|
|
||||||
>
|
|
||||||
<template #filters>
|
|
||||||
<CatalogFilters :filters="filters" v-model="selectedFilter" />
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<template #card="{ item }">
|
|
||||||
<OfferCard :offer="item" />
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<template #pagination>
|
|
||||||
<PaginationLoadMore
|
|
||||||
:shown="items.length"
|
|
||||||
:total="total"
|
|
||||||
:can-load-more="canLoadMore"
|
|
||||||
:loading="isLoadingMore"
|
|
||||||
@load-more="loadMore"
|
|
||||||
/>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<template #empty>
|
|
||||||
<Text tone="muted">{{ t('catalogOffersSection.empty.no_offers') }}</Text>
|
|
||||||
</template>
|
|
||||||
</CatalogPage>
|
|
||||||
</template>
|
</template>
|
||||||
</div>
|
|
||||||
|
<template #card="{ item }">
|
||||||
|
<OfferCard :offer="item" />
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<template #pagination>
|
||||||
|
<PaginationLoadMore
|
||||||
|
:shown="items.length"
|
||||||
|
:total="total"
|
||||||
|
:can-load-more="canLoadMore"
|
||||||
|
:loading="isLoadingMore"
|
||||||
|
@load-more="loadMore"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<template #empty>
|
||||||
|
<Text tone="muted">{{ t('catalogOffersSection.empty.no_offers') }}</Text>
|
||||||
|
</template>
|
||||||
|
</CatalogPage>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
@@ -76,11 +42,8 @@ definePageMeta({
|
|||||||
})
|
})
|
||||||
|
|
||||||
const { t } = useI18n()
|
const { t } = useI18n()
|
||||||
const localePath = useLocalePath()
|
|
||||||
const route = useRoute()
|
|
||||||
const router = useRouter()
|
|
||||||
|
|
||||||
// Products catalog
|
// Products for filter
|
||||||
const {
|
const {
|
||||||
items: products,
|
items: products,
|
||||||
isLoading: productsLoading,
|
isLoading: productsLoading,
|
||||||
@@ -91,8 +54,7 @@ const {
|
|||||||
const {
|
const {
|
||||||
items,
|
items,
|
||||||
total,
|
total,
|
||||||
selectedFilter,
|
selectedProductUuid,
|
||||||
filters,
|
|
||||||
isLoading,
|
isLoading,
|
||||||
isLoadingMore,
|
isLoadingMore,
|
||||||
canLoadMore,
|
canLoadMore,
|
||||||
@@ -101,27 +63,19 @@ const {
|
|||||||
setProductUuid
|
setProductUuid
|
||||||
} = useCatalogOffers()
|
} = useCatalogOffers()
|
||||||
|
|
||||||
// Get product from query
|
// Product filter options
|
||||||
const selectedProductUuid = computed(() => route.query.product as string | undefined)
|
const productFilters = computed(() => {
|
||||||
|
const all = [{ id: 'all', label: t('catalogOffersSection.filters.all_products') }]
|
||||||
// Selected product info
|
const productOptions = products.value.map(p => ({
|
||||||
const selectedProduct = computed(() => {
|
id: p.uuid,
|
||||||
if (!selectedProductUuid.value) return null
|
label: p.name
|
||||||
return products.value.find(p => p.uuid === selectedProductUuid.value)
|
}))
|
||||||
|
return [...all, ...productOptions]
|
||||||
})
|
})
|
||||||
|
|
||||||
const pageTitle = computed(() => {
|
// Handle product filter change
|
||||||
if (selectedProduct.value) {
|
const onProductFilterChange = (value: string) => {
|
||||||
return `${t('catalogOffersSection.header.title')}: ${selectedProduct.value.name}`
|
setProductUuid(value === 'all' ? null : value)
|
||||||
}
|
|
||||||
return t('catalogOffersSection.header.select_product')
|
|
||||||
})
|
|
||||||
|
|
||||||
const selectProduct = (product: any) => {
|
|
||||||
router.push({
|
|
||||||
path: route.path,
|
|
||||||
query: { product: product.uuid }
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Selected offer for map highlighting
|
// Selected offer for map highlighting
|
||||||
@@ -132,17 +86,9 @@ const onSelectOffer = (offer: any) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Initialize
|
// Initialize
|
||||||
await initProducts()
|
await Promise.all([initProducts(), initOffers()])
|
||||||
|
|
||||||
// Watch for product changes
|
|
||||||
watch(selectedProductUuid, async (uuid) => {
|
|
||||||
setProductUuid(uuid || null)
|
|
||||||
if (uuid) {
|
|
||||||
await initOffers()
|
|
||||||
}
|
|
||||||
}, { immediate: true })
|
|
||||||
|
|
||||||
useHead(() => ({
|
useHead(() => ({
|
||||||
title: pageTitle.value
|
title: t('catalogOffersSection.header.title')
|
||||||
}))
|
}))
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -7,10 +7,6 @@
|
|||||||
:selected-id="selectedSupplierId"
|
:selected-id="selectedSupplierId"
|
||||||
@select="onSelectSupplier"
|
@select="onSelectSupplier"
|
||||||
>
|
>
|
||||||
<template #filters>
|
|
||||||
<CatalogFilters :filters="filters" v-model="selectedFilter" />
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<template #card="{ item }">
|
<template #card="{ item }">
|
||||||
<SupplierCard :supplier="item" />
|
<SupplierCard :supplier="item" />
|
||||||
</template>
|
</template>
|
||||||
@@ -41,8 +37,6 @@ const { t } = useI18n()
|
|||||||
const {
|
const {
|
||||||
items,
|
items,
|
||||||
total,
|
total,
|
||||||
selectedFilter,
|
|
||||||
filters,
|
|
||||||
isLoading,
|
isLoading,
|
||||||
isLoadingMore,
|
isLoadingMore,
|
||||||
canLoadMore,
|
canLoadMore,
|
||||||
|
|||||||
@@ -9,7 +9,8 @@
|
|||||||
},
|
},
|
||||||
"filters": {
|
"filters": {
|
||||||
"all": "All",
|
"all": "All",
|
||||||
"active": "Active"
|
"active": "Active",
|
||||||
|
"all_products": "All products"
|
||||||
},
|
},
|
||||||
"empty": {
|
"empty": {
|
||||||
"no_offers": "No active offers",
|
"no_offers": "No active offers",
|
||||||
|
|||||||
@@ -9,7 +9,8 @@
|
|||||||
},
|
},
|
||||||
"filters": {
|
"filters": {
|
||||||
"all": "Все",
|
"all": "Все",
|
||||||
"active": "Активные"
|
"active": "Активные",
|
||||||
|
"all_products": "Все товары"
|
||||||
},
|
},
|
||||||
"empty": {
|
"empty": {
|
||||||
"no_offers": "Нет активных предложений",
|
"no_offers": "Нет активных предложений",
|
||||||
|
|||||||
Reference in New Issue
Block a user