Skip to content

Commit

Permalink
use as const
Browse files Browse the repository at this point in the history
  • Loading branch information
cyrilgourgouillon committed Dec 3, 2023
1 parent 9cdf5cb commit 0e82a1f
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 66 deletions.
14 changes: 2 additions & 12 deletions src/config/Caged.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
import { Notes } from ".";
export const cagedNotes = ['Shape C', 'Shape A', 'Shape G', 'Shape E', 'Shape D'] as const;

export enum Caged {
Shape1 = `Shape ${Notes.C}`,
Shape2 = `Shape ${Notes.A}`,
Shape3 = `Shape ${Notes.G}`,
Shape4 = `Shape ${Notes.E}`,
Shape5 = `Shape ${Notes.D}`,
}

export type CagedType = keyof typeof Caged;

export const cagedNotes = Object.values(Caged) as unknown as CagedType[];
export type Caged = (typeof cagedNotes)[number];
13 changes: 3 additions & 10 deletions src/config/Chords.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
import { Note } from ".";
import { Note } from '.';

export enum ChordsType {
Major = "M",
Minor = "m",
MajorSeventh = "maj7",
MinorSeventh = "min7",
}
export const chordTypes = ['M', 'm', 'maj7', 'min7'] as const;

export type ChordType = '' | 'm' | 'maj7' | 'min7';

export const chordTypes = Object.values(ChordsType) as ChordType[];
export type ChordType = (typeof chordTypes)[number];

export type Chord = {
note: Note;
Expand Down
15 changes: 2 additions & 13 deletions src/config/GuitarStrings.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,3 @@
export enum GuitarStrings {
String1 = "String 1",
String2 = "String 2",
String3 = "String 3",
String4 = "String 4",
String5 = "String 5",
String6 = "String 6",
}
export const guitarStrings = ['String 1', 'String 2', 'String 3', 'String 4', 'String 5', 'String 6'];

export type GuitarString = keyof typeof GuitarStrings;

export const guitarStrings = Object.values(
GuitarStrings
) as unknown as GuitarString[];
export type GuitarString = (typeof guitarStrings)[number];
42 changes: 20 additions & 22 deletions src/config/Notes.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
export enum Notes {
C = "C",
Csharp = "C#",
Dbemol = "Db",
D = "D",
Dsharp = "D#",
Ebemol = "Eb",
E = "E",
F = "F",
Fsharp = "F#",
Gbemol = "Gb",
G = "G",
Gsharp = "G#",
Abemol = "Ab",
A = "A",
Asharp = "A#",
Bbemol = "Bb",
B = "B",
}
export const notes = [
'C',
'C#',
'Db',
'D',
'D#',
'Eb',
'E',
'F',
'F#',
'Gb',
'G',
'G#',
'Ab',
'A',
'A#',
'Bb',
'B',
] as const;

export type Note = keyof typeof Notes;

export const notes = Object.values(Notes) as Note[];
export type Note = typeof notes[number];
6 changes: 3 additions & 3 deletions src/contexts/ChordContext.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Dispatch, SetStateAction, createContext, useCallback, useEffect, useState } from 'react';
import { DEFAULT_NUMBER_OF_CHORD } from '../config/constants';
import { getListOfRandomChords, getRandomNoteFromCaged, isValidChordCountList } from '../services';
import { CagedType, Chord, ChordType, chordTypes as allChordTypes } from '../config';
import { Caged, Chord, ChordType, chordTypes as allChordTypes } from '../config';
import { useSpeedContext } from '../hooks';

interface ChordSettingsContextProps {
Expand All @@ -10,7 +10,7 @@ interface ChordSettingsContextProps {
setAvailableChordTypes: Dispatch<SetStateAction<ChordType[]>>;
numberOfChordDisplayed: number;
isShapeVisible: boolean;
cagedPosition: CagedType;
cagedPosition: Caged;
getRandomChordsOnClick: () => void;
changeNumberOfChordDisplayed: (step: number) => void;
toggleShapeVisible: () => void;
Expand All @@ -23,7 +23,7 @@ export const ChordSettingsContextProvider = ({ children }: { children: React.Rea
const [chords, setChords] = useState<Chord[]>(getListOfRandomChords(DEFAULT_NUMBER_OF_CHORD, availableChordTypes));
const [numberOfChordDisplayed, setNumberOfChordDisplayed] = useState(DEFAULT_NUMBER_OF_CHORD);
const [isShapeVisible, setIsShapeVisible] = useState(false);
const [cagedPosition, setCagedPosition] = useState<CagedType>(getRandomNoteFromCaged());
const [cagedPosition, setCagedPosition] = useState<Caged>(getRandomNoteFromCaged());

const { speed, secondsElapsed, resetSecondsElapsed } = useSpeedContext();

Expand Down
4 changes: 2 additions & 2 deletions src/services/noteService.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Note, notes, cagedNotes } from "../config";
import { CagedType } from "../config/Caged";
import { Caged } from "../config/Caged";
import { NOTES_LIST_MAX, NOTES_LIST_MIN } from "../config/constants";
import { getRandomItemFrom } from "../utils/random";
import { shuffle } from "../utils/shuffle";
Expand All @@ -18,6 +18,6 @@ export const getRandomNote = (): Note => {
return getRandomItemFrom(notes);
};

export const getRandomNoteFromCaged = (): CagedType => {
export const getRandomNoteFromCaged = (): Caged => {
return getRandomItemFrom(cagedNotes);
}
4 changes: 2 additions & 2 deletions src/utils/random.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export const getRandomItemFrom = <T>(arrary: T[]): T => {
return arrary[Math.floor(Math.random()*arrary.length)];
export const getRandomItemFrom = <T>(array: readonly T[]): T => {
return array[Math.floor(Math.random() * array.length)];
};
4 changes: 2 additions & 2 deletions src/utils/shuffle.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Note } from "../config/Notes";
import { Note } from '../config/Notes';

export const shuffle = (array: Note[]): Note[] => {
export const shuffle = (array: readonly Note[]): Note[] => {
const arrayCopy = [...array];

return arrayCopy.sort(() => Math.random() - 0.5);
Expand Down

0 comments on commit 0e82a1f

Please sign in to comment.