-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FEAT: Adds
Global controls
section. (#7)
## Features * FEAT: pass `isPlaying` and `setPlaying` to osc directly * FEAT: nicer structure * FEAT: `toggleOscillator` -> `useState` * FEAT: started refactor, small UI tweaks ## Docs * DOC: update `README.md` and enhance `TODOs`, typo fix
- Loading branch information
1 parent
e9e637b
commit be7fd33
Showing
7 changed files
with
144 additions
and
61 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
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import "./audioStyles.scss"; | ||
import React, { useState, useEffect } from "react"; | ||
|
||
export default function GlobalPlayPause(props) { | ||
// props.playStates: array of each InteractiveOscillator | ||
// isPlaying and setPlaying keys | ||
const [isPlayingGlobal, setPlayingGlobal] = useState(false); | ||
|
||
// Get state changes of oscillators | ||
useEffect(() => { | ||
setPlayingGlobal( | ||
props.playStates.map((oscPlayData) => oscPlayData.isPlaying).some(Boolean) | ||
); | ||
}, [props.playStates, isPlayingGlobal]); | ||
|
||
const handleGlobalPlayPause = () => { | ||
console.log(`All oscillators ` + (isPlayingGlobal ? "stopped" : "started")); | ||
props.playStates.map((oscPlayData) => | ||
oscPlayData.setPlaying(!isPlayingGlobal) | ||
); | ||
}; | ||
|
||
return ( | ||
<div> | ||
<label htmlFor="global-play-pause"> | ||
Global Controls: | ||
<br /> | ||
<button | ||
onClick={handleGlobalPlayPause} | ||
id="global-play-pause" | ||
className={ | ||
isPlayingGlobal ? "play-pause-button paused" : "play-pause-button" | ||
} | ||
/> | ||
</label> | ||
</div> | ||
); | ||
} |
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