|
52 | 52 | <div class="pt-1 mt-2"> |
53 | 53 | <CommonButton |
54 | 54 | @common-button-click="addProductToCart(data.product)" |
55 | | - :is-loading="isLoading" |
| 55 | + :is-loading="isTestLoading" |
56 | 56 | > |
57 | 57 | ADD TO CART</CommonButton |
58 | 58 | > |
@@ -87,10 +87,11 @@ import { stripHTML, filteredVariantName } from "@/utils/functions"; |
87 | 87 |
|
88 | 88 | import { useCart } from "@/store/useCart"; |
89 | 89 |
|
90 | | -const isLoading = useState("isLoading", () => false); |
91 | | -
|
92 | 90 | const cart = useCart(); |
93 | 91 |
|
| 92 | +// You can now access the loading state directly from the cart store |
| 93 | +const isTestLoading = computed(() => cart.loading); |
| 94 | +
|
94 | 95 | const selectedVariation = ref(); // TODO Pass this value to addProductToCart() |
95 | 96 |
|
96 | 97 | const props = defineProps({ |
@@ -119,43 +120,12 @@ watch( |
119 | 120 | * @return {Promise<void>} A Promise that resolves when the product has been successfully added to the cart. |
120 | 121 | */ |
121 | 122 | const addProductToCart = async (product) => { |
122 | | - const productId = product.databaseId ? product.databaseId : product; |
123 | | - const productQueryInput = { |
124 | | - productId, |
125 | | - }; |
126 | | -
|
127 | | - isLoading.value = true; |
128 | | -
|
129 | | - const addToCartvariables = { input: productQueryInput }; |
130 | | -
|
131 | 123 | cart.addToCart(product); |
132 | 124 |
|
133 | | - const { mutate, onDone, onError } = useMutation(ADD_TO_CART_MUTATION, { |
134 | | - addToCartvariables, |
135 | | - }); |
136 | | -
|
137 | | - // mutate(addToCartvariables); |
138 | | -
|
139 | | - console.log("We should have added the product here, but it is disabled"); |
140 | | -
|
141 | | - console.log("Before Triggering a refresh"); |
142 | | -
|
143 | 125 | watchEffect(() => { |
144 | | - console.log("watchEffect isLoading.value:", isLoading.value); |
145 | | -
|
146 | | - if (isLoading.value === false) { |
| 126 | + if (isTestLoading.value === false) { |
147 | 127 | window.location.reload(); |
148 | 128 | } |
149 | 129 | }); |
150 | | -
|
151 | | - onDone(() => { |
152 | | - isLoading.value = false; |
153 | | - // Refresh the page |
154 | | - window.location.reload(); |
155 | | - }); |
156 | | -
|
157 | | - onError(() => { |
158 | | - isLoading.value = false; |
159 | | - }); |
160 | 130 | }; |
161 | 131 | </script> |
0 commit comments