Skip to content

Commit 1c6b03f

Browse files
committed
upgrade a bunch of things and deal with the wreckage
1 parent 00f30f8 commit 1c6b03f

File tree

8 files changed

+5177
-6207
lines changed

8 files changed

+5177
-6207
lines changed

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ version: "3"
22

33
services:
44
bare: &app
5-
image: node:10
5+
image: node:16
66
command: bash
77
working_dir: /app/
88
command: yarn dev

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
"name": "snacker-tracker-ui",
33
"version": "0.1.0",
44
"private": true,
5-
"dependencies": {},
65
"scripts": {
76
"start": "react-scripts start",
87
"build": "react-scripts build",
@@ -31,14 +30,15 @@
3130
"d3": "^5.15.0",
3231
"d3-tip": "^0.9.1",
3332
"dayjs": "^1.8.16",
34-
"react": "^16.11.0",
33+
"react": "^18.2.0",
3534
"react-bootstrap": "^1.0.0-beta.16",
3635
"react-charts": "^2.0.0-beta.4",
3736
"react-dom": "^16.11.0",
3837
"react-router-bootstrap": "^0.25.0",
3938
"react-router-dom": "^5.1.2",
40-
"react-scripts": "^4.0.2",
39+
"react-scripts": "^5.0.1",
4140
"reactstrap": "^8.2.0",
42-
"source-map-explorer": "^2.1.2"
41+
"source-map-explorer": "^2.1.2",
42+
"url": "^0.11.0"
4343
}
4444
}

src/components/NavBar.js

Lines changed: 16 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import Nav from 'react-bootstrap/Nav'
44
import Navbar from 'react-bootstrap/Navbar'
55
import NavItem from 'react-bootstrap/NavItem'
66
import Button from 'react-bootstrap/Button'
7-
//import Form from 'react-bootstrap/Form'
8-
//import FormControl from 'react-bootstrap/FormControl'
97
import Dropdown from 'react-bootstrap/Dropdown'
108

9+
import { LocationContext } from '../lib/LocationContext'
10+
1111

1212
import { useAuth0 } from "../react-auth0-spa";
1313

@@ -23,23 +23,6 @@ const NavBar = () => {
2323
await getTokenSilently()
2424
})()
2525

