Optimize catalog loading: backend bounds filtering + early returns
All checks were successful
Build Docker Image / build (push) Successful in 4m12s
All checks were successful
Build Docker Image / build (push) Successful in 4m12s
- Add bounds (west/south/east/north) parameters to GetNodes query - Add setBoundsFilter to useCatalogHubs, useCatalogSuppliers, useCatalogProducts - Replace client-side bounds filtering with backend query - Add early return to setProductFilter to avoid redundant fetches - Watch filterByBounds to trigger backend refetch when checkbox changes
This commit is contained in:
@@ -82,16 +82,6 @@ const onBoundsChange = (bounds: MapBounds) => {
|
||||
currentMapBounds.value = bounds
|
||||
}
|
||||
|
||||
// Check if item is within map bounds
|
||||
const isInBounds = (item: any, bounds: MapBounds | null): boolean => {
|
||||
if (!bounds) return true
|
||||
if (!item.latitude || !item.longitude) return false
|
||||
const lat = Number(item.latitude)
|
||||
const lng = Number(item.longitude)
|
||||
return lat >= bounds.south && lat <= bounds.north
|
||||
&& lng >= bounds.west && lng <= bounds.east
|
||||
}
|
||||
|
||||
const {
|
||||
catalogMode,
|
||||
selectMode,
|
||||
@@ -117,26 +107,17 @@ const {
|
||||
init: initProducts,
|
||||
setSupplierFilter,
|
||||
setHubFilter,
|
||||
clearFilters: clearProductFilters
|
||||
clearFilters: clearProductFilters,
|
||||
setBoundsFilter: setProductBoundsFilter
|
||||
} = useCatalogProducts()
|
||||
const { items: hubs, isLoading: hubsLoading, isLoadingMore: hubsLoadingMore, canLoadMore: hubsCanLoadMore, loadMore: loadMoreHubs, init: initHubs, setProductFilter: setHubProductFilter } = useCatalogHubs()
|
||||
const { items: suppliers, isLoading: suppliersLoading, isLoadingMore: suppliersLoadingMore, canLoadMore: suppliersCanLoadMore, loadMore: loadMoreSuppliers, init: initSuppliers, setProductFilter: setSupplierProductFilter } = useCatalogSuppliers()
|
||||
const { items: hubs, isLoading: hubsLoading, isLoadingMore: hubsLoadingMore, canLoadMore: hubsCanLoadMore, loadMore: loadMoreHubs, init: initHubs, setProductFilter: setHubProductFilter, setBoundsFilter: setHubBoundsFilter } = useCatalogHubs()
|
||||
const { items: suppliers, isLoading: suppliersLoading, isLoadingMore: suppliersLoadingMore, canLoadMore: suppliersCanLoadMore, loadMore: loadMoreSuppliers, init: initSuppliers, setProductFilter: setSupplierProductFilter, setBoundsFilter: setSupplierBoundsFilter } = useCatalogSuppliers()
|
||||
|
||||
// Filtered items by map bounds
|
||||
const filteredProducts = computed(() => {
|
||||
if (!filterByBounds.value || !currentMapBounds.value) return products.value
|
||||
return products.value.filter((p: any) => isInBounds(p, currentMapBounds.value))
|
||||
})
|
||||
|
||||
const filteredHubs = computed(() => {
|
||||
if (!filterByBounds.value || !currentMapBounds.value) return hubs.value
|
||||
return hubs.value.filter((h: any) => isInBounds(h, currentMapBounds.value))
|
||||
})
|
||||
|
||||
const filteredSuppliers = computed(() => {
|
||||
if (!filterByBounds.value || !currentMapBounds.value) return suppliers.value
|
||||
return suppliers.value.filter((s: any) => isInBounds(s, currentMapBounds.value))
|
||||
})
|
||||
// Items are now filtered on the backend via setBoundsFilter
|
||||
// These are simple pass-throughs to maintain template compatibility
|
||||
const filteredProducts = computed(() => products.value)
|
||||
const filteredHubs = computed(() => hubs.value)
|
||||
const filteredSuppliers = computed(() => suppliers.value)
|
||||
|
||||
// Selection loading state
|
||||
const selectionLoading = computed(() => {
|
||||
@@ -202,6 +183,14 @@ watch(productId, (newProductId) => {
|
||||
setSupplierProductFilter(newProductId || null)
|
||||
}, { immediate: true })
|
||||
|
||||
// Apply bounds filter when "filter by map bounds" is enabled
|
||||
watch([filterByBounds, currentMapBounds], ([enabled, bounds]) => {
|
||||
const boundsToApply = enabled && bounds ? bounds : null
|
||||
setHubBoundsFilter(boundsToApply)
|
||||
setSupplierBoundsFilter(boundsToApply)
|
||||
setProductBoundsFilter(boundsToApply)
|
||||
})
|
||||
|
||||
// Offers data for quote results
|
||||
const offers = ref<any[]>([])
|
||||
const offersLoading = ref(false)
|
||||
|
||||
Reference in New Issue
Block a user