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

Adding "Add" button for stacks #91

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
9 changes: 9 additions & 0 deletions app/assets/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,15 @@ button.remove > * {
color: red !important;
}

button.add{
background-color: transparent !important;
box-shadow: none !important;
border-style: none !important;
}
button.add > * {
color: green !important;
}

img.logo {
height: 33px;
padding-right: 20px;
Expand Down
10 changes: 9 additions & 1 deletion app/src/components/StackItem.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import { Button } from 'react-materialize';

export function StackItem({ stack, onRemove }) {
export function StackItem({ stack, onRemove, onAdd }) {
return (
<li className="cart-item">
<span className="item-name">
Expand All @@ -18,6 +18,14 @@ export function StackItem({ stack, onRemove }) {
onClick={() => onRemove(stack)}
icon="clear"
waves="light"
/>
<Button
floating
large
className="right add waves-green"
onClick={() => onAdd(stack)}
icon="add"
waves="light"
/>
</div>
</li>
Expand Down
11 changes: 10 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,11 @@ export class ShopView extends React.Component {
exitTimer: t,
}));
}

addToStack(stack) {
this.time = LOGOUT_TIMER;
stack.qty++;
}

clearCart(stack) {
this.time = LOGOUT_TIMER;
Expand Down Expand Up @@ -252,7 +261,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.clearCart(...a)} onAdd={(...a) => this.addToStack(...a)} />
));

return (
Expand Down