Skip to content

Commit a57462c

Browse files
committed
the client is probably ready
1 parent b784c8d commit a57462c

File tree

6 files changed

+90
-26
lines changed

6 files changed

+90
-26
lines changed

src/App.css

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
}
6565

6666
.raw-data-area{
67+
width: 350px;
6768
overflow-y: auto;
6869
}
6970
.add-div{
@@ -85,6 +86,7 @@
8586
/* -----------------login -----------------*/
8687

8788
.login-page{
89+
background-color: whitesmoke;
8890
height: 100vh;
8991
display: flex;
9092
justify-content: center;

src/App.js

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,11 @@ class App extends React.Component {
7575
this.newValue= this.newValue.bind(this);
7676
this.newGraph= this.newGraph.bind(this);
7777
this.delete= this.delete.bind(this);
78+
this.graphUpdate= this.graphUpdate.bind(this);
7879
}
7980

8081
componentDidMount() {
81-
document.title="hehe";
82+
document.title="Hey";
8283
}
8384

8485
newValue(date,value,category,graph, special, special_data){
@@ -120,29 +121,44 @@ class App extends React.Component {
120121
if(data[cat].graphs.length === 0)
121122
data.splice(cat,1);
122123

123-
console.log(data);
124124
let first = data[0];
125125
this.setState( { current: { name: first.graphs[0].name,
126126
type: first.graphs[0].type,
127127
data: first.graphs[0].data, category: 0, graph: 0 } });
128+
}
129+
130+
graphUpdate(graph){
131+
let parsed
132+
try{
133+
parsed = JSON.parse(graph);
134+
} catch(e){
135+
console.log("Invalid json from raw data option. >> "+e)
136+
return;
137+
}
138+
parsed.map(o =>{
139+
o.x = new Date(o.x);
140+
})
141+
let cat = this.state.current.category;
142+
let grf = this.state.current.graph;
143+
data[cat].graphs[grf].data = parsed;
144+
let current = data[cat].graphs[grf];
128145

146+
this.setState( { current: { name: current.name, type: current.type, data: parsed, category: cat, graph: grf } });
129147
}
130-
render() {
131148

149+
render() {
132150
return (
133151
<>
134152
<Header title={this.state.current.name} onGraphChange={this.onGraphChange} data={data} newGraph={this.newGraph}/>
135153
<Content data={this.state.current.data} title={this.state.current.name} newValue={this.newValue} category={this.state.current.category}
136-
graph={this.state.current.graph} valueType={this.state.current.type} delete={this.delete}/>
154+
graph={this.state.current.graph} valueType={this.state.current.type} delete={this.delete} graphUpdate={this.graphUpdate}/>
137155
</>
138156
);
139157
}
140158
}
141159

142160
export default App;
143161

144-
145-
146162
function newGraphParse(category,graph,valueType){
147163
let newcategory = true;
148164
let category_index=0;

src/components/Content/Content.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class Content extends React.Component {
1818

1919
let stats = <div className='stats-area'>Add some values to graph</div>
2020
if(this.props.data.length > 0)
21-
stats = <Stats valueType={this.props.valueType} data={this.props.data} gym={ this.isGym() }/>;
21+
stats = <Stats valueType={this.props.valueType} data={this.props.data} gym={ this.isGym() } graphUpdate={this.props.graphUpdate}/>;
2222

2323
return (
2424
<>

src/components/Content/Stats/DataDialog/DataDialog.js

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,60 @@ import '../../../../App.css';
33
import Dialog from '@material-ui/core/Dialog';
44
import DialogActions from '@material-ui/core/DialogActions';
55
import DialogContent from '@material-ui/core/DialogContent';
6-
import DialogContentText from '@material-ui/core/DialogContentText';
76
import DialogTitle from '@material-ui/core/DialogTitle';
87
import Button from '@material-ui/core/Button';
8+
import TextField from '@material-ui/core/TextField';
9+
10+
let graph;
911

1012
export default function DataDialog(props) {
1113

12-
let fields=[];
13-
props.data.map((o,ind)=>{
14-
fields.push(<p key={ind}>{JSON.stringify(o)}</p>);
15-
});
14+
const [disabled, setDisabled] = React.useState(true);
15+
const [data, setData] = React.useState(JSON.stringify(props.data,null,4));
16+
17+
function onInput(e){
18+
graph = e.target.value;
19+
setData(graph);
20+
21+
if(graph.length === 0)
22+
setDisabled(true);
23+
else
24+
setDisabled(false);
25+
}
26+
27+
function submitHandle(){
28+
props.graphUpdate(graph);
29+
props.dialogClose();
30+
}
31+
32+
// React.useEffect(()=>{
33+
// console.log("haha");
34+
// })
35+
36+
// let fields=[];
37+
// props.data.map((o,ind)=>{
38+
// fields.push(<p key={ind}>{JSON.stringify(o)}</p>);
39+
// });
1640

1741
return (
1842
<Dialog open={props.open} onClose={props.dialogClose} aria-labelledby="form-dialog-title">
1943
<DialogTitle>Raw data:</DialogTitle>
2044
<DialogContent className="raw-data-area">
21-
{fields}
45+
{/* {fields} */}
46+
<TextField
47+
placeholder="What have you done? ctrl z asap"
48+
multiline={true}
49+
rows={9}
50+
rowsMax={15}
51+
value={data}
52+
fullWidth
53+
helperText="Change at your own risk"
54+
onChange={onInput}
55+
/>
2256
</DialogContent>
2357
<DialogActions>
2458
<Button onClick={props.dialogClose} color="primary" className="raw">Leave</Button>
25-
{/* <Button onClick={()=> this.onSubmit()}
26-
color="primary">
27-
Add
28-
</Button> */}
59+
<Button disabled={disabled} onClick={submitHandle} color="primary">Change</Button>
2960
</DialogActions>
3061
</Dialog>
3162
)

src/components/Content/Stats/Stats.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ class Stats extends React.Component {
3939
<p>Lowest: {getLowest(this.props.data)} </p>
4040
<p>Average: {getAverage(this.props.data)} </p>
4141
<Button color="primary" variant="contained" onClick={this.dialogClick}>Raw Data</Button>
42-
<DataDialog open={this.state.open} dialogClose={this.dialogClose} title={this.props.title} data={this.props.data}/>
42+
<DataDialog open={this.state.open} dialogClose={this.dialogClose} title={this.props.title} data={this.props.data}
43+
graphUpdate={this.props.graphUpdate}/>
4344
</div>
4445
);
4546
}

src/components/Login.js

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,39 @@
11
import React from 'react';
22
import '../App.css';
33
import Paper from '@material-ui/core/Paper';
4-
import Typography from '@material-ui/core/Typography';
54
import TextField from '@material-ui/core/TextField';
65
import Button from '@material-ui/core/Button';
76

7+
let name;
88
export default function Login(props) {
99

10+
const [disabled, setDisabled] = React.useState(true);
11+
12+
function componentDidMount(){
13+
document.title="Hey";
14+
}
15+
16+
function onInput(e){
17+
name = e.target.value;
18+
if(name.length === 0)
19+
setDisabled(true);
20+
else
21+
setDisabled(false);
22+
}
23+
24+
function submitHandle(){
25+
console.log(name);
26+
window.location.href='/app';
27+
}
28+
1029
return (
1130
<div className="login-page">
1231
<Paper className={'login-paper'}>
13-
{/* <div className='login-title'>
14-
<Typography variant="h5" component="h3">
15-
Login
16-
</Typography>
17-
</div> */}
1832
<div className='login-content'>
19-
<TextField label="login" variant="outlined" fullWidth />
33+
<TextField label="Name" variant="outlined" fullWidth onChange={onInput} autoFocus/>
2034
</div>
2135
<div className='login-actions'>
22-
<Button variant="contained" color="primary">da</Button>
36+
<Button variant="contained" color="primary" disabled={disabled} onClick={submitHandle}>Enter</Button>
2337
</div>
2438
</Paper>
2539
</div>

0 commit comments

Comments
 (0)