Skip to content
This repository has been archived by the owner on Oct 5, 2024. It is now read-only.

Updating stacks #90

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/src/components/StackItem.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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"
/>
</div>
Expand Down
14 changes: 13 additions & 1 deletion app/src/components/views/shop.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -252,7 +264,7 @@ export class ShopView extends React.Component {
});

const cartContents = this.shoppingCart.map(stack => (
<StackItem key={stack.item.id} stack={stack} onRemove={(...a) => this.clearCart(...a)} />
<StackItem key={stack.item.id} stack={stack} onRemove={(...a) => this.subtractCart(...a)} />
));

return (
Expand Down