Skip to content

Commit dbb3a5d

Browse files
author
Christian DeCarle
committed
Converted all components to javascript - added math expression support for input field
1 parent 478f9d6 commit dbb3a5d

14 files changed

+156
-113
lines changed
File renamed without changes.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"@types/react-dom": "^17.0.0",
1818
"concurrently": "^6.0.0",
1919
"electron-is-dev": "^2.0.0",
20+
"mathjs": "^9.3.0",
2021
"moment": "^2.29.1",
2122
"node": "^15.10.0",
2223
"react": "^17.0.2",

src/App.tsx src/App.jsx

File renamed without changes.

src/App.test.tsx src/App.test.jsx

File renamed without changes.

src/Components/MainForm.tsx src/Components/MainForm.jsx

+1-14
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,7 @@
11
import React from 'react';
2-
import Moment from 'react-moment';
32
import TimeInput from './TimeInput';
4-
import Timer from './Timer';
53

6-
type MainFormState = {
7-
durationInput: string,
8-
currentDateTime: Date
9-
}
10-
11-
export class MainForm extends React.Component<{ message: string}, MainFormState>{
12-
state: MainFormState = {
13-
durationInput:"",
14-
15-
currentDateTime: new Date()
16-
}
17-
intervalId : any;
4+
export class MainForm extends React.Component{
185

196
render(){
207
return(

src/Components/SoundPlayer.jsx

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class SoudPlayer extends Component {
2+
state = { play: false }
3+
4+
audio = new Audio(this.props.url)
5+
6+
componentDidMount() {
7+
audio.addEventListener('ended', () => this.setState({play:false}));
8+
}
9+
10+
componentWillUnmount() {
11+
audio.removeEventListener('ended', () => this.setState({play:false}));
12+
}
13+
render() {
14+
return (
15+
<div>
16+
17+
</div>
18+
);
19+
}
20+
}
21+
22+
export default SoudPlayer;

src/Components/TimeInput.tsx src/Components/TimeInput.jsx

+7-16
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,22 @@
1-
import React, { createRef } from "react";
1+
import React from "react";
22
import Timer from "./Timer";
33

44
const defaultTimerDuration = "15";
55

6-
type TimeInputProps = {
7-
}
6+
export default class TimeInput extends React.Component{
87

9-
10-
type TimeInputState = {
11-
value: string,
12-
}
13-
14-
export default class TimeInput extends React.Component<TimeInputProps, TimeInputState>{
15-
private instanceRef = createRef<HTMLInputElement>();
16-
17-
constructor(props: TimeInputProps){
8+
constructor(props){
189
super(props);
1910
this.state = { value: defaultTimerDuration }
2011
this.handleChange = this.handleChange.bind(this);
2112
this.handleClick = this.handleClick.bind(this);
2213
}
2314

24-
handleChange(e: React.ChangeEvent<HTMLInputElement>){
25-
this.setState({ value: e.target.value })
15+
handleChange(e){
16+
this.setState({ value: e.target.value })
2617
}
2718

28-
handleClick(e: React.MouseEvent<HTMLInputElement>){
19+
handleClick(e){
2920
this.setState({ value: ""})
3021
}
3122

@@ -38,7 +29,7 @@ export default class TimeInput extends React.Component<TimeInputProps, TimeInput
3829
onClick={this.handleClick}
3930
ref={this.instanceRef} />
4031
</form>
41-
<Timer duration={parseInt(this.state.value)} /*clickHandler={this.handleBtnClick}*/ ></Timer>
32+
<Timer duration={this.state.value} /*clickHandler={this.handleBtnClick}*/ ></Timer>
4233
</div>
4334
)
4435
}

src/Components/Timer.jsx

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import React from "react";
2+
import './styles.css';
3+
import Moment from 'react-moment';
4+
import moment from 'moment';
5+
import { evaluate } from 'mathjs';
6+
7+
export default class Timer extends React.Component {
8+
state = {
9+
running: false,
10+
start: new Date(),
11+
end: new Date(),
12+
remainingTime: 0,
13+
soundPlaying: false
14+
}
15+
16+
audio = new Audio('bensound-creativeminds.mp3')
17+
18+
startTimer = () => {
19+
this.audio.pause();
20+
var start = new Date();
21+
this.setState({
22+
running: true,
23+
start: start,
24+
end: moment(start).add(evaluate(this.props.duration), 's').toDate()
25+
})
26+
}
27+
28+
stopTimer = () => {
29+
//this.audio.play();
30+
this.setState({
31+
running: false,
32+
})
33+
}
34+
35+
tick = () => {
36+
var now = moment(new Date())
37+
this.setState({
38+
remainingTime: moment(this.state.end).diff(now)
39+
})
40+
if (this.state.running && this.state.remainingTime <= 0) {
41+
this.stopTimer();
42+
window.confirm("Timer is finished", this.audio.play());
43+
}
44+
}
45+
46+
pauseAudio = () => {
47+
this.audio.pause();
48+
}
49+
50+
componentWillMount = () => {
51+
this.tick();
52+
}
53+
54+
componentDidMount = () => {
55+
this.intervalId = setInterval(() => this.tick(), 100);
56+
}
57+
58+
componentWillUnmount = () => {
59+
this.intervalId = null;
60+
}
61+
62+
render() {
63+
const toPositiveFilter = (d) => {
64+
return d.replace("-", "")
65+
}
66+
return (
67+
<div>
68+
69+
<button onClick={this.startTimer} className="button" >Start</button> <button onClick={this.stopTimer} className="button">Stop</button>
70+
<p>{this.state.running ? <Moment durationFromNow filter={toPositiveFilter}>{this.state.end}</Moment> : null}</p>
71+
</div>
72+
)
73+
}
74+
}

src/Components/Timer.tsx

-82
This file was deleted.

src/index.tsx src/index.jsx

File renamed without changes.

src/react-app-env.d.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/// <reference types="react-scripts" />
File renamed without changes.
File renamed without changes.

yarn.lock

+50-1
Original file line numberDiff line numberDiff line change
@@ -3672,6 +3672,11 @@ commondir@^1.0.1:
36723672
resolved "https://registry.npmjs.org/commondir/-/commondir-1.0.1.tgz"
36733673
integrity sha1-3dgA2gxmEnOTzKWVDqloo6rxJTs=
36743674

3675+
complex.js@^2.0.11:
3676+
version "2.0.12"
3677+
resolved "https://registry.yarnpkg.com/complex.js/-/complex.js-2.0.12.tgz#fa4df97d8928e5f7b6a86b35bdeecc3a3eda8a22"
3678+
integrity sha512-oQX99fwL6LrTVg82gDY1dIWXy6qZRnRL35N+YhIX0N7tSwsa0KFy6IEMHTNuCW4mP7FS7MEqZ/2I/afzYwPldw==
3679+
36753680
component-emitter@^1.2.1:
36763681
version "1.3.0"
36773682
resolved "https://registry.npmjs.org/component-emitter/-/component-emitter-1.3.0.tgz"
@@ -4265,7 +4270,7 @@ decamelize@^1.2.0:
42654270
resolved "https://registry.npmjs.org/decamelize/-/decamelize-1.2.0.tgz"
42664271
integrity sha1-9lNNFRSCabIDUue+4m9QH5oZEpA=
42674272

4268-
decimal.js@^10.2.0:
4273+
decimal.js@^10.2.0, decimal.js@^10.2.1:
42694274
version "10.2.1"
42704275
resolved "https://registry.npmjs.org/decimal.js/-/decimal.js-10.2.1.tgz"
42714276
integrity sha512-KaL7+6Fw6i5A2XSnsbhm/6B+NuEA7TZ4vqxnd5tXz9sbKtrN9Srj8ab4vKVdK8YAqZO9P1kg45Y6YLoduPf+kw==
@@ -4887,6 +4892,11 @@ escape-html@~1.0.3:
48874892
resolved "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz"
48884893
integrity sha1-Aljq5NPQwJdN4cFpGI7wBR0dGYg=
48894894

4895+
escape-latex@^1.2.0:
4896+
version "1.2.0"
4897+
resolved "https://registry.yarnpkg.com/escape-latex/-/escape-latex-1.2.0.tgz#07c03818cf7dac250cce517f4fda1b001ef2bca1"
4898+
integrity sha512-nV5aVWW1K0wEiUIEdZ4erkGGH8mDxGyxSeqPzRNtWP7ataw+/olFObw7hujFWlVjNsaDFw5VZ5NzVSIqRgfTiw==
4899+
48904900
[email protected], escape-string-regexp@^2.0.0:
48914901
version "2.0.0"
48924902
resolved "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-2.0.0.tgz"
@@ -5572,6 +5582,11 @@ forwarded@~0.1.2:
55725582
resolved "https://registry.npmjs.org/forwarded/-/forwarded-0.1.2.tgz"
55735583
integrity sha1-mMI9qxF1ZXuMBXPozszZGw/xjIQ=
55745584

5585+
fraction.js@^4.0.13:
5586+
version "4.0.13"
5587+
resolved "https://registry.yarnpkg.com/fraction.js/-/fraction.js-4.0.13.tgz#3c1c315fa16b35c85fffa95725a36fa729c69dfe"
5588+
integrity sha512-E1fz2Xs9ltlUp+qbiyx9wmt2n9dRzPsS11Jtdb8D2o+cC7wr9xkkKsVKJuBX0ST+LVS+LhLO+SbLJNtfWcJvXA==
5589+
55755590
fragment-cache@^0.2.1:
55765591
version "0.2.1"
55775592
resolved "https://registry.npmjs.org/fragment-cache/-/fragment-cache-0.2.1.tgz"
@@ -6822,6 +6837,11 @@ jake@^10.6.1:
68226837
filelist "^1.0.1"
68236838
minimatch "^3.0.4"
68246839

6840+
javascript-natural-sort@^0.7.1:
6841+
version "0.7.1"
6842+
resolved "https://registry.yarnpkg.com/javascript-natural-sort/-/javascript-natural-sort-0.7.1.tgz#f9e2303d4507f6d74355a73664d1440fb5a0ef59"
6843+
integrity sha1-+eIwPUUH9tdDVac2ZNFED7Wg71k=
6844+
68256845
jest-changed-files@^26.6.2:
68266846
version "26.6.2"
68276847
resolved "https://registry.npmjs.org/jest-changed-files/-/jest-changed-files-26.6.2.tgz"
@@ -7733,6 +7753,20 @@ matcher@^3.0.0:
77337753
dependencies:
77347754
escape-string-regexp "^4.0.0"
77357755

7756+
mathjs@^9.3.0:
7757+
version "9.3.0"
7758+
resolved "https://registry.yarnpkg.com/mathjs/-/mathjs-9.3.0.tgz#59cc43b536b22616197e56da303604b430daa6ac"
7759+
integrity sha512-0kYW+TXgB8lCqUj5wHR2hqAO2twSbPRelSFgRJXiwAx4nM6FrIb43Jd6XhW7sVbwYB+9HCNiyg5Kn8VYeB7ilg==
7760+
dependencies:
7761+
complex.js "^2.0.11"
7762+
decimal.js "^10.2.1"
7763+
escape-latex "^1.2.0"
7764+
fraction.js "^4.0.13"
7765+
javascript-natural-sort "^0.7.1"
7766+
seedrandom "^3.0.5"
7767+
tiny-emitter "^2.1.0"
7768+
typed-function "^2.0.0"
7769+
77367770
md5.js@^1.3.4:
77377771
version "1.3.5"
77387772
resolved "https://registry.npmjs.org/md5.js/-/md5.js-1.3.5.tgz"
@@ -10505,6 +10539,11 @@ schema-utils@^3.0.0:
1050510539
ajv "^6.12.5"
1050610540
ajv-keywords "^3.5.2"
1050710541

10542+
seedrandom@^3.0.5:
10543+
version "3.0.5"
10544+
resolved "https://registry.yarnpkg.com/seedrandom/-/seedrandom-3.0.5.tgz#54edc85c95222525b0c7a6f6b3543d8e0b3aa0a7"
10545+
integrity sha512-8OwmbklUNzwezjGInmZ+2clQmExQPvomqjL7LFqOYqtmuxRgQYqOD3mHaU+MvZn5FLUeVxVfQjwLZW/n/JFuqg==
10546+
1050810547
select-hose@^2.0.0:
1050910548
version "2.0.0"
1051010549
resolved "https://registry.npmjs.org/select-hose/-/select-hose-2.0.0.tgz"
@@ -11442,6 +11481,11 @@ timsort@^0.3.0:
1144211481
resolved "https://registry.npmjs.org/timsort/-/timsort-0.3.0.tgz"
1144311482
integrity sha1-QFQRqOfmM5/mTbmiNN4R3DHgK9Q=
1144411483

11484+
tiny-emitter@^2.1.0:
11485+
version "2.1.0"
11486+
resolved "https://registry.yarnpkg.com/tiny-emitter/-/tiny-emitter-2.1.0.tgz#1d1a56edfc51c43e863cbb5382a72330e3555423"
11487+
integrity sha512-NB6Dk1A9xgQPMoGqC5CVXn123gWyte215ONT5Pp5a0yt4nlEoO1ZWeCwpncaekPHXO60i47ihFnZPiRPjRMq4Q==
11488+
1144511489
1144611490
version "1.0.4"
1144711491
resolved "https://registry.npmjs.org/tmpl/-/tmpl-1.0.4.tgz"
@@ -11661,6 +11705,11 @@ type@^2.0.0:
1166111705
resolved "https://registry.npmjs.org/type/-/type-2.3.0.tgz"
1166211706
integrity sha512-rgPIqOdfK/4J9FhiVrZ3cveAjRRo5rsQBAIhnylX874y1DX/kEKSVdLsnuHB6l1KTjHyU01VjiMBHgU2adejyg==
1166311707

11708+
typed-function@^2.0.0:
11709+
version "2.0.0"
11710+
resolved "https://registry.yarnpkg.com/typed-function/-/typed-function-2.0.0.tgz#15ab3825845138a8b1113bd89e60cd6a435739e8"
11711+
integrity sha512-Hhy1Iwo/e4AtLZNK10ewVVcP2UEs408DS35ubP825w/YgSBK1KVLwALvvIG4yX75QJrxjCpcWkzkVRB0BwwYlA==
11712+
1166411713
typedarray-to-buffer@^3.1.5:
1166511714
version "3.1.5"
1166611715
resolved "https://registry.npmjs.org/typedarray-to-buffer/-/typedarray-to-buffer-3.1.5.tgz"

0 commit comments

Comments
 (0)