Skip to content

Commit c9c1af8

Browse files
committed
Refactor code
1 parent 8d8d244 commit c9c1af8

File tree

3 files changed

+24
-46
lines changed

3 files changed

+24
-46
lines changed

components/Category/CategoryShowProducts.vue

Lines changed: 0 additions & 30 deletions
This file was deleted.

components/Products/ProductsShowAll.vue

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,33 @@
5555

5656
<script setup>
5757
import FETCH_ALL_PRODUCTS_QUERY from "@/apollo/queries/FETCH_ALL_PRODUCTS_QUERY.gql";
58+
import GET_PRODUCTS_FROM_CATEGORY_QUERY from "@/apollo/queries/GET_PRODUCTS_FROM_CATEGORY_QUERY.gql";
59+
5860
import { filteredVariantPrice } from "@/utils/functions";
5961
62+
const props = defineProps({
63+
categoryId: { type: String, required: false },
64+
categorySlug: { type: String, required: false },
65+
});
66+
6067
const config = useRuntimeConfig();
6168
6269
const productImage = (product) =>
6370
product.image ? product.image.sourceUrl : config.placeholderImage;
6471
65-
const variables = { limit: 99 };
66-
const { data } = await useAsyncQuery(FETCH_ALL_PRODUCTS_QUERY, variables);
72+
const productVariables = { limit: 99 };
73+
const { data } = await useAsyncQuery(
74+
FETCH_ALL_PRODUCTS_QUERY,
75+
productVariables
76+
);
77+
78+
if (props.id) {
79+
const categoryVariables = { id: props.categoryId, slug: props.categorySlug };
80+
const { data } = await useAsyncQuery(
81+
GET_PRODUCTS_FROM_CATEGORY_QUERY,
82+
categoryVariables
83+
);
84+
}
6785
</script>
6886

6987
<style scoped>

pages/category/[category].vue

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,13 @@
11
<template>
2-
<div v-if="data?.productCategory">
3-
<CategoryShowProducts :products="data.productCategory" />
4-
</div>
5-
<div v-else>
6-
<SpinnerLoading />
7-
</div>
2+
<ProductsShowAll
3+
:category-id="route.query.id"
4+
:category-slug="route.params.product"
5+
/>
86
</template>
97

108
<script setup>
11-
import GET_PRODUCTS_FROM_CATEGORY_QUERY from "@/apollo/queries/GET_PRODUCTS_FROM_CATEGORY_QUERY.gql";
12-
139
const route = useRoute();
1410
15-
const variables = { id: route.query.id, slug: route.params.category };
16-
const { data } = await useAsyncQuery(
17-
GET_PRODUCTS_FROM_CATEGORY_QUERY,
18-
variables
19-
);
20-
2111
useHead({
2212
title: route.params.category,
2313
titleTemplate: "%s - Nuxt 3 Woocommerce",

0 commit comments

Comments
 (0)