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,4 @@
|
||||
import { GetNodesDocument, GetHubCountriesDocument } from '~/composables/graphql/public/geo-generated'
|
||||
import { GetNodesDocument, GetHubCountriesDocument, GetHubsForProductDocument } from '~/composables/graphql/public/geo-generated'
|
||||
|
||||
const PAGE_SIZE = 24
|
||||
|
||||
@@ -11,6 +11,7 @@ const countries = ref<string[]>([])
|
||||
const isLoading = ref(false)
|
||||
const isLoadingMore = ref(false)
|
||||
const isInitialized = ref(false)
|
||||
const filterProductUuid = ref<string | null>(null)
|
||||
|
||||
export function useCatalogHubs() {
|
||||
const { t } = useI18n()
|
||||
@@ -50,6 +51,22 @@ export function useCatalogHubs() {
|
||||
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(
|
||||
GetHubsForProductDocument,
|
||||
{ productUuid: filterProductUuid.value },
|
||||
'public',
|
||||
'geo'
|
||||
)
|
||||
const next = data?.hubsForProduct || []
|
||||
items.value = next
|
||||
total.value = next.length
|
||||
isInitialized.value = true
|
||||
return
|
||||
}
|
||||
|
||||
// Default: fetch all hubs with filters
|
||||
const transportType = selectedFilter.value === 'all' ? null : selectedFilter.value
|
||||
const country = selectedCountry.value === 'all' ? null : selectedCountry.value
|
||||
const data = await execute(
|
||||
@@ -93,6 +110,13 @@ export function useCatalogHubs() {
|
||||
}
|
||||
})
|
||||
|
||||
const setProductFilter = (uuid: string | null) => {
|
||||
filterProductUuid.value = uuid
|
||||
if (isInitialized.value) {
|
||||
fetchPage(0, true)
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize data if not already loaded
|
||||
const init = async () => {
|
||||
if (!isInitialized.value && items.value.length === 0) {
|
||||
@@ -117,6 +141,7 @@ export function useCatalogHubs() {
|
||||
canLoadMore,
|
||||
fetchPage,
|
||||
loadMore,
|
||||
init
|
||||
init,
|
||||
setProductFilter
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user