Files
webapp/app/composables/useClusteredNodes.ts
Ruslan Bakiev 755a92d194
All checks were successful
Build Docker Image / build (push) Successful in 5m1s
feat(catalog): filter map clusters by chips
2026-02-07 08:35:22 +07:00

64 lines
1.6 KiB
TypeScript

import { GetClusteredNodesDocument } from './graphql/public/geo-generated'
import type { ClusterPointType } from './graphql/public/geo-generated'
export interface MapBounds {
west: number
south: number
east: number
north: number
zoom: number
}
export function useClusteredNodes(
transportType?: Ref<string | undefined>,
nodeType?: Ref<string | undefined>,
productUuid?: Ref<string | undefined>,
hubUuid?: Ref<string | undefined>,
supplierUuid?: Ref<string | undefined>
) {
const { client } = useApolloClient('publicGeo')
const clusteredNodes = ref<ClusterPointType[]>([])
const loading = ref(false)
const fetchClusters = async (bounds: MapBounds) => {
loading.value = true
try {
const { data } = await client.query({
query: GetClusteredNodesDocument,
variables: {
west: bounds.west,
south: bounds.south,
east: bounds.east,
north: bounds.north,
zoom: Math.floor(bounds.zoom),
transportType: transportType?.value,
nodeType: nodeType?.value,
productUuid: productUuid?.value,
hubUuid: hubUuid?.value,
supplierUuid: supplierUuid?.value
},
fetchPolicy: 'network-only'
})
clusteredNodes.value = (data?.clusteredNodes ?? []).filter(Boolean) as ClusterPointType[]
} catch (error) {
console.error('Failed to fetch clustered nodes:', error)
clusteredNodes.value = []
} finally {
loading.value = false
}
}
const clearNodes = () => {
clusteredNodes.value = []
}
return {
clusteredNodes,
loading,
fetchClusters,
clearNodes
}
}