Skip to content

Commit 4c0146b

Browse files
authored
Merge pull request #992 from w3bdesign/991-refactor-more-code
991 refactor more code
2 parents 36ded01 + 137370a commit 4c0146b

File tree

9 files changed

+94
-71
lines changed

9 files changed

+94
-71
lines changed

components/Cart/CartCheckoutButton.vue

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

components/Cart/CartContents.vue

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,11 @@
4545
>
4646
Cart is currently empty
4747
</h2>
48-
<CartCheckoutButton
48+
<CommonButton
49+
link-to="/checkout"
4950
v-if="showCheckoutButton && data.cart?.contents?.nodes?.length"
50-
/>
51+
>CHECKOUT</CommonButton
52+
>
5153
</div>
5254
</template>
5355

components/Category/CategoryShowProducts.vue

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

components/Products/ProductsShowAll.vue

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +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+
67+
const config = useRuntimeConfig();
68+
6069
const productImage = (product) =>
61-
product.image ? product.image.sourceUrl : process.env.placeholderSmallImage;
70+
product.image ? product.image.sourceUrl : config.placeholderImage;
6271
63-
const variables = { limit: 99 };
64-
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+
}
6585
</script>
6686

6787
<style scoped>

components/common/CommonButton.vue

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,32 @@
11
<template>
2-
<div>
2+
<div v-if="linkTo" class="flex justify-center">
3+
<NuxtLink :to="linkTo" class="button-link">
4+
<button
5+
:class="{ disabled: isLoading }"
6+
@click="$emit('CommonButtonClick')"
7+
>
8+
<slot />
9+
<svg
10+
v-if="isLoading"
11+
class="absolute -mt-6 -ml-2 animate-spin"
12+
width="25"
13+
height="25"
14+
viewBox="0 0 24 24"
15+
fill="none"
16+
xmlns="http://www.w3.org/2000/svg"
17+
>
18+
<path
19+
fill-rule="evenodd"
20+
clip-rule="evenodd"
21+
d="M12 0C5.37258 0 0 5.37258 0 12C0 18.6274 5.37258 24 12 24C18.6274 24 24 18.6274 24 12C24 5.37258 18.6274 0 12 0ZM4.14355 13.5165C4.85219 17.2096 8.10023 20 12 20C16.4183 20 20 16.4183 20 12C20 7.58172 16.4183 4 12 4C8.0886 4 4.83283 6.80704 4.13728 10.5165L6.72824 10.5071C7.37819 8.20738 9.49236 6.52222 12.0001 6.52222C15.0254 6.52222 17.4779 8.9747 17.4779 12C17.4779 15.0253 15.0254 17.4778 12.0001 17.4778C9.49752 17.4778 7.3869 15.7995 6.73228 13.5071L4.14355 13.5165ZM9.52234 12C9.52234 13.3684 10.6317 14.4778 12.0001 14.4778C13.3685 14.4778 14.4779 13.3684 14.4779 12C14.4779 10.6316 13.3685 9.52222 12.0001 9.52222C10.6317 9.52222 9.52234 10.6316 9.52234 12Z"
22+
fill="white"
23+
/>
24+
</svg>
25+
</button>
26+
</NuxtLink>
27+
</div>
28+
<div v-else class="flex justify-center">
329
<button
4-
class="relative w-48 h-12 px-4 py-2 mt-4 transition ease-in-out delay-75 duration-300 font-bold text-white bg-blue-500 rounded hover:bg-blue-800"
530
:class="{ disabled: isLoading }"
631
@click="$emit('CommonButtonClick')"
732
>
@@ -27,8 +52,9 @@
2752
</template>
2853

2954
<script setup>
30-
/* Usage:
31-
* <CommonButton @common-button-click="function name" isLoading="true">Common button</CommonButton>
55+
/*
56+
* Usage:
57+
* <CommonButton @common-button-click="functionName" isLoading="true">Common button</CommonButton>
3258
*/
3359
3460
defineEmits(["CommonButtonClick"]);
@@ -39,11 +65,24 @@ defineProps({
3965
required: false,
4066
default: false,
4167
},
68+
linkTo: {
69+
type: String,
70+
required: false,
71+
default: "",
72+
},
4273
});
4374
</script>
4475

4576
<style scoped>
4677
.disabled {
4778
@apply bg-blue-500 text-white font-bold py-2 px-4 rounded opacity-50 cursor-not-allowed;
4879
}
80+
81+
button {
82+
@apply relative w-48 h-12 px-4 py-2 mt-4 transition ease-in-out delay-75 duration-300 font-bold text-white bg-blue-500 rounded hover:bg-blue-800;
83+
}
84+
85+
.button-link {
86+
border-bottom: none;
87+
}
4988
</style>

nuxt.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export default defineNuxtConfig({
1616
runtimeConfig: {
1717
public: {
1818
graphqlURL: process.env.PUBLIC_GRAPHQL_URL,
19+
indexName: process.env.PUBLIC_ALGOLIA_INDEX_NAME,
1920
placeholderImage: process.env.PUBLIC_PLACEHOLDER_SMALL_IMAGE_URL,
2021
},
2122
},

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",

pages/search.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ import {
4242
AisHits,
4343
} from "vue-instantsearch/vue3/es/index.js";
4444
45-
const indexName = "dfweb";
45+
const config = useRuntimeConfig();
46+
47+
const indexName = config.indexName;
4648
const algolia = useAlgoliaRef();
4749
4850
const convertProductNameToSlug = (productName) =>

pages/success.vue

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,22 @@
55
</div>
66
</template>
77

8+
<script setup>
9+
useHead({
10+
title: "Order placed",
11+
titleTemplate: "%s - Nuxt 3 Woocommerce",
12+
meta: [
13+
{ name: "viewport", content: "width=device-width, initial-scale=1" },
14+
{
15+
hid: "description",
16+
name: "description",
17+
content: "Nuxt 3 Woocommerce",
18+
},
19+
],
20+
link: [{ rel: "icon", type: "image/x-icon", href: "/favicon.ico" }],
21+
});
22+
</script>
23+
824
<style scoped>
925
h1 {
1026
@apply h-10 p-6 text-3xl font-bold text-center;

0 commit comments

Comments
 (0)