-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Switch to CSS variables for colors and rem (based on vw) for sizes * Refactor to move progress up to App level * More refactoring and label the type of timer
- Loading branch information
1 parent
8389f89
commit 98c081e
Showing
7 changed files
with
110 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,58 @@ | ||
import buzz from "buzz"; | ||
import React from "react"; | ||
import React, { useState } from "react"; | ||
import { MdVolumeOff, MdVolumeUp } from "react-icons/md"; | ||
import Progress from "../Progress/Progress"; | ||
import Timer from "../Timer/Timer"; | ||
import "./App.css"; | ||
|
||
class App extends React.Component { | ||
chime = new buzz.sound( | ||
const App = () => { | ||
const [focusCount, setFocusCount] = useState(0); | ||
const [muted, setMuted] = useState(true); | ||
const [progress, setProgress] = useState(0); | ||
const [breakCount, setBreakCount] = useState(0); | ||
|
||
const chime = new buzz.sound( | ||
"https://soundbible.com/mp3/Electronic_Chime-KevanGC-495939803.mp3" | ||
); | ||
chime.mute(); | ||
|
||
state = { | ||
count: 0, | ||
isMuted: true | ||
}; | ||
|
||
componentDidMount() { | ||
this.state.isMuted && this.chime.mute(); | ||
} | ||
|
||
render() { | ||
const { count, isMuted } = this.state; | ||
|
||
return ( | ||
<div className="App"> | ||
<Timer onComplete={this.handleComplete} key={count} /> | ||
<button | ||
className={`App-toggleMuteButton ${isMuted && "is-muted"}`} | ||
onClick={this.toggleMute} | ||
> | ||
{isMuted ? <MdVolumeOff /> : <MdVolumeUp />} | ||
</button> | ||
</div> | ||
); | ||
} | ||
|
||
toggleMute = () => { | ||
const toggleMute = () => { | ||
this.chime.toggleMute(); | ||
this.setState({ | ||
isMuted: !this.state.isMuted | ||
}); | ||
setMuted(!muted); | ||
}; | ||
|
||
handleComplete = () => { | ||
if (!this.state.isMuted) { | ||
const handleComplete = timerType => { | ||
if (!muted) { | ||
this.chime.play(); | ||
} | ||
|
||
// Increment the timer's key so that it starts the next countdown. | ||
this.setState({ count: this.state.count + 1 }); | ||
timerType === "focus" | ||
? setFocusCount(focusCount + 1) | ||
: setBreakCount(breakCount + 1); | ||
}; | ||
} | ||
|
||
const handleTick = (timerInfo, nextStop) => { | ||
setProgress(1 - timerInfo.total / (nextStop.duration * 60 * 1000)); | ||
}; | ||
|
||
return ( | ||
<div className="App"> | ||
<Timer | ||
onTick={handleTick} | ||
onComplete={handleComplete} | ||
key={`${focusCount + breakCount}$`} | ||
/> | ||
<div className="App-progress"> | ||
<Progress progress={progress} /> | ||
</div> | ||
<button | ||
className={`App-toggleMuteButton ${muted && "is-muted"}`} | ||
onClick={toggleMute} | ||
> | ||
{muted ? <MdVolumeOff /> : <MdVolumeUp />} | ||
</button> | ||
</div> | ||
); | ||
}; | ||
|
||
export default App; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,23 @@ | ||
@import url("https://fonts.googleapis.com/css?family=Space+Mono&display=swap"); | ||
|
||
:root { | ||
--darkBlue: #222831; | ||
--lightGray: #eeeeee; | ||
--mediumGray: #bbbbbb; | ||
--red: #d65a31; | ||
--darkGray: #141414; | ||
--monospace: "Space Mono", monospace; | ||
} | ||
|
||
html { | ||
font-size: 2vw; | ||
} | ||
|
||
body { | ||
-moz-osx-font-smoothing: grayscale; | ||
-webkit-font-smoothing: antialiased; | ||
background-color: #222831; | ||
background-color: var(--darkBlue); | ||
margin: 0; | ||
padding: 0; | ||
font-family: var(--monospace); | ||
} |