mirror of
https://github.com/captbaritone/webamp.git
synced 2026-07-23 18:17:38 +00:00
Convert UserInput reducer to TypeScript
This commit is contained in:
parent
b2359c6b5a
commit
bd1b4709d4
2 changed files with 23 additions and 36 deletions
|
|
@ -1,36 +0,0 @@
|
|||
import {
|
||||
SET_FOCUS,
|
||||
SET_BAND_FOCUS,
|
||||
SET_SCRUB_POSITION,
|
||||
UNSET_FOCUS,
|
||||
SET_USER_MESSAGE,
|
||||
UNSET_USER_MESSAGE
|
||||
} from "../actionTypes";
|
||||
|
||||
const defaultUserInput = {
|
||||
focus: null,
|
||||
bandFocused: null,
|
||||
scrubPosition: 0,
|
||||
userMessage: null
|
||||
};
|
||||
|
||||
export const userInput = (state = defaultUserInput, action) => {
|
||||
switch (action.type) {
|
||||
case SET_FOCUS:
|
||||
return { ...state, focus: action.input, bandFocused: null };
|
||||
case SET_BAND_FOCUS:
|
||||
return { ...state, focus: action.input, bandFocused: action.bandFocused };
|
||||
case UNSET_FOCUS:
|
||||
return { ...state, focus: null, bandFocused: null };
|
||||
case SET_SCRUB_POSITION:
|
||||
return { ...state, scrubPosition: action.position };
|
||||
case SET_USER_MESSAGE:
|
||||
return { ...state, userMessage: action.message };
|
||||
case UNSET_USER_MESSAGE:
|
||||
return { ...state, userMessage: null };
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
};
|
||||
|
||||
export default userInput;
|
||||
23
js/types.ts
23
js/types.ts
|
|
@ -55,6 +55,22 @@ export type Action =
|
|||
type: "TOGGLE_REPEAT";
|
||||
} | {
|
||||
type: "TOGGLE_SHUFFLE";
|
||||
} | {
|
||||
type: "SET_FOCUS";
|
||||
input: string;
|
||||
} | {
|
||||
type: "SET_BAND_FOCUS";
|
||||
input: string;
|
||||
} | {
|
||||
type: "UNSET_FOCUS";
|
||||
} | {
|
||||
type: "SET_SCRUB_POSITION";
|
||||
position: number;
|
||||
} | {
|
||||
type: "SET_USER_MESSAGE";
|
||||
message: string;
|
||||
} | {
|
||||
type: "UNSET_USER_MESSAGE";
|
||||
};
|
||||
|
||||
export interface SettingsState {
|
||||
|
|
@ -78,3 +94,10 @@ export interface MediaState {
|
|||
repeat: boolean;
|
||||
status: string | null; // TODO: Convert this to an enum
|
||||
}
|
||||
|
||||
export interface UserInputState {
|
||||
focus: string | null; // TODO: Convert this to an enum?
|
||||
bandFocused: null;
|
||||
scrubPosition: number;
|
||||
userMessage: string | null;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue