Skip to content
This repository has been archived by the owner on Jun 26, 2024. It is now read-only.

Commit

Permalink
added paused functionality to start/stop
Browse files Browse the repository at this point in the history
  • Loading branch information
tryonlinux committed Aug 7, 2021
1 parent 9e2a0df commit 0c4a619
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 13 deletions.
10 changes: 7 additions & 3 deletions src/components/Actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import * as React from 'react';
export interface ActionsProps {
setTime: (time: number) => void;
toggleTimer: (isCounting: boolean) => void;
toggleIsStopped: () => void;
isStopped: boolean;
isCounting: boolean;
}

Expand All @@ -12,25 +14,27 @@ class Actions extends React.Component<ActionsProps, ActionsState> {
super(props);
this.state = {};
}

render() {
return (
<div className="column">
<button
style={{ backgroundColor: 'lightgreen' }}
disabled={this.props.isCounting}
disabled={!this.props.isStopped}
onClick={() => this.props.toggleTimer(true)}
>
Start
</button>
<button
style={{ backgroundColor: 'crimson' }}
disabled={!this.props.isCounting}
onClick={() => this.props.toggleTimer(false)}
disabled={this.props.isStopped}
onClick={() => this.props.toggleIsStopped()}
>
Stop
</button>
<button
style={{ backgroundColor: 'lightgray' }}
disabled={!this.props.isCounting}
onClick={() => this.props.setTime(25)}
>
Reset
Expand Down
20 changes: 10 additions & 10 deletions src/components/Editor.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//TODO Add flash function
//TODO add pause function to stop
//TODO add gif to readme
//TODO add to listed.to
import React from 'react';
Expand All @@ -22,7 +21,7 @@ const initialState = {
time: 25,
soundOn: true,
flashOn: true,
isStopped: false,
isStopped: true,
};

export default class Editor extends React.Component<{}, EditorInterface> {
Expand All @@ -33,25 +32,27 @@ export default class Editor extends React.Component<{}, EditorInterface> {
this.toggleTimer = this.toggleTimer.bind(this);
this.toggleSound = this.toggleSound.bind(this);
this.toggleFlash = this.toggleFlash.bind(this);
this.toggleIsStopped = this.toggleIsStopped.bind(this);
this.flash = this.flash.bind(this);
let componentRelay = new ComponentRelay({ targetWindow: window });
componentRelay.setSize('100%', '40px');
}

setTime(time: number): void {
this.setState({ time, isCounting: false });
this.setState({ time, isCounting: false, isStopped: true });
}
toggleTimer(isCounting: boolean) {
//TODO disable either start of stop
//TODO then either start the countdown or not
this.setState({ isCounting });
this.setState({ isCounting, isStopped: !this.state.isStopped });
}
toggleSound() {
this.setState({ soundOn: !this.state.soundOn });
}
toggleFlash() {
this.setState({ flashOn: !this.state.flashOn });
}
toggleIsStopped() {
this.setState({ isStopped: !this.state.isStopped });
}
flash() {
alert('flash flash');
}
Expand All @@ -66,25 +67,24 @@ export default class Editor extends React.Component<{}, EditorInterface> {
time={this.state.time}
soundOn={this.state.soundOn}
flashOn={this.state.flashOn}
isStopped={this.state.isStopped}
flash={this.flash}
/>
) : (
<TimeInput time={this.state.time} setTime={this.setTime} />
)}
</div>
<div className="vl column" />

<Actions
setTime={this.setTime}
isCounting={this.state.isCounting}
isStopped={this.state.isStopped}
toggleTimer={this.toggleTimer}
toggleIsStopped={this.toggleIsStopped}
/>
<div className="vl column" />

<Modes setTime={this.setTime} isCounting={this.state.isCounting} />

<div className="vl column" />

<Settings
soundOn={this.state.soundOn}
flashOn={this.state.flashOn}
Expand Down
9 changes: 9 additions & 0 deletions src/components/Timer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export interface TimerProps {
time: number;
soundOn: boolean;
flashOn: boolean;
isStopped: boolean;
flash: () => void;
}

Expand All @@ -27,6 +28,14 @@ class Timer extends React.Component<TimerProps, TimerState> {
if (this.props.time !== prevProps.time) {
this.setState({ mins: this.props.time });
}
if (this.props.isStopped !== prevProps.isStopped) {
if (this.props.isStopped) {
window.clearInterval(this.timer);
} else {
this.timer = 0;
this.startTimer();
}
}
}

componentDidMount() {
Expand Down

0 comments on commit 0c4a619

Please sign in to comment.