import { CONFIG_LOADED, CONFIG_LOAD_ERROR, CONFIG_UPDATED, CONFIG_SAVED, OBJECT_STARTED, OBJECT_PAUSED, OBJECT_STOPPED, OBJECT_STATUS_LOADED, FILE_UPLOADED, FILES_LOADED, FILE_DELETED, PARAMS_LOADED, PARAMS_LOAD_ERROR, PLAYERS_LOADED, PLAYERS_LOAD_ERROR } from '../actions/types'; const initialState = { config: undefined, params: [], files: [], players: [] }; export default function (state = initialState, action) { switch (action.type) { case CONFIG_LOADED: { return { ...state, config: action.config } } case CONFIG_UPDATED: { return { ...state, config: action.config } } case CONFIG_SAVED: { return { ...state, config: action.config } } case CONFIG_LOAD_ERROR: { return { ...state, configLoadError: action.error } } case OBJECT_STARTED: { return { ...state, status: action.status } } case OBJECT_PAUSED: { return { ...state, status: action.status } } case OBJECT_STOPPED: { return { ...state, status: action.status } } case OBJECT_STATUS_LOADED: { return { ...state, status: action.status }; } case FILE_UPLOADED: { let files = JSON.parse(JSON.stringify(state.files)); files.push({ key: action.file.name, name: action.file.name }); return { ...state, files: files }; } case FILES_LOADED: { let files = action.files.map((file) => { return { key: file.name, name: file.name } }); return { ...state, files: files }; } case FILE_DELETED: { let files = state.files.filter((file) => { return file.name !== action.fileName }); return { ...state, files: files }; } case PLAYERS_LOADED: { return { ...state, players: action.players }; } case PLAYERS_LOAD_ERROR: { return { ...state, players: [], playersLoadError: action.error }; } case PARAMS_LOADED: { return { ...state, params: action.params }; } case PARAMS_LOAD_ERROR: { return { ...state, paramsLoadError: action.error } } default: return state; } };