Skip to content

Commit 082cc97

Browse files
committed
Remove product from Pinia state
1 parent f0dc4b2 commit 082cc97

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

components/Cart/CartContents.vue

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,23 @@
5858
import GET_CART_QUERY from "@/apollo/queries/GET_CART_QUERY.gql";
5959
import UPDATE_CART_MUTATION from "@/apollo/mutations/UPDATE_CART_MUTATION.gql";
6060
61+
import { useCart } from "@/store/useCart";
62+
6163
const isRemoving = useState("isRemoving", () => false);
6264
65+
const cart = useCart();
66+
6367
defineProps({
6468
showCheckoutButton: { type: Boolean, required: false, default: false },
6569
});
6670
6771
const { data } = await useAsyncQuery(GET_CART_QUERY);
6872
69-
const handleRemoveProduct = ({ key }) => {
73+
const handleRemoveProduct = (product) => {
7074
const updatedItems = [];
7175
76+
const { key } = product;
77+
7278
updatedItems.push({
7379
key,
7480
quantity: 0,
@@ -82,6 +88,8 @@ const handleRemoveProduct = ({ key }) => {
8288
},
8389
};
8490
91+
cart.removeProductFromCart(product);
92+
8593
const { mutate, onDone, onError } = useMutation(UPDATE_CART_MUTATION, {
8694
variables,
8795
});

store/useCart.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export const useCart = defineStore("cartState", {
2323
this.cart.push(product);
2424
}
2525
},
26-
removeProductFromCart({ product }) {
26+
removeProductFromCart(product) {
2727
this.cart.splice(this.cart.indexOf(product), 1);
2828
},
2929

0 commit comments

Comments
 (0)