state debug, functions and status in state
parent
5665eb4955
commit
dff64780f5
|
|
@ -31,4 +31,6 @@ export type Found = {
|
|||
export enum BtnColor {
|
||||
blue = "primary",
|
||||
green = "success"
|
||||
}
|
||||
}
|
||||
|
||||
export enum Status {params, plaing, plaied, showlist}
|
||||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue