-
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
1 parent
1f34336
commit 5485d25
Showing
21 changed files
with
206 additions
and
38 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { Chord } from "../../config"; | ||
import { chordToString } from "../../services/chordService"; | ||
|
||
export const ChordsList = ({ chords }: { chords: Chord[] }) => { | ||
return ( | ||
<div className="flex flex-col md:flex-row md:gap-7 text-[35px] md:text-[75px] mb-6 font-bold"> | ||
{chords.map((chord: Chord, index: number) => ( | ||
<div key={index}>{chordToString(chord)}</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './ChordsList'; |
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 +1,2 @@ | ||
export * from './NotesList'; | ||
export * from './ChordsList'; |
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,4 @@ | ||
export enum AppPages { | ||
notes = "Notes", | ||
chords = "Chords", | ||
} |
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,17 @@ | ||
import { Note } from "."; | ||
|
||
export enum ChordsType { | ||
Major = "", | ||
Minor = "m", | ||
MajorSeventh = "maj7", | ||
MinorSeventh = "min7", | ||
} | ||
|
||
export type ChordType = keyof typeof ChordsType; | ||
|
||
export const chords = Object.values(ChordsType) as unknown as ChordType[]; | ||
|
||
export type Chord = { | ||
note: Note; | ||
chordType: ChordType; | ||
}; |
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,12 +1,14 @@ | ||
export enum GuitarStrings { | ||
String1 = 'String 1', | ||
String2 = 'String 2', | ||
String3 = 'String 3', | ||
String4 = 'String 4', | ||
String5 = 'String 5', | ||
String6 = 'String 6', | ||
String1 = "String 1", | ||
String2 = "String 2", | ||
String3 = "String 3", | ||
String4 = "String 4", | ||
String5 = "String 5", | ||
String6 = "String 6", | ||
} | ||
|
||
export type GuitarString = keyof typeof GuitarStrings; | ||
|
||
export const guitarStrings = Object.values(GuitarStrings) as unknown as GuitarString[]; | ||
export const guitarStrings = Object.values( | ||
GuitarStrings | ||
) as unknown as GuitarString[]; |
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,3 @@ | ||
export const DEFAULT_NUMBER_OF_CHORD = 3; | ||
export const CHORDS_LIST_MAX = 3; | ||
export const CHORDS_LIST_MIN = 1; |
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 +1,2 @@ | ||
export * from './notes'; | ||
export * from './chords'; |
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,4 @@ | ||
export * from './Notes'; | ||
export * from './GuitarStrings'; | ||
export * from "./Notes"; | ||
export * from "./GuitarStrings"; | ||
export * from "./Chords"; | ||
export * from "./AppPages"; |
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,69 @@ | ||
import { useState } from "react"; | ||
import { Button, IconButton } from "@chakra-ui/react"; | ||
|
||
import { FaPlus, FaMinus } from "react-icons/fa"; | ||
|
||
import { ChordsList } from "../components"; | ||
|
||
import { getListOfRandomChords, isValidChordCountList } from "../services"; | ||
import { | ||
DEFAULT_NUMBER_OF_CHORD, | ||
CHORDS_LIST_MAX, | ||
CHORDS_LIST_MIN, | ||
} from "../config/constants"; | ||
|
||
export const ChordsPage = () => { | ||
const [chords, setChords] = useState( | ||
getListOfRandomChords(DEFAULT_NUMBER_OF_CHORD) | ||
); | ||
|
||
const [numberOfChordDisplayed, setNumberOfChordDisplayed] = useState( | ||
DEFAULT_NUMBER_OF_CHORD | ||
); | ||
|
||
const handleGetRandomChordOnClick = () => { | ||
setChords(getListOfRandomChords(numberOfChordDisplayed)); | ||
}; | ||
|
||
const handleChangeNumberOfChordDisplayed = (step: number) => { | ||
setNumberOfChordDisplayed((prevState: number) => { | ||
const value = prevState + step; | ||
if (isValidChordCountList(value)) { | ||
return value; | ||
} | ||
return prevState; | ||
}); | ||
}; | ||
|
||
return ( | ||
<div className="h-full flex flex-col items-center justify-center"> | ||
<div className="text-lg font-semibold mb-10">RANDOM CHORDS GENERATOR</div> | ||
<div className="w-screen flex items-center justify-center"> | ||
<div className="flex flex-col items-center"> | ||
<ChordsList chords={chords} /> | ||
<div className="flex flex-col gap-1"> | ||
<div className="flex gap-1"> | ||
<IconButton | ||
aria-label="minus" | ||
icon={<FaMinus />} | ||
variant="outline" | ||
onClick={() => handleChangeNumberOfChordDisplayed(-1)} | ||
disabled={numberOfChordDisplayed === CHORDS_LIST_MIN} | ||
/> | ||
<Button variant="outline" onClick={handleGetRandomChordOnClick}> | ||
Generate list of {numberOfChordDisplayed} chords | ||
</Button> | ||
<IconButton | ||
aria-label="plus" | ||
icon={<FaPlus />} | ||
variant="outline" | ||
onClick={() => handleChangeNumberOfChordDisplayed(1)} | ||
disabled={numberOfChordDisplayed === CHORDS_LIST_MAX} | ||
/> | ||
</div> | ||
</div> | ||
</div> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './NotesPage'; | ||
export * from "./NotesPage"; | ||
export * from "./ChordsPage"; |
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,28 @@ | ||
import { getRandomNote } from "./"; | ||
import { Chord, ChordType, chords } from "../config"; | ||
import { getRandomItemFrom } from "../utils/random"; | ||
import { CHORDS_LIST_MAX, CHORDS_LIST_MIN } from "../config/constants"; | ||
|
||
export const getRandomChordType = (): ChordType => { | ||
return getRandomItemFrom(chords); | ||
}; | ||
|
||
export const getRandomChord = (): Chord => { | ||
return { note: getRandomNote(), chordType: getRandomChordType() } as Chord; | ||
}; | ||
|
||
export const chordToString = (chord: Chord): string => { | ||
return `${chord.note}${chord.chordType}`; | ||
} | ||
|
||
export const getListOfRandomChords = (count: number): Chord[] => { | ||
const randomChords: Chord[] = []; | ||
for(let i = 0; i < count; i++) { | ||
randomChords.push(getRandomChord()); | ||
} | ||
return randomChords; | ||
}; | ||
|
||
export const isValidChordCountList = (count: number): boolean => { | ||
return count >= CHORDS_LIST_MIN && count <= CHORDS_LIST_MAX | ||
} |
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 './noteService' | ||
export * from './stringService' | ||
export * from "./noteService"; | ||
export * from "./stringService"; | ||
export * from "./chordService"; |
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,5 +1,6 @@ | ||
import { GuitarString, guitarStrings } from "../config"; | ||
import { getRandomItemFrom } from "../utils/random"; | ||
|
||
export const getRandomString = (): GuitarString => { | ||
return guitarStrings[Math.floor(Math.random()*guitarStrings.length)]; | ||
return getRandomItemFrom(guitarStrings); | ||
}; |
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,3 @@ | ||
export const getRandomItemFrom = <T>(arrary: T[]): T => { | ||
return arrary[Math.floor(Math.random()*arrary.length)]; | ||
}; |
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,7 +1,7 @@ | ||
import { Note } from "../config/Notes"; | ||
|
||
export const shuffle = (array: Note[]): Note[] => { | ||
const arrayCopy = [...array]; | ||
const arrayCopy = [...array]; | ||
|
||
return arrayCopy.sort(() => Math.random() - 0.5); | ||
}; |