Split out userInput reducer

This commit is contained in:
Jordan Eldredge 2018-04-02 16:46:41 -07:00
parent 6d7f85046b
commit 97fa59123c
3 changed files with 38 additions and 33 deletions

View file

@ -2,15 +2,9 @@ import { combineReducers } from "redux";
import { BANDS } from "../constants";
import {
SET_BAND_VALUE,
SET_FOCUS,
SET_BAND_FOCUS,
SET_SCRUB_POSITION,
SET_EQ_AUTO,
SET_EQ_ON,
SET_EQ_OFF,
UNSET_FOCUS,
SET_USER_MESSAGE,
UNSET_USER_MESSAGE,
SET_AVAILABLE_SKINS,
NETWORK_CONNECTED,
NETWORK_DISCONNECTED
@ -20,32 +14,7 @@ import playlist from "./playlist";
import windows from "./windows";
import media from "./media";
import display from "./display";
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;
}
};
import userInput from "./userInput";
const defaultSettingsState = {
availableSkins: []

36
js/reducers/userInput.js Normal file
View file

@ -0,0 +1,36 @@
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

@ -1,5 +1,5 @@
import { SET_FOCUS, SET_SCRUB_POSITION, UNSET_FOCUS } from "../actionTypes";
import { userInput } from "./";
import userInput from "./userInput";
describe("userInput reducer", () => {
const state = userInput(undefined, { type: "@@INIT" });