Some checks failed
Build Docker Image / build (push) Failing after 1m29s
- Add hubCountries query and country filter for hubs page - Add getAvailableProducts query for offers (only products with active offers) - Add sourceLatitude/sourceLongitude to orders GraphQL - Fix ListMapLayout with position fixed for proper map height - GlobalSearchBar: make fields wider, remove unit selector - Remove status/isVerified filters from suppliers/offers (backend handles this)
68 lines
1.6 KiB
TypeScript
68 lines
1.6 KiB
TypeScript
import { GetSupplierProfilesDocument } from '~/composables/graphql/public/exchange-generated'
|
|
|
|
const PAGE_SIZE = 24
|
|
|
|
// Shared state across list and map views
|
|
const items = ref<any[]>([])
|
|
const total = ref(0)
|
|
const isLoading = ref(false)
|
|
const isLoadingMore = ref(false)
|
|
const isInitialized = ref(false)
|
|
|
|
export function useCatalogSuppliers() {
|
|
const { execute } = useGraphQL()
|
|
|
|
const itemsWithCoords = computed(() =>
|
|
items.value.filter(s => s.latitude && s.longitude)
|
|
)
|
|
|
|
const canLoadMore = computed(() => items.value.length < total.value)
|
|
|
|
const fetchPage = async (offset: number, replace = false) => {
|
|
if (replace) isLoading.value = true
|
|
try {
|
|
const data = await execute(
|
|
GetSupplierProfilesDocument,
|
|
{ limit: PAGE_SIZE, offset },
|
|
'public',
|
|
'exchange'
|
|
)
|
|
const next = data?.getSupplierProfiles || []
|
|
items.value = replace ? next : items.value.concat(next)
|
|
total.value = data?.getSupplierProfilesCount ?? total.value
|
|
isInitialized.value = true
|
|
} finally {
|
|
isLoading.value = false
|
|
}
|
|
}
|
|
|
|
const loadMore = async () => {
|
|
if (isLoadingMore.value) return
|
|
isLoadingMore.value = true
|
|
try {
|
|
await fetchPage(items.value.length)
|
|
} finally {
|
|
isLoadingMore.value = false
|
|
}
|
|
}
|
|
|
|
// Initialize data if not already loaded
|
|
const init = async () => {
|
|
if (!isInitialized.value && items.value.length === 0) {
|
|
await fetchPage(0, true)
|
|
}
|
|
}
|
|
|
|
return {
|
|
items,
|
|
total,
|
|
isLoading,
|
|
isLoadingMore,
|
|
itemsWithCoords,
|
|
canLoadMore,
|
|
fetchPage,
|
|
loadMore,
|
|
init
|
|
}
|
|
}
|