Skip to content

Commit

Permalink
WIP add challenge
Browse files Browse the repository at this point in the history
  • Loading branch information
Andy authored and Andy committed May 2, 2024
1 parent ba44cf1 commit f85f580
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 14 deletions.
19 changes: 11 additions & 8 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { useState, useEffect } from "react";
import ModeToggle from "@components/ModeToggle/ModeToggle";
import Review from "@components/Modes/Review/Review";
import Challenge from "@components/Modes/Challenge/Challenge";
import ChallengeContextProvider from "@context/challenge";

import { Mode } from "@types";

Expand All @@ -15,15 +16,17 @@ function App() {
const [activeMode, setActiveMode] = useState(Mode.review);

return (
<div className="p-4 h-screen flex flex-col justify-center">
<div>
<h1 className="text-3xl font-bold text-center mb-12 text-sky-500/100">
Music Theory Practice
</h1>
<ModeToggle activeMode={activeMode} setActiveMode={setActiveMode} />
{activeMode === Mode.review ? <Review /> : <Challenge />}
<ChallengeContextProvider>
<div className="p-4 h-screen flex flex-col justify-center">
<div>
<h1 className="text-3xl font-bold text-center mb-12 text-sky-500/100">
Music Theory Practice
</h1>
<ModeToggle activeMode={activeMode} setActiveMode={setActiveMode} />
{activeMode === Mode.review ? <Review /> : <Challenge />}
</div>
</div>
</div>
</ChallengeContextProvider>
);
}

Expand Down
6 changes: 4 additions & 2 deletions src/components/Modes/Challenge/Challenge.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { useState } from "react";
import { useState, useContext } from "react";
import classNames from "classnames";
import { shuffle } from "lodash";

import { Note, Scale } from "@types";
import data from "@data";

import { ChallengeContext } from "@context/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);
Expand All @@ -16,7 +17,7 @@ export default function Challenge() {
const [notesFound, setNotesFound] = useState<number[]>([]);
const [inProgress, setInprogress] = useState<boolean>(true);
const notesLeftCount = notesLeft.length;

console.log("context", useContext(ChallengeContext));
function handleClick(id: number): void {
const index = notesLeft.indexOf(id);
if (index > -1) {
Expand Down Expand Up @@ -48,6 +49,7 @@ export default function Challenge() {
onClick={() => {
handleClick(note.id);
}}
key={note.id}
className={classNames("rounded-md m-2 basis-1/4 h-20", {
"bg-green-500": notesFound.includes(note.id),
"bg-sky-500/50": !notesFound.includes(note.id),
Expand Down
6 changes: 2 additions & 4 deletions src/components/Notes/Notes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,8 @@ export default function Notes({ activeNotes, activeScale }: NotesProps) {
return (
<div className="flex flex-row items-baseline justify-evenly mb-8">
{activeNotes.map((note, i) => (
<div className="flex flex-col basis-1/4">
<button key={note.id} className={getNoteClass(note)}>
{note.string}
</button>
<div key={note.id} className="flex flex-col basis-1/4">
<button className={getNoteClass(note)}>{note.string}</button>
<div className="self-center">{mapNotesToLabelsMajor(i)} </div>
</div>
))}
Expand Down
16 changes: 16 additions & 0 deletions src/context/challenge.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import React, { createContext, useState } from "react";
export const ChallengeContext = createContext({});

type Props = {
children: React.ReactNode;
};

export default function ChallengeContextProvider({ children }: Props) {
const [foo, setFoo] = useState(false);

return (
<ChallengeContext.Provider value={{ foo, setFoo }}>
{children}
</ChallengeContext.Provider>
);
}
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"@data":["src/data.json"],
"@components/*": ["src/components/*"],
"@utils/*": ["src/utils/*"],
"@context/*": ["src/context/*"],
"@types": ["src/types.ts"],
},
"target": "ES2020",
Expand Down
1 change: 1 addition & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export default defineConfig({
"@utils": path.resolve(__dirname, "./src/utils"),
"@data": path.resolve(__dirname, "./src/data.json"),
"@types": path.resolve(__dirname, "./src/types.ts"),
"@context": path.resolve(__dirname, "./src/context"),
},
},
test: {
Expand Down

0 comments on commit f85f580

Please sign in to comment.