-
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.
12 add custom timer to generate noteschords automatically (#16)
* Add AutoSkipper component * Add autoskipper on chords * Fix indent
- Loading branch information
1 parent
fe84a12
commit 6211d41
Showing
11 changed files
with
153 additions
and
27 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { ButtonGroup, Button, IconButton, useToast } from "@chakra-ui/react"; | ||
import { useEffect, useState } from "react"; | ||
import { Speed, speeds } from "../config"; | ||
import { getSpeedColor, getSpeedIcon } from "../services"; | ||
|
||
export const AutoSkipper = ({ onSkip }: { onSkip: () => void }) => { | ||
const toast = useToast(); | ||
const [speed, setSpeed] = useState<Speed | undefined>(undefined); | ||
const [intervalId, setIntervalId] = useState<number | undefined>(); | ||
|
||
useEffect(() => { | ||
if (speed) { | ||
const skipInterval = setInterval(() => { | ||
onSkip(); | ||
}, speed); | ||
|
||
setIntervalId(skipInterval); | ||
|
||
return () => clearInterval(skipInterval); | ||
} | ||
}, [onSkip, speed]); | ||
|
||
const handleStopAutoSkipper = () => { | ||
clearInterval(intervalId); | ||
setSpeed(undefined); | ||
}; | ||
|
||
const triggerToast = (skipDuration: Speed) => { | ||
toast({ | ||
title: `Auto-skip every ${skipDuration / 1000} seconds`, | ||
status: "info", | ||
duration: 1000, | ||
}); | ||
}; | ||
|
||
return ( | ||
<> | ||
<ButtonGroup size="sm" isAttached> | ||
<Button | ||
className={`w-full ${speed === undefined ? "cursor-default" : ""}`} | ||
variant="outline" | ||
onClick={handleStopAutoSkipper} | ||
disabled={speed === undefined} | ||
colorScheme={speed === undefined ? "grey" : "blue"} | ||
> | ||
{speed === undefined ? "Auto-skipper" : "Stop"} | ||
</Button> | ||
{speeds.map((s, i) => ( | ||
<IconButton | ||
key={i} | ||
aria-label="minus" | ||
icon={getSpeedIcon(s)} | ||
variant="outline" | ||
onClick={() => { | ||
triggerToast(s); | ||
setSpeed(s); | ||
}} | ||
isActive={speed === s} | ||
colorScheme={speed === s ? getSpeedColor(s) : ""} | ||
/> | ||
))} | ||
</ButtonGroup> | ||
</> | ||
); | ||
}; |
4 changes: 2 additions & 2 deletions
4
src/components/ChordsList/ChordsList.tsx → src/components/ChordsList.tsx
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 was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
src/components/NotesList/NotesList.tsx → src/components/NotesList.tsx
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,4 +1,4 @@ | ||
import { Note } from "../../config"; | ||
import { Note } from "../config"; | ||
|
||
export const NotesList = ({ | ||
notes, | ||
|
This file was deleted.
Oops, something went wrong.
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,15 @@ | ||
export enum Speed { | ||
walk = 15000, | ||
run = 10000, | ||
drive = 5000, | ||
fly = 3000, | ||
rush = 1000, | ||
} | ||
|
||
export const speeds = [ | ||
Speed.walk, | ||
Speed.run, | ||
Speed.drive, | ||
Speed.fly, | ||
Speed.rush, | ||
]; |
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,3 +1,4 @@ | ||
export * from "./noteService"; | ||
export * from "./stringService"; | ||
export * from "./chordService"; | ||
export * from "./speedService"; |
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 { | ||
FaCarSide, | ||
FaPlane, | ||
FaRocket, | ||
FaRunning, | ||
FaWalking, | ||
} from "react-icons/fa"; | ||
import { Speed } from "../config"; | ||
|
||
export const getSpeedIcon = (speed: Speed) => { | ||
switch (speed) { | ||
case Speed.walk: | ||
return <FaWalking />; | ||
case Speed.run: | ||
return <FaRunning />; | ||
case Speed.drive: | ||
return <FaCarSide />; | ||
case Speed.fly: | ||
return <FaPlane />; | ||
case Speed.rush: | ||
return <FaRocket />; | ||
} | ||
}; | ||
|
||
export const getSpeedColor = (speed: Speed) => { | ||
switch (speed) { | ||
case Speed.walk: | ||
return "yellow"; | ||
case Speed.run: | ||
return "orange"; | ||
case Speed.drive: | ||
return "red"; | ||
case Speed.fly: | ||
return "pink"; | ||
case Speed.rush: | ||
return "purple"; | ||
} | ||
}; |