26-
/*
27-
const handleSubmit = event => {
28-
alert(JSON.stringify(event))
29-
console.log(event, 'this triggered')
30-
event.stopPropagation()
31-
event.preventDefault()
32-
const form = event.currentTarget;
33-
34-
console.log(form)
35-
};
36-
37-
<Form inline onSubmit={handleSubmit}>
38-
<FormControl onChange={updateSearch} type="text" placeholder="Search" className="mr-sm-2" />
39-
<Button type="submit">Search</Button>
40-
</Form>
41-
*/
42-
4326
return (
4427
<Navbar bg="light" expand="lg">
4528
<Navbar.Brand to="/" as={NavLink}>Snacker-Tracker UI</Navbar.Brand>
@@ -49,28 +32,24 @@ const NavBar = () => {
4932
<Nav.Link to="/top-scans" as={NavLink}>Top Scans</Nav.Link>
5033
<Nav.Link to="/last-scans" as={NavLink}>Last Scans</Nav.Link>
5134
<Nav.Link to="/categories" as={NavLink}>Categories</Nav.Link>
35+
<Dropdown drop="down">
36+
<LocationContext.Consumer>
37+
{location => (
38+
<Dropdown.Toggle variant="light" id="dropdown-basic">
39+
{location}
40+
</Dropdown.Toggle>
41+
)}
42+
</LocationContext.Consumer>
43+
44+
<Dropdown.Menu>
45+
<Dropdown.Item to="?location=thailand:bangkok" as={NavLink}>Thailand</Dropdown.Item>
46+
<Dropdown.Item to="?location=singapore" as={NavLink}>Singapore</Dropdown.Item>
47+
</Dropdown.Menu>
48+
</Dropdown>
5249
</Nav>
5350

5451
{!isAuthenticated && (
5552
<NavItem>
56-
<Button
57-
id="qsLoginBtn"
58-
color="primary"
59-
className="btn-margin"
60-
onClick={() => loginWithRedirect({connection: 'line'})}
61-
>
62-
Log in (line)
63-
</Button>
64-
65-
<Button
66-
id="qsLoginBtn"
67-
color="primary"
68-
className="btn-margin"
69-
onClick={() => loginWithRedirect({connection: 'facebook'})}
70-
>
71-
Log in (fb)
72-
</Button>
73-
7453
<Button
7554
id="qsLoginBtn"
7655
color="primary"

src/lib/LocationContext.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import React, { useState, useContext } from 'react'
2+
3+
export const LocationContext = React.createContext("thailand:bangkok")

src/views/CodeDetails.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { Component } from "react";
22

3-
import queryString from 'query-string'
3+
import url from 'url'
44

55
//import Loading from "../components/Loading";
66

@@ -59,7 +59,11 @@ class CodeDetails extends Component {
5959
constructor(props) {
6060
super(props)
6161

62-
const query = queryString.parse(this.props.location.search)
62+
//const query = queryString.parse(this.props.location.search)
63+
//
64+
const query = {
65+
"period": "daily"
66+
}
6367

6468
this.state = {
6569
counts: [],
@@ -74,11 +78,14 @@ class CodeDetails extends Component {
7478
}
7579

7680
componentDidUpdate(previousProps, previousState) {
77-
const query = queryString.parse(this.props.location.search)
78-
const period = query.period || 'daily'
79-
if(period !== previousState.period) {
81+
const q = url.parse(this.props.location.search, true).query
82+
const query = {
83+
"period": q.period || "daily"
84+
}
85+
86+
if(query.period !== previousState.period) {
8087
this.setState({period: query.period})
81-
this.loadGraph(period)
88+
this.loadGraph(query.period)
8289
}
8390
}
8491

@@ -162,7 +169,7 @@ class CodeDetails extends Component {
162169
{this.state.counts.length > 0 && (<ScanCountGraph counts={this.state.counts} period={this.state.period_map[this.state.period]} />)}
163170
<NavLink to={this.makeGraphLink('hourly')}>Hourly</NavLink> | <NavLink to={this.makeGraphLink('weekdaily')}>Weekday</NavLink> | <NavLink to={this.makeGraphLink('daily')}>Daily</NavLink>
164171
</Container>
165-
<ScanCountGraph period={queryString.parse(this.props.location.search).period || 'daily'} counts={this.state.counts.items || []} />
172+
<ScanCountGraph period={this.state.period || 'daily'} counts={this.state.counts.items || []} />
166173
</Col>
167174
</Row>
168175
</Container>

src/views/Home.js

Lines changed: 38 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import dayjs from 'dayjs'
55

66
import { NavLink } from 'react-router-dom'
77

8-
import queryString from 'query-string'
8+
import url from 'url'
9+
import { LocationContext } from '../lib/LocationContext'
910

1011
import CanvasJSReact from '../lib/canvasjs.react'
1112

@@ -49,31 +50,39 @@ class TopScansGraph extends Component {
4950
}
5051
}
5152

52-
/*
53-
<Content />
54-
*/
55-
5653
class Home extends React.Component {
5754
constructor(props) {
5855
super(props)
59-
const query = queryString.parse(this.props.location.search)
56+
const query = url.parse(this.props.location.search, true).query
6057

6158
this.state = {
6259
code: false,
6360
scans: false,
64-
period: query.period || 'all-time'
61+
period: query.period || 'all-time',
62+
location: null
6563
}
6664
}
6765

68-
componentDidUpdate(previousProps, previousState) {
69-
const query = queryString.parse(this.props.location.search)
66+
slugMappings = {
67+
'this-week': ["This week", dayjs().startOf('week').toISOString()],
68+
'last-7-days': ["Last 7 days", dayjs().subtract(7, 'day').toISOString()],
69+
'this-month': ["This month", dayjs().startOf('month').toISOString()],
70+
'last-30-days': ["Last 30 days", dayjs().subtract(30, 'day').toISOString()],
71+
'year-to-date': ["Year to date", dayjs().startOf('year').toISOString()],
72+
'all-time': ["All time", null]
73+
}
74+
75+
76+
componentDidUpdate(_previousProps, previousState) {
77+
const query = url.parse(this.props.location.search, true).query
7078
const period = query.period || 'all-time'
7179
if(period !== previousState.period) {
7280
this.setState({period})
7381
this.load()
7482
}
7583
}
7684

85+
7786
async load() {
7887
let options = {}
7988
if(this.props.auth.isAuthenticated) {
@@ -82,33 +91,16 @@ class Home extends React.Component {
8291
}
8392
}
8493

85-
console.log(this.state.period)
86-
8794
const opts = {}
88-
switch(this.state.period) {
89-
case 'this-week':
90-
opts.from_date = dayjs().startOf('week').toISOString()
91-
break
92-
93-
case 'last-7-days':
94-
opts.from_date = dayjs().subtract(7, 'day').toISOString()
95-
break
96-
97-
case 'this-month':
98-
opts.from_date = dayjs().startOf('month').toISOString()
99-
break
100-
101-
case 'last-30-days':
102-
opts.from_date = dayjs().subtract(30, 'day').toISOString()
103-
break
104-
105-
case 'year-to-date':
106-
opts.from_date = dayjs().startOf('year').toISOString()
107-
break
108-
109-
case 'all-time':
110-
default:
111-
break
95+
96+
if(Object.keys(this.slugMappings).includes(this.state.period)) {
97+
if(this.slugMappings[this.state.period][1] != null) {
98+
opts.from_date = this.slugMappings[this.state.period][1]
99+
}
100+
}
101+
102+
if(opts.from_date == null) {
103+
delete opts.from_date
112104
}
113105

114106
const client = new API(this.props.config.REPORTER_URL, options)
@@ -139,10 +131,19 @@ class Home extends React.Component {
139131
if(!this.state.scans || !this.state.codes) {
140132
return ("...")
141133
} else {
134+
const things = Object.entries(this.slugMappings).map( m => {
135+
return (<NavLink to={this.makeGraphLink(m[0])}>{m[1][0]}</NavLink> )
136+
})
137+
138+
const len = things.length
139+
140+
for(let i = 0; i < ((len -1) * 2); i = i + 2) {
141+
things.splice(i + 1, 0, " | ")
142+
}
143+
142144
return (
143145
<Fragment>
144-
<NavLink to={this.makeGraphLink('this-week')}>This week</NavLink> | <NavLink to={this.makeGraphLink('last-7-days')}>Last 7 days</NavLink> | <NavLink to={this.makeGraphLink('this-month')}>This month</NavLink> | <NavLink to={this.makeGraphLink('last-30-days')}>Last 30 days</NavLink> | <NavLink to={this.makeGraphLink('year-to-date')}>Year to date</NavLink> | <NavLink to={this.makeGraphLink('all-time')}>All Time</NavLink>
145-
146+
{things}
146147
<TopScansGraph codes={this.state.codes} topscans={this.state.scans} />
147148
</Fragment>
148149
)

src/views/LastScans.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ class LastScans extends Component {
3838
this.setState({scans, codes})
3939
}
4040

41-
42-
4341
render() {
4442
let rows = null
4543
// if we've loaded data, essentially
@@ -65,10 +63,14 @@ class LastScans extends Component {
6563
<Col>
6664
{dayjs(s.scanned_at).fromNow()} ({dayjs(s.scanned_at).format('YYYY/MM/DD HH:mm:ss')})
6765
</Col>
66+
<Col>
67+
{s.location}
68+
</Col>
6869
</Row>
6970
)
7071
})
7172
}
73+
7274
return (
7375
<Fragment>
7476
<Row>
@@ -81,6 +83,9 @@ class LastScans extends Component {
8183
<Col className="d-none d-sm-block">
8284
Last Scanned
8385
</Col>
86+
<Col className="d-none d-sm-block">
87+
Location
88+
</Col>
8489
</Row>
8590
{rows}
8691
</Fragment>

0 commit comments

Comments
 (0)