Skip to content

Commit 23bcb3f

Browse files
authored
Merge pull request #1288 from w3bdesign/dev
Dev
2 parents 0878ff0 + d19c451 commit 23bcb3f

File tree

5 files changed

+12
-29
lines changed

5 files changed

+12
-29
lines changed

components/Cart/CartContents.vue

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ import UPDATE_CART_MUTATION from "@/apollo/mutations/UPDATE_CART_MUTATION.gql";
3030
3131
import { useCart } from "@/store/useCart";
3232
33-
const isRemoving = useState("isRemoving", () => false);
34-
3533
const cart = useCart();
3634
3735
defineProps({
@@ -55,8 +53,6 @@ const handleRemoveProduct = (product) => {
5553
quantity: 0,
5654
});
5755
58-
isRemoving.value = true;
59-
6056
const variables = {
6157
input: {
6258
items: updatedItems,
@@ -72,11 +68,8 @@ const handleRemoveProduct = (product) => {
7268
mutate(variables);
7369
7470
onDone(() => {
75-
isRemoving.value = false;
7671
document.location = "/cart";
7772
});
78-
79-
onError(() => (isRemoving.value = false));
8073
};
8174
</script>
8275

components/Cart/CartItem.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
4747
import { formatPrice } from "@/utils/functions";
4848
49-
const isRemoving = useState("isRemoving", () => false);
49+
const isRemoving = useRef(false);
5050
5151
const props = defineProps({
5252
product: {

components/Products/ProductsSingleProduct.vue

Lines changed: 3 additions & 4 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="isTestLoading"
55+
:is-loading="isLoading"
5656
>
5757
ADD TO CART</CommonButton
5858
>
@@ -89,8 +89,7 @@ import { useCart } from "@/store/useCart";
8989
9090
const cart = useCart();
9191
92-
// You can now access the loading state directly from the cart store
93-
const isTestLoading = computed(() => cart.loading);
92+
const isLoading = computed(() => cart.loading);
9493
9594
const selectedVariation = ref(); // TODO Pass this value to addProductToCart()
9695
@@ -123,7 +122,7 @@ const addProductToCart = async (product) => {
123122
cart.addToCart(product);
124123
125124
watchEffect(() => {
126-
if (isTestLoading.value === false) {
125+
if (isLoading.value === false) {
127126
window.location.reload();
128127
}
129128
});

components/common/CommonButton.vue

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
<div v-if="linkTo" :class="{ center: centerButton }">
33
<NuxtLink :to="linkTo" class="button-link">
44
<button
5+
:disabled="isLoading"
56
:class="{ disabled: isLoading }"
6-
@click="$emit('CommonButtonClick')"
7+
@click.stop="$emit('CommonButtonClick')"
78
type="submit"
89
>
910
<slot />
@@ -28,8 +29,9 @@
2829
</div>
2930
<div v-else :class="{ center: centerButton }">
3031
<button
32+
:disabled="isLoading"
3133
:class="{ disabled: isLoading }"
32-
@click="$emit('CommonButtonClick')"
34+
@click.stop="$emit('CommonButtonClick')"
3335
type="submit"
3436
>
3537
<slot />
@@ -80,6 +82,10 @@ defineProps({
8082
</script>
8183

8284
<style scoped>
85+
button.disabled {
86+
@apply bg-blue-500 text-white font-bold py-2 px-4 rounded opacity-50 cursor-not-allowed;
87+
}
88+
8389
.disabled {
8490
@apply bg-blue-500 text-white font-bold py-2 px-4 rounded opacity-50 cursor-not-allowed;
8591
}

store/useCart.js

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@ export const useCart = defineStore("cartState", {
2323
async addToCart(product) {
2424
this.loading = true;
2525
try {
26-
console.log("Adding to cart:", product);
27-
console.log("Adding product.databaseId to cart:", product.databaseId);
28-
2926
const { mutate } = useMutation(ADD_TO_CART_MUTATION);
3027
const response = await mutate({
3128
input: {
@@ -35,7 +32,6 @@ export const useCart = defineStore("cartState", {
3532
});
3633

3734
if (response.data && response.data.addToCart) {
38-
console.log("Response from Add To Cart mutation:", response);
3935
this.loading = false;
4036
// Assuming the response returns the updated cart item, we need to handle it properly
4137
const newCartItem = response.data.addToCart.cartItem;
@@ -74,18 +70,7 @@ export const useCart = defineStore("cartState", {
7470
},
7571
},
7672
getters: {
77-
/*
78-
7973
getCartQuantity() {
80-
return this.cart.reduce((total, product) => total + product.quantity, 0);
81-
},
82-
*/
83-
84-
getCartQuantity() {
85-
86-
//console.log("Cart is:", this.cart);
87-
88-
8974
if (!this.cart) {
9075
console.error("Cart is undefined");
9176
return 0;

0 commit comments

Comments
 (0)