Skip to content

Show products #1478

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 10 additions & 14 deletions components/Products/ProductGrid.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,25 @@
<ProductSort />
</div>
<div id="product-container" class="flex flex-wrap items-center">
<template v-if="store.loading">
<SpinnerLoading />
</template>
<template v-else-if="store.error">
<p>Error loading products.</p>
</template>
<template v-else>
<template v-if="products.length > 0">
<ProductCard
v-for="product in store.filteredProducts"
v-for="product in products"
:key="product.id"
:product="product"
/>
</template>
<template v-else>
<p>No products are available.</p>
</template>
</div>
</div>
</template>

<script setup>
import { useProductsStore } from "@/store/useProductsStore";

const store = useProductsStore();

onMounted(() => {
store.fetchProducts();
defineProps({
products: {
type: Array,
required: true,
},
});
</script>
24 changes: 23 additions & 1 deletion pages/products.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,34 @@
<div class="container mx-auto">
<div class="flex flex-wrap">
<ProductFilter />
<ProductGrid />
<div class="w-full md:w-3/4 p-4">
<template v-if="pending">
<SpinnerLoading />
</template>
<template v-else-if="error">
<p>Error loading products.</p>
</template>
<template v-else>
<ProductGrid :products="store.filteredProducts" />
</template>
</div>
</div>
</div>
</template>

<script setup>
import { useProductsStore } from "@/store/useProductsStore";
import FETCH_ALL_PRODUCTS_QUERY from "@/apollo/queries/FETCH_ALL_PRODUCTS_QUERY.gql";

const store = useProductsStore();

const { data, pending, error } = await useAsyncQuery(FETCH_ALL_PRODUCTS_QUERY);

if (data.value) {
store.products = data.value.products.nodes;
store.productTypes = store.getUniqueProductTypes;
}

useHead({
title: "Products",
titleTemplate: "%s - Nuxt 3 Woocommerce",
Expand Down