-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Port Pronunciations to use redux-toolkit (#2753)
- Loading branch information
1 parent
fa59f6f
commit 6b800c0
Showing
7 changed files
with
79 additions
and
76 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
29 changes: 14 additions & 15 deletions
29
src/components/Pronunciations/Redux/PronunciationsActions.ts
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,22 +1,21 @@ | ||
import { Action, PayloadAction } from "@reduxjs/toolkit"; | ||
|
||
import { | ||
PronunciationsAction, | ||
PronunciationsStatus, | ||
} from "components/Pronunciations/Redux/PronunciationsReduxTypes"; | ||
resetAction, | ||
setPlayingAction, | ||
setRecordingAction, | ||
} from "components/Pronunciations/Redux/PronunciationsReducer"; | ||
|
||
// Action Creation Functions | ||
|
||
export function playing(payload: string): PronunciationsAction { | ||
return { | ||
type: PronunciationsStatus.Playing, | ||
payload, | ||
}; | ||
export function playing(fileName: string): PayloadAction { | ||
return setPlayingAction(fileName); | ||
} | ||
|
||
export function recording(payload: string): PronunciationsAction { | ||
return { | ||
type: PronunciationsStatus.Recording, | ||
payload, | ||
}; | ||
export function recording(wordId: string): PayloadAction { | ||
return setRecordingAction(wordId); | ||
} | ||
|
||
export function reset(): PronunciationsAction { | ||
return { type: PronunciationsStatus.Default }; | ||
export function resetPronunciations(): Action { | ||
return resetAction(); | ||
} |
47 changes: 27 additions & 20 deletions
47
src/components/Pronunciations/Redux/PronunciationsReducer.ts
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,25 +1,32 @@ | ||
import { createSlice } from "@reduxjs/toolkit"; | ||
|
||
import { | ||
defaultState, | ||
PronunciationsAction, | ||
PronunciationsStatus, | ||
PronunciationsState, | ||
} from "components/Pronunciations/Redux/PronunciationsReduxTypes"; | ||
import { StoreAction, StoreActionTypes } from "rootActions"; | ||
import { StoreActionTypes } from "rootActions"; | ||
|
||
const pronunciationsSlice = createSlice({ | ||
name: "pronunciationsState", | ||
initialState: defaultState, | ||
reducers: { | ||
resetAction: () => defaultState, | ||
setPlayingAction: (state, action) => { | ||
state.fileName = action.payload; | ||
state.status = PronunciationsStatus.Playing; | ||
state.wordId = ""; | ||
}, | ||
setRecordingAction: (state, action) => { | ||
state.fileName = ""; | ||
state.status = PronunciationsStatus.Recording; | ||
state.wordId = action.payload; | ||
}, | ||
}, | ||
extraReducers: (builder) => | ||
builder.addCase(StoreActionTypes.RESET, () => defaultState), | ||
}); | ||
|
||
export const { resetAction, setPlayingAction, setRecordingAction } = | ||
pronunciationsSlice.actions; | ||
|
||
export const pronunciationsReducer = ( | ||
state: PronunciationsState = defaultState, | ||
action: StoreAction | PronunciationsAction | ||
): PronunciationsState => { | ||
switch (action.type) { | ||
case PronunciationsStatus.Playing: | ||
return { ...defaultState, ...action }; | ||
case PronunciationsStatus.Recording: | ||
return { ...defaultState, ...action }; | ||
case PronunciationsStatus.Default: | ||
return defaultState; | ||
case StoreActionTypes.RESET: | ||
return defaultState; | ||
default: | ||
return state; | ||
} | ||
}; | ||
export default pronunciationsSlice.reducer; |
17 changes: 7 additions & 10 deletions
17
src/components/Pronunciations/Redux/PronunciationsReduxTypes.ts
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,20 +1,17 @@ | ||
export enum PronunciationsStatus { | ||
Default = "DEFAULT", | ||
Inactive = "INACTIVE", | ||
Playing = "PLAYING", | ||
Recording = "RECORDING", | ||
} | ||
|
||
export interface PronunciationsAction { | ||
type: PronunciationsStatus; | ||
payload?: string; | ||
} | ||
|
||
export interface PronunciationsState { | ||
type: PronunciationsStatus; | ||
payload: string; | ||
fileName: string; | ||
status: PronunciationsStatus; | ||
wordId: string; | ||
} | ||
|
||
export const defaultState: PronunciationsState = { | ||
type: PronunciationsStatus.Default, | ||
payload: "", | ||
fileName: "", | ||
status: PronunciationsStatus.Inactive, | ||
wordId: "", | ||
}; |
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