diff --git a/app/pages/catalog/index.vue b/app/pages/catalog/index.vue index 9480caf..7d290cc 100644 --- a/app/pages/catalog/index.vue +++ b/app/pages/catalog/index.vue @@ -100,6 +100,7 @@ const catalogPageRef = ref<{ currentBounds: Ref } | null>(null // Current map bounds (local state, updated when map moves) const currentMapBounds = ref(null) +const selectionBoundsBackup = ref<{ hadBounds: boolean; bounds: { west: number; south: number; east: number; north: number } | null } | null>(null) // Hovered item for map highlight const hoveredItemId = ref(null) @@ -235,8 +236,43 @@ const onLoadMore = () => { if (selectMode.value === 'supplier') loadMoreSuppliers() } +const getSelectionBounds = () => { + const bounds = currentMapBounds.value ?? catalogPageRef.value?.currentBounds?.value ?? null + if (!bounds) return null + return { west: bounds.west, south: bounds.south, east: bounds.east, north: bounds.north } +} + +const applySelectionBounds = () => { + if (!selectionBoundsBackup.value) { + selectionBoundsBackup.value = { + hadBounds: !!urlBounds.value, + bounds: urlBounds.value + } + } + const bounds = getSelectionBounds() + if (bounds) { + setBoundsInUrl(bounds) + } +} + +const restoreSelectionBounds = () => { + const prev = selectionBoundsBackup.value + if (!prev) return + if (prev.hadBounds && prev.bounds) { + setBoundsInUrl(prev.bounds) + } else { + clearBoundsFromUrl() + } + selectionBoundsBackup.value = null +} + // Initialize data and sync map view when selectMode changes watch(selectMode, async (mode) => { + if (mode) { + applySelectionBounds() + } else { + restoreSelectionBounds() + } if (mode === 'product') { await initProducts() setMapViewMode('offers')