Refactor catalog filters: remove badges, use select dropdowns
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:
Ruslan Bakiev
2026-01-08 10:08:05 +07:00
parent e629025899
commit 0c88cf383c
7 changed files with 94 additions and 137 deletions

View 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>

View File

@@ -5,21 +5,14 @@ const PAGE_SIZE = 24
// Shared state across list and map views
const items = ref<any[]>([])
const total = ref(0)
const selectedFilter = ref('all')
const productUuid = ref<string | null>(null)
const selectedProductUuid = ref<string | null>(null)
const isLoading = ref(false)
const isLoadingMore = ref(false)
const isInitialized = ref(false)
export function useCatalogOffers() {
const { t } = useI18n()
const { execute } = useGraphQL()
const filters = computed(() => [
{ id: 'all', label: t('catalogOffersSection.filters.all') },
{ id: 'active', label: t('catalogOffersSection.filters.active') }
])
const itemsWithCoords = computed(() =>
items.value
.filter(offer => offer.locationLatitude && offer.locationLongitude)
@@ -37,14 +30,13 @@ export function useCatalogOffers() {
const fetchPage = async (offset: number, replace = false) => {
if (replace) isLoading.value = true
try {
const status = selectedFilter.value === 'active' ? 'active' : null
const data = await execute(
GetOffersDocument,
{
limit: PAGE_SIZE,
offset,
status,
productUuid: productUuid.value
status: 'active',
productUuid: selectedProductUuid.value
},
'public',
'exchange'
@@ -59,10 +51,11 @@ export function useCatalogOffers() {
}
const setProductUuid = (uuid: string | null) => {
if (productUuid.value !== uuid) {
productUuid.value = uuid
isInitialized.value = false
items.value = []
if (selectedProductUuid.value !== uuid) {
selectedProductUuid.value = uuid
if (isInitialized.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
const init = async () => {
if (!isInitialized.value && items.value.length === 0) {
@@ -93,9 +79,7 @@ export function useCatalogOffers() {
return {
items,
total,
selectedFilter,
productUuid,
filters,
selectedProductUuid,
isLoading,
isLoadingMore,
itemsWithCoords,

View File

@@ -8,7 +8,7 @@
@select="onSelectHub"
>
<template #filters>
<CatalogFilters :filters="filters" v-model="selectedFilter" />
<CatalogFilterSelect :filters="filters" v-model="selectedFilter" />
</template>
<template #card="{ item }">

View File

@@ -1,51 +1,19 @@
<template>
<div class="flex flex-col flex-1 min-h-0">
<!-- Loading state -->
<div v-if="isLoading || productsLoading" class="flex-1 flex items-center justify-center">
<Card padding="lg">
<Stack align="center" justify="center" gap="3">
<Spinner />
<Text tone="muted">{{ t('catalogLanding.states.loading') }}</Text>
</Stack>
</Card>
</div>
<!-- Products catalog (when no product selected) -->
<div v-else-if="!selectedProductUuid" class="flex-1 overflow-y-auto py-4">
<Stack gap="4">
<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"
:loading="isLoading || productsLoading"
map-id="offers-map"
point-color="#f59e0b"
:selected-id="selectedOfferId"
@select="onSelectOffer"
>
<template #filters>
<CatalogFilters :filters="filters" v-model="selectedFilter" />
<CatalogFilterSelect
v-if="productFilters.length > 1"
:filters="productFilters"
:model-value="selectedProductUuid || 'all'"
@update:model-value="onProductFilterChange"
/>
</template>
<template #card="{ item }">
@@ -67,8 +35,6 @@
</template>
</CatalogPage>
</template>
</div>
</template>
<script setup lang="ts">
definePageMeta({
@@ -76,11 +42,8 @@ definePageMeta({
})
const { t } = useI18n()
const localePath = useLocalePath()
const route = useRoute()
const router = useRouter()
// Products catalog
// Products for filter
const {
items: products,
isLoading: productsLoading,
@@ -91,8 +54,7 @@ const {
const {
items,
total,
selectedFilter,
filters,
selectedProductUuid,
isLoading,
isLoadingMore,
canLoadMore,
@@ -101,27 +63,19 @@ const {
setProductUuid
} = useCatalogOffers()
// Get product from query
const selectedProductUuid = computed(() => route.query.product as string | undefined)
// Selected product info
const selectedProduct = computed(() => {
if (!selectedProductUuid.value) return null
return products.value.find(p => p.uuid === selectedProductUuid.value)
// Product filter options
const productFilters = computed(() => {
const all = [{ id: 'all', label: t('catalogOffersSection.filters.all_products') }]
const productOptions = products.value.map(p => ({
id: p.uuid,
label: p.name
}))
return [...all, ...productOptions]
})
const pageTitle = computed(() => {
if (selectedProduct.value) {
return `${t('catalogOffersSection.header.title')}: ${selectedProduct.value.name}`
}
return t('catalogOffersSection.header.select_product')
})
const selectProduct = (product: any) => {
router.push({
path: route.path,
query: { product: product.uuid }
})
// Handle product filter change
const onProductFilterChange = (value: string) => {
setProductUuid(value === 'all' ? null : value)
}
// Selected offer for map highlighting
@@ -132,17 +86,9 @@ const onSelectOffer = (offer: any) => {
}
// Initialize
await initProducts()
// Watch for product changes
watch(selectedProductUuid, async (uuid) => {
setProductUuid(uuid || null)
if (uuid) {
await initOffers()
}
}, { immediate: true })
await Promise.all([initProducts(), initOffers()])
useHead(() => ({
title: pageTitle.value
title: t('catalogOffersSection.header.title')
}))
</script>

View File

@@ -7,10 +7,6 @@
:selected-id="selectedSupplierId"
@select="onSelectSupplier"
>
<template #filters>
<CatalogFilters :filters="filters" v-model="selectedFilter" />
</template>
<template #card="{ item }">
<SupplierCard :supplier="item" />
</template>
@@ -41,8 +37,6 @@ const { t } = useI18n()
const {
items,
total,
selectedFilter,
filters,
isLoading,
isLoadingMore,
canLoadMore,

View File

@@ -9,7 +9,8 @@
},
"filters": {
"all": "All",
"active": "Active"
"active": "Active",
"all_products": "All products"
},
"empty": {
"no_offers": "No active offers",

View File

@@ -9,7 +9,8 @@
},
"filters": {
"all": "Все",
"active": "Активные"
"active": "Активные",
"all_products": "Все товары"
},
"empty": {
"no_offers": "Нет активных предложений",