fix(catalog): prevent unnecessary list reloads on map movement
All checks were successful
Build Docker Image / build (push) Successful in 4m14s
All checks were successful
Build Docker Image / build (push) Successful in 4m14s
- Remove currentMapBounds from watch - it changes on every map move - Watch only filterByBounds and urlBounds (URL-based state) - Add early return in setBoundsFilter if bounds haven't changed This fixes the issue where the list was reloading on every map movement even when the 'filter by bounds' checkbox was OFF.
This commit is contained in:
@@ -144,6 +144,17 @@ export function useCatalogHubs() {
|
||||
}
|
||||
|
||||
const setBoundsFilter = (bounds: { west: number; south: number; east: number; north: number } | null) => {
|
||||
// Early return if bounds haven't changed
|
||||
const prev = filterBounds.value
|
||||
const same = prev === bounds || (
|
||||
prev && bounds &&
|
||||
prev.west === bounds.west &&
|
||||
prev.south === bounds.south &&
|
||||
prev.east === bounds.east &&
|
||||
prev.north === bounds.north
|
||||
)
|
||||
if (same) return
|
||||
|
||||
filterBounds.value = bounds
|
||||
if (isInitialized.value) {
|
||||
fetchPage(0, true)
|
||||
|
||||
@@ -179,6 +179,17 @@ export function useCatalogProducts() {
|
||||
|
||||
// Products are filtered by offer locations within bounds
|
||||
const setBoundsFilter = (bounds: { west: number; south: number; east: number; north: number } | null) => {
|
||||
// Early return if bounds haven't changed
|
||||
const prev = filterBounds.value
|
||||
const same = prev === bounds || (
|
||||
prev && bounds &&
|
||||
prev.west === bounds.west &&
|
||||
prev.south === bounds.south &&
|
||||
prev.east === bounds.east &&
|
||||
prev.north === bounds.north
|
||||
)
|
||||
if (same) return
|
||||
|
||||
filterBounds.value = bounds
|
||||
if (isInitialized.value) {
|
||||
fetchProducts()
|
||||
|
||||
@@ -101,6 +101,17 @@ export function useCatalogSuppliers() {
|
||||
}
|
||||
|
||||
const setBoundsFilter = (bounds: { west: number; south: number; east: number; north: number } | null) => {
|
||||
// Early return if bounds haven't changed
|
||||
const prev = filterBounds.value
|
||||
const same = prev === bounds || (
|
||||
prev && bounds &&
|
||||
prev.west === bounds.west &&
|
||||
prev.south === bounds.south &&
|
||||
prev.east === bounds.east &&
|
||||
prev.north === bounds.north
|
||||
)
|
||||
if (same) return
|
||||
|
||||
filterBounds.value = bounds
|
||||
if (isInitialized.value) {
|
||||
fetchPage(0, true)
|
||||
|
||||
@@ -237,11 +237,10 @@ watch(productId, (newProductId) => {
|
||||
}, { immediate: true })
|
||||
|
||||
// Apply bounds filter when "filter by map bounds" is enabled
|
||||
// Use URL bounds if available, otherwise use current map bounds
|
||||
watch([filterByBounds, urlBounds, currentMapBounds], ([enabled, urlB, mapB]) => {
|
||||
// Use URL bounds if available, otherwise current map bounds
|
||||
const bounds = urlB || mapB
|
||||
const boundsToApply = enabled && bounds ? bounds : null
|
||||
// Only watch URL bounds - currentMapBounds changes too often (every map move)
|
||||
watch([filterByBounds, urlBounds], ([enabled, urlB]) => {
|
||||
// Apply bounds filter only when checkbox is ON and bounds are in URL
|
||||
const boundsToApply = enabled && urlB ? urlB : null
|
||||
setHubBoundsFilter(boundsToApply)
|
||||
setSupplierBoundsFilter(boundsToApply)
|
||||
setProductBoundsFilter(boundsToApply)
|
||||
|
||||
Reference in New Issue
Block a user