Fix type safety in catalog composables + 3 InfoPanel bugs
All checks were successful
Build Docker Image / build (push) Successful in 3m42s
All checks were successful
Build Docker Image / build (push) Successful in 3m42s
- Add proper codegen types to all catalog composables: - useCatalogHubs: HubItem, NearestHubItem - useCatalogSuppliers: SupplierItem, NearestSupplierItem - useCatalogProducts: ProductItem - useCatalogOffers: OfferItem - useCatalogInfo: InfoEntity, ProductItem, HubItem, OfferItem - Fix InfoPanel bugs for offers: - Use locationLatitude/locationLongitude for offer coordinates - Enrich entity with supplierName after loading profile - Apply-to-filter now adds both product AND hub for offers - Filter null values from GraphQL array responses - Add type-safe coordinate helper (getEntityCoords) - Fix urlBounds type inference in useCatalogSearch
This commit is contained in:
@@ -1,9 +1,14 @@
|
||||
import type { SuppliersListQueryResult, NearestSuppliersQueryResult } from '~/composables/graphql/public/geo-generated'
|
||||
import { SuppliersListDocument, NearestSuppliersDocument } from '~/composables/graphql/public/geo-generated'
|
||||
|
||||
const PAGE_SIZE = 24
|
||||
|
||||
// Types from codegen
|
||||
type SupplierItem = NonNullable<NonNullable<SuppliersListQueryResult['suppliersList']>[number]>
|
||||
type NearestSupplierItem = NonNullable<NonNullable<NearestSuppliersQueryResult['nearestSuppliers']>[number]>
|
||||
|
||||
// Shared state across list and map views
|
||||
const items = ref<any[]>([])
|
||||
const items = ref<Array<SupplierItem | NearestSupplierItem>>([])
|
||||
const total = ref(0)
|
||||
const isLoading = ref(false)
|
||||
const isLoadingMore = ref(false)
|
||||
@@ -15,7 +20,7 @@ export function useCatalogSuppliers() {
|
||||
const { execute } = useGraphQL()
|
||||
|
||||
const itemsWithCoords = computed(() =>
|
||||
items.value.filter(s => s.latitude && s.longitude)
|
||||
items.value.filter((s): s is NearestSupplierItem => 'latitude' in s && 'longitude' in s && s.latitude != null && s.longitude != null)
|
||||
)
|
||||
|
||||
const canLoadMore = computed(() => items.value.length < total.value)
|
||||
@@ -38,7 +43,7 @@ export function useCatalogSuppliers() {
|
||||
'public',
|
||||
'geo'
|
||||
)
|
||||
items.value = data?.nearestSuppliers || []
|
||||
items.value = (data?.nearestSuppliers || []).filter((s): s is NearestSupplierItem => s !== null)
|
||||
total.value = items.value.length
|
||||
isInitialized.value = true
|
||||
return
|
||||
@@ -60,7 +65,7 @@ export function useCatalogSuppliers() {
|
||||
'public',
|
||||
'geo'
|
||||
)
|
||||
const next = data?.suppliersList || []
|
||||
const next = (data?.suppliersList || []).filter((s): s is SupplierItem => s !== null)
|
||||
|
||||
items.value = replace ? next : items.value.concat(next)
|
||||
// suppliersList doesn't return total count, estimate from fetched items
|
||||
|
||||
Reference in New Issue
Block a user