Add cascading filters for Explore mode
All checks were successful
Build Docker Image / build (push) Successful in 3m34s
All checks were successful
Build Docker Image / build (push) Successful in 3m34s
When a product is selected, hubs and suppliers are filtered to show only those that are relevant to that product.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { GetSupplierProfilesDocument } from '~/composables/graphql/public/exchange-generated'
|
||||
import { GetSuppliersForProductDocument } from '~/composables/graphql/public/geo-generated'
|
||||
|
||||
const PAGE_SIZE = 24
|
||||
|
||||
@@ -8,6 +9,7 @@ const total = ref(0)
|
||||
const isLoading = ref(false)
|
||||
const isLoadingMore = ref(false)
|
||||
const isInitialized = ref(false)
|
||||
const filterProductUuid = ref<string | null>(null)
|
||||
|
||||
export function useCatalogSuppliers() {
|
||||
const { execute } = useGraphQL()
|
||||
@@ -21,6 +23,35 @@ export function useCatalogSuppliers() {
|
||||
const fetchPage = async (offset: number, replace = false) => {
|
||||
if (replace) isLoading.value = true
|
||||
try {
|
||||
// If filtering by product, use specialized query
|
||||
if (filterProductUuid.value) {
|
||||
const data = await execute(
|
||||
GetSuppliersForProductDocument,
|
||||
{ productUuid: filterProductUuid.value },
|
||||
'public',
|
||||
'geo'
|
||||
)
|
||||
const supplierUuids = (data?.suppliersForProduct || []).map(s => s?.uuid).filter(Boolean)
|
||||
// Fetch full profiles for these suppliers
|
||||
if (supplierUuids.length > 0) {
|
||||
const profilesData = await execute(
|
||||
GetSupplierProfilesDocument,
|
||||
{ limit: supplierUuids.length, offset: 0 },
|
||||
'public',
|
||||
'exchange'
|
||||
)
|
||||
// Filter to only include suppliers that match the product filter
|
||||
const allProfiles = profilesData?.getSupplierProfiles || []
|
||||
items.value = allProfiles.filter(p => supplierUuids.includes(p.uuid))
|
||||
} else {
|
||||
items.value = []
|
||||
}
|
||||
total.value = items.value.length
|
||||
isInitialized.value = true
|
||||
return
|
||||
}
|
||||
|
||||
// Default: fetch all suppliers
|
||||
const data = await execute(
|
||||
GetSupplierProfilesDocument,
|
||||
{ limit: PAGE_SIZE, offset },
|
||||
@@ -53,6 +84,13 @@ export function useCatalogSuppliers() {
|
||||
}
|
||||
}
|
||||
|
||||
const setProductFilter = (uuid: string | null) => {
|
||||
filterProductUuid.value = uuid
|
||||
if (isInitialized.value) {
|
||||
fetchPage(0, true)
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
items,
|
||||
total,
|
||||
@@ -62,6 +100,7 @@ export function useCatalogSuppliers() {
|
||||
canLoadMore,
|
||||
fetchPage,
|
||||
loadMore,
|
||||
init
|
||||
init,
|
||||
setProductFilter
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user