-
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.
- Loading branch information
Andy
authored and
Andy
committed
May 1, 2024
1 parent
64af220
commit a4f2d2b
Showing
4 changed files
with
62 additions
and
3 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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 { useState } from "react"; | ||
import { shuffle } from "lodash"; | ||
|
||
import { Note, Scale } from "@types"; | ||
import data from "@data"; | ||
|
||
export default function Challenge() { | ||
const { notes, scales } = data; | ||
// this stuff will need to be refs or go in an effect as we will lose it on renders... | ||
const shuffledNotes: Note[] = shuffle(notes); | ||
const randomScale: Scale = shuffle(scales).pop() || scales[0]; | ||
const notesInScale: number[] = [...randomScale.notes]; | ||
|
||
// on click, if id is in notes left, turn tile a color and remove said id from array | ||
const [notesLeft, setNotesLeft] = useState(notesInScale); | ||
// think about what the default state should be. On load, it's in progress | ||
const [inProgress, setInprogress] = useState(true); | ||
Check failure on line 17 in src/components/Modes/Challenge/Challenge.tsx GitHub Actions / build
|
||
|
||
const notesLeftCount = notesLeft.length; | ||
|
||
function handleClick(id: number): void { | ||
const index = notesLeft.indexOf(id); | ||
if (index > -1) { | ||
// match. Remove note | ||
const updated = [...notesLeft.splice(index, 1)]; | ||
setNotesLeft(updated); | ||
} | ||
} | ||
return ( | ||
<> | ||
<h2>Remaining Notes: {notesLeftCount} </h2> | ||
<h2>Scale: {randomScale.name}</h2> | ||
<div className="p-4 h-screen flex flex-row justify-center flex-wrap"> | ||
{shuffledNotes.map((note) => { | ||
return ( | ||
<button | ||
onClick={() => { | ||
handleClick(note.id); | ||
}} | ||
className="rounded-md m-2 bg-sky-500 basis-1/4" | ||
> | ||
{note.string} | ||
</button> | ||
); | ||
})} | ||
</div> | ||
</> | ||
); | ||
} |