Skip to content

Commit aaefb68

Browse files
committed
Refactor and fix variations bug
1 parent 09ae78c commit aaefb68

File tree

4 files changed

+33
-42
lines changed

4 files changed

+33
-42
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<template>
2+
<li
3+
class="inline-block py-2 text-xl font-semibold no-underline lg:text-base lg:px-4"
4+
>
5+
<NuxtLink :to="to">
6+
<span class="text-xl text-white no-underline lg:text-black">
7+
{{ label }}
8+
</span>
9+
</NuxtLink>
10+
</li>
11+
</template>
12+
13+
<script setup>
14+
const props = defineProps({
15+
to: {
16+
type: String,
17+
required: true,
18+
},
19+
label: {
20+
type: String,
21+
required: true,
22+
},
23+
});
24+
</script>

components/Layout/LayoutNavbar.vue

Lines changed: 5 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -30,46 +30,10 @@
3030
<ul
3131
class="items-center justify-end flex-1 pr-4 -mr-4 list-reset lg:flex"
3232
>
33-
<li
34-
class="inline-block py-2 text-xl font-semibold no-underline lg:text-base lg:px-4"
35-
>
36-
<NuxtLink to="/">
37-
<span
38-
class="text-xl text-white no-underline lg:text-black is-active"
39-
>
40-
Home
41-
</span>
42-
</NuxtLink>
43-
</li>
44-
<li
45-
class="inline-block py-2 text-xl font-semibold no-underline lg:text-base lg:px-4"
46-
>
47-
<NuxtLink to="/products">
48-
<span class="text-xl text-white no-underline lg:text-black"
49-
>Products</span
50-
>
51-
</NuxtLink>
52-
</li>
53-
<li
54-
class="inline-block py-2 text-xl font-semibold no-underline lg:text-base lg:px-4"
55-
>
56-
<NuxtLink to="/categories">
57-
<span
58-
class="text-xl text-white no-underline lg:text-black is-active"
59-
>Categories</span
60-
>
61-
</NuxtLink>
62-
</li>
63-
<li
64-
class="inline-block py-2 text-xl font-semibold no-underline lg:text-base lg:px-4"
65-
>
66-
<NuxtLink to="/search">
67-
<span
68-
class="text-xl text-white no-underline lg:text-black is-active"
69-
>Search</span
70-
>
71-
</NuxtLink>
72-
</li>
33+
<NavItem to="/" label="Home" />
34+
<NavItem to="/products" label="Products" />
35+
<NavItem to="/categories" label="Categories" />
36+
<NavItem to="/search" label="Search" />
7337
<li
7438
class="inline-block py-2 text-xl font-semibold no-underline lg:text-base lg:px-4"
7539
>
@@ -90,6 +54,7 @@
9054
* Vue.js template for a header section of a web page.
9155
*
9256
*/
57+
import NavItem from "@/components/Layout/LayoutNavItem.vue";
9358
</script>
9459

9560
<style scoped>

components/Products/ProductsSingleProduct.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ const { data } = await useAsyncQuery(GET_SINGLE_PRODUCT_QUERY, variables);
7878
watch(
7979
() => data.value,
8080
(dataValue) => {
81-
if (dataValue && dataValue.product.variations.nodes.length > 0) {
82-
selectedVariation.value = dataValue.product.variations.nodes[0].databaseId;
81+
if (dataValue && dataValue.product?.variations?.nodes?.length > 0) {
82+
selectedVariation.value = dataValue.product?.variations?.nodes[0].databaseId;
8383
}
8484
},
8585
{ immediate: true }

layouts/default.vue

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
<template>
2+
<div>
23
<LayoutNavbar />
34
<div class="container mx-auto max-w-[84.375rem]">
45
<slot />
56
</div>
67
<LayoutFooter />
78
<LayoutStickyFooter />
9+
</div>
810
</template>
911

1012
<style>

0 commit comments

Comments
 (0)