Files
webapp/app/composables/useClusteredNodes.ts
Ruslan Bakiev 25f946b293
All checks were successful
Build Docker Image / build (push) Successful in 5m46s
Fix geo GraphQL schema mismatch: camelCase → snake_case
All geo .graphql operations and consuming code updated to match
server schema which uses snake_case field/argument names.
Removed non-existent QuoteCalculations query, using NearestOffers instead.
2026-03-09 21:45:57 +07:00

58 lines
1.4 KiB
TypeScript

import { GetClusteredNodesDocument } from './graphql/public/geo-generated'
import type { ClusterPoint } 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>,
) {
const { client } = useApolloClient('publicGeo')
const clusteredNodes = ref<ClusterPoint[]>([])
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,
},
fetchPolicy: 'network-only'
})
clusteredNodes.value = (data?.clustered_nodes ?? []).filter(Boolean) as ClusterPoint[]
} 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
}
}