Skip to content

Commit a8b53a1

Browse files
committed
Fix products
1 parent 25d0b04 commit a8b53a1

File tree

2 files changed

+34
-16
lines changed

2 files changed

+34
-16
lines changed

components/Products/ProductGrid.vue

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,25 @@
44
<ProductSort />
55
</div>
66
<div id="product-container" class="flex flex-wrap items-center">
7-
<template v-if="store.loading">
8-
<SpinnerLoading />
9-
</template>
10-
<template v-else-if="store.error">
11-
<p>Error loading products.</p>
12-
</template>
13-
<template v-else>
7+
<template v-if="products.length > 0">
148
<ProductCard
15-
v-for="product in store.filteredProducts"
9+
v-for="product in products"
1610
:key="product.id"
1711
:product="product"
1812
/>
1913
</template>
14+
<template v-else>
15+
<p>No products are available.</p>
16+
</template>
2017
</div>
2118
</div>
2219
</template>
2320

2421
<script setup>
25-
import { useProductsStore } from "@/store/useProductsStore";
26-
27-
const store = useProductsStore();
28-
29-
if (store.products.length === 0) {
30-
await store.fetchProducts();
31-
}
22+
defineProps({
23+
products: {
24+
type: Array,
25+
required: true,
26+
},
27+
});
3228
</script>

pages/products.vue

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,34 @@
22
<div class="container mx-auto">
33
<div class="flex flex-wrap">
44
<ProductFilter />
5-
<ProductGrid />
5+
<div class="w-full md:w-3/4 p-4">
6+
<template v-if="pending">
7+
<SpinnerLoading />
8+
</template>
9+
<template v-else-if="error">
10+
<p>Error loading products.</p>
11+
</template>
12+
<template v-else>
13+
<ProductGrid :products="store.filteredProducts" />
14+
</template>
15+
</div>
616
</div>
717
</div>
818
</template>
919

1020
<script setup>
21+
import { useProductsStore } from "@/store/useProductsStore";
22+
import FETCH_ALL_PRODUCTS_QUERY from "@/apollo/queries/FETCH_ALL_PRODUCTS_QUERY.gql";
23+
24+
const store = useProductsStore();
25+
26+
const { data, pending, error } = await useAsyncQuery(FETCH_ALL_PRODUCTS_QUERY);
27+
28+
if (data.value) {
29+
store.products = data.value.products.nodes;
30+
store.productTypes = store.getUniqueProductTypes;
31+
}
32+
1133
useHead({
1234
title: "Products",
1335
titleTemplate: "%s - Nuxt 3 Woocommerce",

0 commit comments

Comments
 (0)