From 049833a353d2f32779e1c1cc18bd97c0a2831285 Mon Sep 17 00:00:00 2001 From: NL Date: Tue, 19 Oct 2021 19:17:43 -0600 Subject: [PATCH] Updating stacks Updating stacks so that we can remove one at a time --- app/src/components/StackItem.jsx | 2 +- app/src/components/views/shop.jsx | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/app/src/components/StackItem.jsx b/app/src/components/StackItem.jsx index f2cdaa9..9375ff2 100644 --- a/app/src/components/StackItem.jsx +++ b/app/src/components/StackItem.jsx @@ -16,7 +16,7 @@ export function StackItem({ stack, onRemove }) { large className="right remove waves-red" onClick={() => onRemove(stack)} - icon="clear" + icon={stack.qty > 1 ? "remove" : "clear"} waves="light" /> diff --git a/app/src/components/views/shop.jsx b/app/src/components/views/shop.jsx index 247ed8c..c5dfc07 100644 --- a/app/src/components/views/shop.jsx +++ b/app/src/components/views/shop.jsx @@ -29,6 +29,10 @@ class Stack { get qty() { return this._qty; } + + set qty(qty) { + this._qty = qty; + } get cost() { return this.qty * this.item.price; @@ -141,6 +145,14 @@ export class ShopView extends React.Component { exitTimer: t, })); } + + subtractCart(stack){ + this.time = LOGOUT_TIMER; + stack.qty -= 1; + if(stack.qty == 0){ + this.clearCart(stack); + } + } clearCart(stack) { this.time = LOGOUT_TIMER; @@ -252,7 +264,7 @@ export class ShopView extends React.Component { }); const cartContents = this.shoppingCart.map(stack => ( - this.clearCart(...a)} /> + this.subtractCart(...a)} /> )); return (