Skip to content

Commit a812e1c

Browse files
committed
Development toolbar
1 parent e887c56 commit a812e1c

11 files changed

+78
-36
lines changed

src/App.tsx

+15-26
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { requestPurchase, endPurchase, viewProfileQR, cancelPurchase } from "act
1212
import { addProduct, removeProduct, selectProduct, increaseProductQty, changePage } from "actions/product";
1313

1414
import { Flex, Box } from "reflexbox";
15-
import { ProductList, PurchaseButton, Account, Sidebar, LoadingBox, Button } from "components";
15+
import { ProductList, PurchaseButton, Account, Sidebar, LoadingBox, Button, DevToolbar } from "components";
1616
import * as style from "styles/App.scss";
1717

1818
//Require since qrcode.react does not have support for new javascript "import"
@@ -36,25 +36,9 @@ interface IThunder {
3636
}
3737

3838
class App extends React.Component<IAppProps, {}> {
39-
addRandomProduct() {
40-
let codes = [
41-
"7310500088853",
42-
"7340083438684",
43-
"7611612221351",
44-
"7310500114934",
45-
"7310070765840",
46-
"7315360010754",
47-
"7622300342753"
48-
];
49-
50-
let randomIndex = Math.floor(Math.random() * codes.length);
51-
this.props.dispatch(addProduct(codes[randomIndex]));
52-
}
53-
5439
componentDidMount() {
5540
const { dispatch } = this.props;
5641

57-
// dispatch(login("154464990"));
5842
Thunder.connect(process.env.THUNDER.host, process.env.THUNDER.key, ["products", "cards"]);
5943
Thunder.listen((data: IThunder) => {
6044
if (data.channel === "products") {
@@ -66,6 +50,20 @@ class App extends React.Component<IAppProps, {}> {
6650
}
6751

6852
render() {
53+
if (process.env.NODE_ENV == 'development') {
54+
return (
55+
<div>
56+
<DevToolbar
57+
dispatch={this.props.dispatch}
58+
/>
59+
{this.renderApp()}
60+
</div>
61+
);
62+
}
63+
return this.renderApp();
64+
}
65+
66+
renderApp() {
6967
const { dispatch, products, account, purchase } = this.props;
7068

7169
let selected = products.products.filter((product: any) => {
@@ -81,7 +79,6 @@ class App extends React.Component<IAppProps, {}> {
8179
onRemove={() => dispatch(removeProduct())}
8280
onScrollUp={() => dispatch(changePage(-1))}
8381
onScrollDown={() => dispatch(changePage(1))}
84-
addRandomProduct={() => this.addRandomProduct()}
8582
active={selected > 0}
8683
scrollUpActive={products.page > 0}
8784
scrollDownActive={products.page < products.maxPage}/>
@@ -154,14 +151,6 @@ class App extends React.Component<IAppProps, {}> {
154151
<Box py={1}>Blip a card linked with your account</Box>
155152
<Box py={1}>or</Box>
156153
<Box py={1}>Scan a product to start a cash payment</Box>
157-
{(process.env.NODE_ENV === "development" ? (
158-
<Box py={1}><Button label="dev cash buy" onClick={() => this.addRandomProduct()}/></Box>
159-
) : undefined)}
160-
{(process.env.NODE_ENV === "development" ? (
161-
<Box py={1}>
162-
<Button label="dev account buy" onClick={() => dispatch(login("154464990"))}/>
163-
</Box>
164-
) : undefined)}
165154
{(account.request ? <LoadingBox/> : undefined)}
166155
{(account.request ? <Box className={style.overlay}/> : undefined)}
167156
</Flex>

src/components/DevToolbar.tsx

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import * as React from "react";
2+
import { IAccount } from "types";
3+
import * as classNames from "classnames";
4+
import { Box, Flex } from "reflexbox";
5+
import { Button } from "components";
6+
import * as style from "styles/components/DevToolbar.scss";
7+
import { addProduct, removeProduct, selectProduct, increaseProductQty, changePage } from "actions/product";
8+
import { login, clearAccount } from "actions/account";
9+
10+
interface IDevToolbarProps {
11+
dispatch: Function
12+
}
13+
14+
export default class DevToolbar extends React.Component<IDevToolbarProps, {}> {
15+
addRandomProduct() {
16+
let codes = [
17+
"7310500088853",
18+
"7340083438684",
19+
"7611612221351",
20+
"7310500114934",
21+
"7310070765840",
22+
"7315360010754",
23+
"7622300342753"
24+
];
25+
let randomIndex = Math.floor(Math.random() * codes.length);
26+
this.props.dispatch(addProduct(codes[randomIndex]));
27+
}
28+
29+
render() {
30+
var dispatch = this.props.dispatch;
31+
return (
32+
<Flex pl={2} align="center" auto className={style.devbar}>
33+
<Box auto>{process.env.API.host}</Box>
34+
<Button icon="credit-card" onClick={() => dispatch(login('1337'))}/>
35+
<Button icon="plus" onClick={() => this.addRandomProduct()}/>
36+
</Flex>
37+
);
38+
}
39+
}

src/components/Sidebar.tsx

-3
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@ export default class Sidebar extends React.Component<ISidebarProps, {}> {
2828
<Button icon="trash" disabled={!this.props.active} onClick={this.props.onRemove}/>
2929
</Flex>
3030
<Button icon="chevron-down" onClick={this.props.onScrollDown} disabled={!this.props.scrollDownActive}/>
31-
{(process.env.NODE_ENV === "development" ? (
32-
<Button icon="plus" onClick={this.props.addRandomProduct}/>
33-
) : undefined)}
3431
</Flex>
3532
);
3633
}

src/components/index.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import ProductList from "components/ProductList";
66
import PurchaseButton from "components/PurchaseButton";
77
import Icon from "components/Icon";
88
import Button from "components/Button";
9+
import DevToolbar from "components/DevToolbar";
910

1011
export {
1112
Account,
@@ -15,5 +16,6 @@ export {
1516
ProductList,
1617
PurchaseButton,
1718
Icon,
18-
Button
19+
Button,
20+
DevToolbar
1921
}

src/styles/App.scss

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ body {
3434
.container {
3535
background: #88a0a8;
3636
height: 480px;
37-
width: 800px;
37+
width: $app-width;
3838
overflow: hidden;
3939
display: block;
4040
position: absolute;

src/styles/_globals.scss

+1
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ $grey-dark: #616161;
99
$grey-light: #e0e0e0;
1010
$black: #212121;
1111
$white: #ffffff;
12+
$app-width: 800px;

src/styles/components/Account.scss

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@
2020
animation: rotating 2s linear infinite;
2121
}
2222
}
23-
23+
2424
@keyframes rotating {
2525
10%, 90% {
2626
transform: rotate(-10deg);
2727
}
28-
28+
2929
20%, 80% {
3030
transform: rotate(10deg);
3131
}
@@ -37,4 +37,4 @@
3737
40%, 60% {
3838
transform: rotate(30deg);
3939
}
40-
}
40+
}

src/styles/components/DevToolbar.scss

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
@import "styles/globals";
2+
3+
.devbar {
4+
width: $app-width;
5+
color: $white;
6+
display: block;
7+
font-size: 22px;
8+
text-align: left;
9+
height: 60px;
10+
transition: bottom .3s ease;
11+
background: $black;
12+
z-index: 9;
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const devbar: string;

webpack.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const webpack = require("webpack");
33
const autoprefixer = require("autoprefixer");
44
const ForkCheckerPlugin = require("awesome-typescript-loader").ForkCheckerPlugin;
55

6-
const config = require(process.env.SETTINGS || "./configs/live.js");
6+
const config = require(process.env.SETTINGS || "./config");
77

88
module.exports = {
99
entry: [

webpack.prod.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const path = require("path");
22
const webpack = require("webpack");
33
const autoprefixer = require("autoprefixer");
44

5-
const config = require(process.env.SETTINGS || "./config");
5+
const config = require(process.env.SETTINGS || "./configs/live.js");
66

77
module.exports = {
88
entry: [

0 commit comments

Comments
 (0)