-
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.
* Save. * Visual cue - not right * Sync intervals * Fix visual cue
- Loading branch information
1 parent
2eef331
commit 6c76db7
Showing
13 changed files
with
236 additions
and
67 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,25 @@ | ||
import { Speed } from "../config"; | ||
import { GoDot, GoDotFill } from "react-icons/go"; | ||
import { useSpeedContext } from "../hooks"; | ||
|
||
export const TimerCue = () => { | ||
const { speed, secondsElapsed } = useSpeedContext(); | ||
|
||
const numberOfDots = speed ? speed / 1000: 0; | ||
const dots: React.ReactNode[] = []; | ||
|
||
for (let i = 0; i < secondsElapsed; i++) { | ||
dots.push(<GoDotFill />); | ||
} | ||
for (let i = 0; i < numberOfDots - secondsElapsed; i++) { | ||
dots.push(<GoDot />); | ||
} | ||
|
||
if (speed === Speed.rush) { | ||
return <></>; | ||
} | ||
|
||
return ( | ||
<div className="flex mb-3 text-2xl text-blue-600">{dots.map((d, i) => <div key={i}>{d}</div>)}</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
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,49 @@ | ||
import { Dispatch, SetStateAction, createContext, useEffect, useState } from 'react'; | ||
import { Speed } from '../config'; | ||
|
||
interface SpeedContextProps { | ||
speed: Speed | undefined, | ||
setCurrentSpeed: (speed?: Speed) => void, | ||
secondsElapsed: number, | ||
setSecondsElapsed: Dispatch<SetStateAction<number>>, | ||
resetSecondsElapsed: () => void, | ||
} | ||
|
||
export const SpeedContext = createContext<SpeedContextProps | undefined>(undefined); | ||
|
||
export const SpeedContextProvider = ({ children }: { children: React.ReactNode }) => { | ||
const [speed, setSpeed] = useState<Speed>(); | ||
const [secondsElapsed, setSecondsElapsed] = useState(0); | ||
|
||
const setCurrentSpeed = (speed?: Speed) => { | ||
setSpeed(speed); | ||
} | ||
|
||
const resetSecondsElapsed = () => { | ||
setSecondsElapsed(0); | ||
} | ||
|
||
useEffect(() => { | ||
if (speed) { | ||
const stepInterval = setInterval(() => { | ||
setSecondsElapsed((prevState: number) => prevState + 1); | ||
}, 1000); | ||
|
||
return () => clearInterval(stepInterval); | ||
} | ||
}, [secondsElapsed, setSecondsElapsed, speed]); | ||
|
||
return ( | ||
<SpeedContext.Provider | ||
value={{ | ||
speed, | ||
setCurrentSpeed, | ||
secondsElapsed, | ||
setSecondsElapsed, | ||
resetSecondsElapsed, | ||
}} | ||
> | ||
{children} | ||
</SpeedContext.Provider> | ||
); | ||
}; |
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,2 +1,3 @@ | ||
export * from './useNoteSettingsContext'; | ||
export * from './useChordSettingsContext'; | ||
export * from './useSpeedContext'; |
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,10 @@ | ||
import { useContext } from "react"; | ||
import { SpeedContext } from "../contexts/SpeedContext"; | ||
|
||
export const useSpeedContext = () => { | ||
const context = useContext(SpeedContext); | ||
if (!context) { | ||
throw new Error('useSpeedContext must be used within a SpeedContextProvider'); | ||
} | ||
return context; | ||
}; |
Oops, something went wrong.