Some checks failed
Build Docker Image / build (push) Failing after 1m35s
- Replace FindProductRoutesDocument with GetOffersToHubDocument - Replace FindSupplierProductHubsDocument with GetOffersBySupplierProductDocument + GetHubsNearOfferDocument - Update all catalog pages to use new query naming convention - Add new GraphQL operation files, remove deprecated ones
42 lines
836 B
TypeScript
42 lines
836 B
TypeScript
import { GetProductsDocument } from '~/composables/graphql/public/geo-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(
|
|
GetProductsDocument,
|
|
{},
|
|
'public',
|
|
'geo'
|
|
)
|
|
items.value = data?.products || []
|
|
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
|
|
}
|
|
}
|