-
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.
* Add note context and redesign note * Add chord context [broken] * Add chord context * App redesign
- Loading branch information
1 parent
6211d41
commit 7981d0d
Showing
15 changed files
with
329 additions
and
207 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { | ||
ButtonGroup, | ||
IconButton, | ||
Button, | ||
PopoverContent, | ||
Popover, | ||
PopoverArrow, | ||
PopoverBody, | ||
PopoverTrigger, | ||
} from "@chakra-ui/react"; | ||
import { FaMinus, FaPlus } from "react-icons/fa"; | ||
import { MdBuild } from "react-icons/md"; | ||
import { CHORDS_LIST_MIN, CHORDS_LIST_MAX } from "../config/constants"; | ||
import { AutoSkipper } from "./AutoSkipper"; | ||
import { useChordSettingsContext } from "../hooks"; | ||
|
||
export const ChordsSettings = () => { | ||
const { | ||
numberOfChordDisplayed, | ||
getRandomChordsOnClick, | ||
changeNumberOfChordDisplayed, | ||
toggleShapeVisible, | ||
} = useChordSettingsContext(); | ||
|
||
return ( | ||
<Popover> | ||
<PopoverTrigger> | ||
<IconButton icon={<MdBuild />} aria-label={"settings"}> | ||
Settings | ||
</IconButton> | ||
</PopoverTrigger> | ||
<PopoverContent> | ||
<PopoverArrow /> | ||
<PopoverBody> | ||
<div className="flex flex-col gap-3 items-stretch"> | ||
<ButtonGroup variant="outline"> | ||
<IconButton | ||
aria-label="minus" | ||
icon={<FaMinus />} | ||
onClick={() => changeNumberOfChordDisplayed(-1)} | ||
disabled={numberOfChordDisplayed === CHORDS_LIST_MIN} | ||
/> | ||
<Button onClick={getRandomChordsOnClick}> | ||
Generate list of {numberOfChordDisplayed} chords | ||
</Button> | ||
<IconButton | ||
aria-label="plus" | ||
icon={<FaPlus />} | ||
onClick={() => changeNumberOfChordDisplayed(1)} | ||
disabled={numberOfChordDisplayed === CHORDS_LIST_MAX} | ||
/> | ||
</ButtonGroup> | ||
<Button | ||
variant="outline" | ||
leftIcon={<MdBuild />} | ||
onClick={toggleShapeVisible} | ||
> | ||
Toggle shape complexity | ||
</Button> | ||
<AutoSkipper onSkip={getRandomChordsOnClick} /> | ||
</div> | ||
</PopoverBody> | ||
</PopoverContent> | ||
</Popover> | ||
); | ||
}; |
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,56 @@ | ||
import { | ||
ButtonGroup, | ||
IconButton, | ||
Button, | ||
PopoverContent, | ||
Popover, | ||
PopoverArrow, | ||
PopoverBody, | ||
PopoverTrigger, | ||
} from '@chakra-ui/react'; | ||
import { FaMinus, FaPlus } from 'react-icons/fa'; | ||
import { MdBuild } from 'react-icons/md'; | ||
import { NOTES_LIST_MIN, NOTES_LIST_MAX } from '../config/constants'; | ||
import { AutoSkipper } from './AutoSkipper'; | ||
import { useNoteSettingsContext } from '../hooks'; | ||
|
||
export const NotesSettings = () => { | ||
const { numberOfNoteDisplayed, getRandomNotesOnClick, changeNumberOfNoteDisplayed, toggleStringVisible } = | ||
useNoteSettingsContext(); | ||
|
||
return ( | ||
<Popover> | ||
<PopoverTrigger> | ||
<IconButton icon={<MdBuild />} aria-label={'settings'}> | ||
Settings | ||
</IconButton> | ||
</PopoverTrigger> | ||
<PopoverContent> | ||
<PopoverArrow /> | ||
<PopoverBody> | ||
<div className="flex flex-col gap-3 items-stretch"> | ||
<ButtonGroup variant="outline"> | ||
<IconButton | ||
aria-label="minus" | ||
icon={<FaMinus />} | ||
onClick={() => changeNumberOfNoteDisplayed(-1)} | ||
disabled={numberOfNoteDisplayed === NOTES_LIST_MIN} | ||
/> | ||
<Button onClick={getRandomNotesOnClick}>Generate list of {numberOfNoteDisplayed} notes</Button> | ||
<IconButton | ||
aria-label="plus" | ||
icon={<FaPlus />} | ||
onClick={() => changeNumberOfNoteDisplayed(1)} | ||
disabled={numberOfNoteDisplayed === NOTES_LIST_MAX} | ||
/> | ||
</ButtonGroup> | ||
<Button variant="outline" leftIcon={<MdBuild />} onClick={toggleStringVisible}> | ||
Toggle string complexity | ||
</Button> | ||
<AutoSkipper onSkip={getRandomNotesOnClick} /> | ||
</div> | ||
</PopoverBody> | ||
</PopoverContent> | ||
</Popover> | ||
); | ||
}; |
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,5 @@ | ||
export * from './NotesList'; | ||
export * from './ChordsList'; | ||
export * from './AutoSkipper'; | ||
export * from './NotesSettings' | ||
export * from './ChordsSettings'; |
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,58 @@ | ||
import { createContext, useState } from 'react'; | ||
import { DEFAULT_NUMBER_OF_CHORD, } from '../config/constants'; | ||
import { getListOfRandomChords, getRandomNoteFromCaged, isValidChordCountList } from '../services'; | ||
import { CagedType, Chord } from '../config'; | ||
|
||
interface ChordSettingsContextProps { | ||
chords: Chord[]; | ||
numberOfChordDisplayed: number; | ||
isShapeVisible: boolean; | ||
cagedPosition: CagedType; | ||
getRandomChordsOnClick: () => void; | ||
changeNumberOfChordDisplayed: (step: number) => void; | ||
toggleShapeVisible: () => void; | ||
} | ||
|
||
export const ChordSettingsContext = createContext<ChordSettingsContextProps | undefined>(undefined); | ||
|
||
export const ChordSettingsContextProvider = ({ children }: { children: React.ReactNode }) => { | ||
const [chords, setChords] = useState<Chord[]>(getListOfRandomChords(DEFAULT_NUMBER_OF_CHORD)); | ||
const [numberOfChordDisplayed, setNumberOfChordDisplayed] = useState(DEFAULT_NUMBER_OF_CHORD); | ||
const [isShapeVisible, setIsShapeVisible] = useState(false); | ||
const [cagedPosition, setCagedPosition] = useState<CagedType>(getRandomNoteFromCaged()); | ||
|
||
const changeNumberOfChordDisplayed = (step: number) => { | ||
setNumberOfChordDisplayed((prevState: number) => { | ||
const value = prevState + step; | ||
if (isValidChordCountList(value)) { | ||
return value; | ||
} | ||
return prevState; | ||
}); | ||
}; | ||
|
||
const toggleShapeVisible = () => { | ||
setIsShapeVisible((prevState: boolean) => !prevState); | ||
}; | ||
|
||
const getRandomChordsOnClick = () => { | ||
setChords(getListOfRandomChords(numberOfChordDisplayed)); | ||
setCagedPosition(getRandomNoteFromCaged()); | ||
}; | ||
|
||
return ( | ||
<ChordSettingsContext.Provider | ||
value={{ | ||
chords, | ||
numberOfChordDisplayed, | ||
isShapeVisible, | ||
cagedPosition, | ||
getRandomChordsOnClick, | ||
changeNumberOfChordDisplayed, | ||
toggleShapeVisible, | ||
}} | ||
> | ||
{children} | ||
</ChordSettingsContext.Provider> | ||
); | ||
}; |
Oops, something went wrong.