Add filter by map bounds checkbox to SelectionPanel
All checks were successful
Build Docker Image / build (push) Successful in 3m36s
All checks were successful
Build Docker Image / build (push) Successful in 3m36s
- Remove map search input (was wrong implementation) - Add checkbox "In map area" to filter list by visible map bounds - Filter products/hubs/suppliers when checkbox is enabled - Disable "load more" when filtering by bounds (client-side only)
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
<template>
|
||||
<CatalogPage
|
||||
ref="catalogPageRef"
|
||||
:loading="isLoading"
|
||||
:use-server-clustering="true"
|
||||
:cluster-node-type="clusterNodeType"
|
||||
@@ -8,6 +9,7 @@
|
||||
:items="[]"
|
||||
:show-panel="showPanel"
|
||||
@select="onMapSelect"
|
||||
@bounds-change="onBoundsChange"
|
||||
>
|
||||
<!-- Panel slot - shows selection list OR quote results -->
|
||||
<template #panel>
|
||||
@@ -15,15 +17,17 @@
|
||||
<SelectionPanel
|
||||
v-if="selectMode"
|
||||
:select-mode="selectMode"
|
||||
:products="products"
|
||||
:hubs="hubs"
|
||||
:suppliers="suppliers"
|
||||
:products="filteredProducts"
|
||||
:hubs="filteredHubs"
|
||||
:suppliers="filteredSuppliers"
|
||||
:loading="selectionLoading"
|
||||
:loading-more="selectionLoadingMore"
|
||||
:has-more="selectionHasMore"
|
||||
:has-more="selectionHasMore && !filterByBounds"
|
||||
:filter-by-bounds="filterByBounds"
|
||||
@select="onSelectItem"
|
||||
@close="cancelSelect"
|
||||
@load-more="onLoadMore"
|
||||
@update:filter-by-bounds="filterByBounds = $event"
|
||||
/>
|
||||
|
||||
<!-- Quote results: show offers after search -->
|
||||
@@ -39,6 +43,7 @@
|
||||
|
||||
<script setup lang="ts">
|
||||
import { GetOffersDocument } from '~/composables/graphql/public/exchange-generated'
|
||||
import type { MapBounds } from '~/components/catalog/CatalogMap.vue'
|
||||
|
||||
definePageMeta({
|
||||
layout: 'topnav'
|
||||
@@ -49,6 +54,28 @@ const { execute } = useGraphQL()
|
||||
const router = useRouter()
|
||||
const localePath = useLocalePath()
|
||||
|
||||
// Ref to CatalogPage for accessing bounds
|
||||
const catalogPageRef = ref<{ currentBounds: Ref<MapBounds | null> } | null>(null)
|
||||
|
||||
// Filter by map bounds state
|
||||
const filterByBounds = ref(false)
|
||||
const currentMapBounds = ref<MapBounds | null>(null)
|
||||
|
||||
// Handle bounds change from map
|
||||
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,
|
||||
@@ -69,6 +96,22 @@ const { items: products, isLoading: productsLoading, isLoadingMore: productsLoad
|
||||
const { items: hubs, isLoading: hubsLoading, isLoadingMore: hubsLoadingMore, canLoadMore: hubsCanLoadMore, loadMore: loadMoreHubs, init: initHubs } = useCatalogHubs()
|
||||
const { items: suppliers, isLoading: suppliersLoading, isLoadingMore: suppliersLoadingMore, canLoadMore: suppliersCanLoadMore, loadMore: loadMoreSuppliers, init: initSuppliers } = 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))
|
||||
})
|
||||
|
||||
// Selection loading state
|
||||
const selectionLoading = computed(() => {
|
||||
if (selectMode.value === 'product') return productsLoading.value
|
||||
|
||||
Reference in New Issue
Block a user