Convert UserInput reducer to TypeScript

This commit is contained in:
Jordan Eldredge 2018-09-04 22:01:27 -07:00
parent b2359c6b5a
commit bd1b4709d4
2 changed files with 23 additions and 36 deletions

View file

@ -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;

View file

@ -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;
}