Skip to content

Commit 9cf7b04

Browse files
committed
added basic time input module
1 parent e6bea62 commit 9cf7b04

File tree

5 files changed

+11142
-11461
lines changed

5 files changed

+11142
-11461
lines changed

.env

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
//.env
2-
BROWSER=none
2+
//BROWSER=none
33
DEBUG=electron-builder

package.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,16 @@
1313
"@testing-library/user-event": "^12.1.10",
1414
"@types/jest": "^26.0.15",
1515
"@types/node": "^12.0.0",
16-
"@types/react": "^17.0.0",
16+
"@types/react": "^17.0.3",
1717
"@types/react-dom": "^17.0.0",
1818
"concurrently": "^6.0.0",
1919
"electron-is-dev": "^2.0.0",
20+
"moment": "^2.29.1",
2021
"node": "^15.10.0",
2122
"react": "^17.0.2",
23+
"react-datetime": "^3.0.4",
2224
"react-dom": "^17.0.2",
25+
"react-moment": "^1.1.1",
2326
"react-scripts": "4.0.3",
2427
"typescript": "^4.1.2",
2528
"wait-on": "^5.3.0",

src/App.tsx

+4-21
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,9 @@
11
import React from 'react';
2-
import logo from './logo.svg';
32
import './App.css';
3+
import { MainForm } from './MainForm';
44

5-
function App() {
6-
return (
7-
<div className="App">
8-
<header className="App-header">
9-
<img src={logo} className="App-logo" alt="logo" />
10-
<p>
11-
Edit <code>src/App.tsx</code> and save to reload.
12-
</p>
13-
<a
14-
className="App-link"
15-
href="https://reactjs.org"
16-
target="_blank"
17-
rel="noopener noreferrer"
18-
>
19-
Learn React
20-
</a>
21-
</header>
22-
</div>
23-
);
24-
}
5+
const App = () => (
6+
<MainForm message="Hello!"/>
7+
);
258

269
export default App;

src/MainForm.tsx

+101
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
import React, { createRef } from 'react';
2+
import Moment from 'react-moment';
3+
import './App.css';
4+
5+
type MainFormState = {
6+
count: number,
7+
currentDateTime: Date
8+
}
9+
10+
type TimeInputProps = {
11+
defaultTimerDuration: string
12+
}
13+
14+
type TimeInputState = {
15+
value: string,
16+
}
17+
18+
19+
export class TimeInput extends React.Component<TimeInputProps, TimeInputState>{
20+
private instanceRef = createRef<HTMLInputElement>();
21+
22+
constructor(props: TimeInputProps){
23+
super(props);
24+
this.state = { value: props.defaultTimerDuration }
25+
this.handleChange = this.handleChange.bind(this);
26+
}
27+
state: TimeInputState = {
28+
value: "time..."
29+
}
30+
31+
handleChange(e: React.ChangeEvent<HTMLInputElement>){
32+
this.setState({ value: e.target.value })
33+
}
34+
35+
handleClick(e: MouseEvent){
36+
this.setState({ value:""});
37+
}
38+
39+
render(){
40+
return(
41+
<div>
42+
<form>
43+
<input type="text" value={this.state.value} onChange={this.handleChange} ref={this.instanceRef} />
44+
</form>
45+
</div>
46+
)
47+
}
48+
}
49+
50+
export class Timer extends React.Component<{}, {}>{
51+
52+
}
53+
54+
export class MainForm extends React.Component<{ message: string}, MainFormState>{
55+
state: MainFormState = {
56+
count: 0,
57+
currentDateTime: new Date()
58+
}
59+
intervalId : any;
60+
61+
render(){
62+
return(
63+
<div>
64+
<div onClick={() => this.increment(1)}>
65+
{this.props.message} {this.state.count}
66+
</div>
67+
<TimeInput defaultTimerDuration="15" ></TimeInput>
68+
<Moment format="YYYY/MM/DD hh:mm:ss"></Moment>
69+
</div>
70+
71+
)
72+
73+
}
74+
increment = (amt: number) => {
75+
this.setState((state) => ({
76+
count: state.count + amt
77+
}));
78+
}
79+
80+
tick(){
81+
this.setState(
82+
{
83+
currentDateTime: new Date()
84+
}
85+
)
86+
}
87+
88+
componentWillMount = () =>
89+
{
90+
this.tick();
91+
}
92+
93+
componentDidMount = () => {
94+
this.intervalId = setInterval(() => this.tick(), 1000);
95+
}
96+
97+
componentWillUnmount = () => {
98+
this.intervalId = null;
99+
}
100+
101+
}

0 commit comments

Comments
 (0)