From dff64780f5b5a8b0b1253a13e792a8ac15c6bb4f Mon Sep 17 00:00:00 2001 From: Yuriy Evdokimov Date: Fri, 13 Oct 2023 23:54:52 +0500 Subject: [PATCH] state debug, functions and status in state --- src/Types.ts | 4 +++- src/reducer.ts | 18 +++++++++--------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/Types.ts b/src/Types.ts index dec1a40..cef17a3 100644 --- a/src/Types.ts +++ b/src/Types.ts @@ -31,4 +31,6 @@ export type Found = { export enum BtnColor { blue = "primary", green = "success" -} \ No newline at end of file +} + +export enum Status {params, plaing, plaied, showlist} \ No newline at end of file diff --git a/src/reducer.ts b/src/reducer.ts index c0171d5..e6cb5b3 100644 --- a/src/reducer.ts +++ b/src/reducer.ts @@ -1,10 +1,10 @@ import { finales, initials, tones } from "./data"; import { IState } from "./store"; -import { SylPart, Syllable, Tone } from "./types"; +import { SylPart, Syllable, Tone, Status } from "./types"; import { GetSyllablesByInitAndFin, getRandomArray, toggle } from "./utils"; export enum ActionType { - toggleOne, toggleAll, refreshPlayList, setPause, setCount + toggleOne, toggleAll, refreshPlayList, setPause, setCount, setStatus } export enum ToggleType { init, fin } @@ -22,7 +22,7 @@ const ProceedAllInitials = (state: IState):{ allInitiales:boolean, initiales: Sy initiales: toggled, foundSyllables: foundSyllables, foundTones: foundTones - } + } } const ProceedAllFinales = (state: IState):{ allfinales:boolean, finales: SylPart[], foundSyllables:Syllable[], foundTones: Tone[]} => @@ -35,10 +35,9 @@ const ProceedAllFinales = (state: IState):{ allfinales:boolean, finales: SylPart finales: toggled, foundSyllables: foundSyllables, foundTones: foundTones - } + } } - const ProceedInitiale = (state: IState, index: SylPart):{ initiales: SylPart[], foundSyllables:Syllable[], foundTones: Tone[]} => { let toggled = toggle(state.initiales,index) @@ -48,7 +47,7 @@ const ProceedInitiale = (state: IState, index: SylPart):{ initiales: SylPart[], initiales: toggled, foundSyllables: foundSyllables, foundTones: foundTones - } + } } const ProceedFinale = (state: IState, index: SylPart):{ finales: SylPart[], foundSyllables:Syllable[], foundTones: Tone[]} => @@ -60,7 +59,7 @@ const ProceedFinale = (state: IState, index: SylPart):{ finales: SylPart[], foun finales: toggled, foundSyllables: foundSyllables, foundTones: foundTones - } + } } export const reducer = (state:IState, action:Action):IState => { @@ -68,6 +67,7 @@ export const reducer = (state:IState, action:Action):IState => { case ActionType.setPause: return { ...state, sylPause: action.payload as number } case ActionType.setCount: return { ...state, sylCount: action.payload as number } case ActionType.refreshPlayList: return { ...state, randomTones: getRandomArray( state.foundTones, state.sylCount! ) } + case ActionType.setStatus: return { ...state, status: action.payload as Status} case ActionType.toggleAll: { if (action.payload as ToggleType === ToggleType.init) return { ...state, ...ProceedAllInitials(state) } @@ -76,9 +76,9 @@ export const reducer = (state:IState, action:Action):IState => { } case ActionType.toggleOne: { - if ( (action.payload as TogglePayload).type === ToggleType.init) + if ( (action.payload as TogglePayload).type === ToggleType.init) return { ...state, ...ProceedInitiale(state, (action.payload as TogglePayload).part ) } - if ( (action.payload as TogglePayload).type === ToggleType.fin) + if ( (action.payload as TogglePayload).type === ToggleType.fin) return { ...state, ...ProceedFinale(state, (action.payload as TogglePayload).part ) } return state }