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)
42 lines
876 B
TypeScript
42 lines
876 B
TypeScript
import { GetAvailableProductsDocument } from '~/composables/graphql/public/exchange-generated'
|
|
|
|
// Shared state
|
|
const items = ref<any[]>([])
|
|
const isLoading = ref(false)
|
|
const isInitialized = ref(false)
|
|
|
|
export function useCatalogProducts() {
|
|
const { execute } = useGraphQL()
|
|
|
|
const fetchProducts = async () => {
|
|
if (isLoading.value) return
|
|
isLoading.value = true
|
|
try {
|
|
const data = await execute(
|
|
GetAvailableProductsDocument,
|
|
{},
|
|
'public',
|
|
'exchange'
|
|
)
|
|
items.value = data?.getAvailableProducts || []
|
|
isInitialized.value = true
|
|
} finally {
|
|
isLoading.value = false
|
|
}
|
|
}
|
|
|
|
const init = async () => {
|
|
if (!isInitialized.value && items.value.length === 0) {
|
|
await fetchProducts()
|
|
}
|
|
}
|
|
|
|
return {
|
|
items,
|
|
isLoading,
|
|
isInitialized,
|
|
fetchProducts,
|
|
init
|
|
}
|
|
}
|