Skip to content

Commit 49f0121

Browse files
committed
.
1 parent d689237 commit 49f0121

File tree

2 files changed

+10
-35
lines changed

2 files changed

+10
-35
lines changed

components/Products/ProductsSingleProduct.vue

Lines changed: 5 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
<div class="pt-1 mt-2">
5353
<CommonButton
5454
@common-button-click="addProductToCart(data.product)"
55-
:is-loading="isLoading"
55+
:is-loading="isTestLoading"
5656
>
5757
ADD TO CART</CommonButton
5858
>
@@ -87,10 +87,11 @@ import { stripHTML, filteredVariantName } from "@/utils/functions";
8787
8888
import { useCart } from "@/store/useCart";
8989
90-
const isLoading = useState("isLoading", () => false);
91-
9290
const cart = useCart();
9391
92+
// You can now access the loading state directly from the cart store
93+
const isTestLoading = computed(() => cart.loading);
94+
9495
const selectedVariation = ref(); // TODO Pass this value to addProductToCart()
9596
9697
const props = defineProps({
@@ -119,43 +120,12 @@ watch(
119120
* @return {Promise<void>} A Promise that resolves when the product has been successfully added to the cart.
120121
*/
121122
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-
131123
cart.addToCart(product);
132124
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-
143125
watchEffect(() => {
144-
console.log("watchEffect isLoading.value:", isLoading.value);
145-
146-
if (isLoading.value === false) {
126+
if (isTestLoading.value === false) {
147127
window.location.reload();
148128
}
149129
});
150-
151-
onDone(() => {
152-
isLoading.value = false;
153-
// Refresh the page
154-
window.location.reload();
155-
});
156-
157-
onError(() => {
158-
isLoading.value = false;
159-
});
160130
};
161131
</script>

store/useCart.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export const useCart = defineStore("cartState", {
3636

3737
if (response.data && response.data.addToCart) {
3838
console.log("Response from Add To Cart mutation:", response);
39+
this.loading = false;
3940
// Assuming the response returns the updated cart item, we need to handle it properly
4041
const newCartItem = response.data.addToCart.cartItem;
4142
const foundProductInCartIndex = this.cart.findIndex(
@@ -81,6 +82,10 @@ export const useCart = defineStore("cartState", {
8182
*/
8283

8384
getCartQuantity() {
85+
86+
//console.log("Cart is:", this.cart);
87+
88+
8489
if (!this.cart) {
8590
console.error("Cart is undefined");
8691
return 0;

0 commit comments

Comments
 (0)