Skip to content

Commit cfca056

Browse files
committed
Started adding sound
1 parent 136b102 commit cfca056

File tree

5 files changed

+27
-15
lines changed

5 files changed

+27
-15
lines changed

package.json

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"react-moment": "^1.1.1",
2626
"react-scripts": "4.0.3",
2727
"typescript": "^4.1.2",
28+
"use-sound": "^2.0.1",
2829
"wait-on": "^5.3.0",
2930
"web-vitals": "^1.0.1"
3031
},
@@ -38,6 +39,7 @@
3839
"postinstall": "electron-builder install-app-deps",
3940
"electron-pack": "yarn build --em.main=build/electron.js",
4041
"preelectron-pack": "yarn build",
42+
"prepackage-win": "yarn build",
4143
"package-win": "electron-packager . electimer --overwrite --platform=win32 --arch=x64 --icon=public/favicon.ico --out=release-builds --version-string.CompanyName=CE --version-string.FileDescription=CE --version-string.ProductName=\"Electimer\""
4244
},
4345
"build": {

public/bensound-creativeminds.mp3

2.81 MB
Binary file not shown.

src/Components/MainForm.tsx

-4
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,7 @@ export class MainForm extends React.Component<{ message: string}, MainFormState>
2020
render(){
2121
return(
2222
<div>
23-
<div onClick={() => this.increment(1)}>
24-
{this.state.count}
25-
</div>
2623
<TimeInput ></TimeInput>
27-
<Moment format="YYYY/MM/DD hh:mm:ss"></Moment>
2824
</div>
2925

3026
)

src/Components/Timer.tsx

+13-11
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@ import React from "react";
22
import './styles.css';
33
import Moment from 'react-moment';
44
import moment from 'moment';
5+
import useSound from 'use-sound';
56

67
type TimerProps = {
78
duration: number
89
}
910

1011
type TimerState = {
1112
running: boolean
12-
start: number
13-
end: number
13+
start: Date
14+
end: Date
1415
remainingTime: number
1516
}
1617

@@ -21,33 +22,32 @@ export default class Timer extends React.Component<TimerProps, TimerState>{
2122
super(props);
2223
this.state = {
2324
running: false,
24-
start: 0,
25-
end: 0,
25+
start: new Date(),
26+
end: new Date(),
2627
remainingTime: 0
2728
}
2829
}
2930

3031

3132
startTimer = () => {
32-
var start = new Date().getTime();
33+
var start = new Date();
3334
this.setState({
3435
running: true,
3536
start: start,
36-
end: start + this.props.duration * 1000
37+
end: moment(start).add(this.props.duration, 's').toDate()
3738
})
3839
}
3940

4041
stopTimer = () => {
4142
this.setState({
4243
running: false,
43-
start: 0,
44-
end: 0
4544
})
4645
}
4746

4847
tick = () => {
48+
var now = moment(new Date())
4949
this.setState({
50-
remainingTime: this.state.end - new Date().getTime()
50+
remainingTime: moment(this.state.end).diff(now)
5151
})
5252
if(this.state.running && this.state.remainingTime <= 0)
5353
{
@@ -69,11 +69,13 @@ export default class Timer extends React.Component<TimerProps, TimerState>{
6969
this.intervalId = null;
7070
}
7171
render(){
72+
const toPositiveFilter = (d: string) => {
73+
return d.replace("-", "")
74+
}
7275
return(
7376
<div>
7477
<button onClick={this.startTimer} className="button" >Start</button> <button onClick={this.stopTimer} className="button">Stop</button>
75-
<p>{ this.state.running ? <Moment format="YYYY/mm/dd hh:mm:ss">{this.state.remainingTime}</Moment> : null }</p>
76-
<p>{ this.state.running ? this.state.remainingTime/1000 : null }</p>
78+
<p>{ this.state.running ? <Moment durationFromNow filter={toPositiveFilter}>{this.state.end}</Moment> : null }</p>
7779
</div>
7880
)
7981
}

yarn.lock

+12
Original file line numberDiff line numberDiff line change
@@ -6028,6 +6028,11 @@ hosted-git-info@^4.0.1:
60286028
dependencies:
60296029
lru-cache "^6.0.0"
60306030

6031+
howler@^2.1.3:
6032+
version "2.2.1"
6033+
resolved "https://registry.yarnpkg.com/howler/-/howler-2.2.1.tgz#a521a9b495841e8bb9aa12e651bebba0affc179e"
6034+
integrity sha512-0iIXvuBO/81CcrQ/HSSweYmbT50fT2mIc9XMFb+kxIfk2pW/iKzDbX1n3fZmDXMEIpYvyyfrB+gXwPYSDqUxIQ==
6035+
60316036
hpack.js@^2.1.6:
60326037
version "2.1.6"
60336038
resolved "https://registry.npmjs.org/hpack.js/-/hpack.js-2.1.6.tgz"
@@ -11841,6 +11846,13 @@ url@^0.11.0:
1184111846
punycode "1.3.2"
1184211847
querystring "0.2.0"
1184311848

11849+
use-sound@^2.0.1:
11850+
version "2.0.1"
11851+
resolved "https://registry.yarnpkg.com/use-sound/-/use-sound-2.0.1.tgz#72e70d4bfdda71a6959e5adab0c7e10ff4080a0a"
11852+
integrity sha512-wNwnyIOe8QPDQgWRZd3PqVEJ9BpLO+VJX+EpQSb6EvvjblHhnYMD7WIOTQ4hgloC2jC7Az6FhclHilC441De7A==
11853+
dependencies:
11854+
howler "^2.1.3"
11855+
1184411856
use@^3.1.0:
1184511857
version "3.1.1"
1184611858
resolved "https://registry.npmjs.org/use/-/use-3.1.1.tgz"

0 commit comments

Comments
 (0)