mirador
Version:
An open-source, web-based 'multi-up' viewer that supports zoom-pan-rotate functionality, ability to display/compare simple images, and images with annotations.
52 lines (49 loc) • 1.36 kB
JavaScript
import without from 'lodash/without';
import ActionTypes from '../actions/action-types';
const defaultState = { items: [] };
/**
* errorsReducer
*/
export const errorsReducer = (state = defaultState, action) => {
let ret;
switch (action.type) {
case ActionTypes.ADD_ERROR:
return {
...state,
[action.id]: { id: action.id, message: action.message },
items: [...state.items, action.id],
};
case ActionTypes.RECEIVE_INFO_RESPONSE_FAILURE:
return {
...state,
[action.infoId]: {
id: action.infoId,
message: action.error,
},
items: [...state.items, action.infoId],
};
case ActionTypes.RECEIVE_SEARCH_FAILURE:
return {
...state,
[action.searchId]: {
id: action.searchId,
message: action.error,
},
items: [...state.items, action.searchId],
};
case ActionTypes.REMOVE_ERROR:
ret = Object.keys(state).reduce((object, key) => {
if (key !== action.id) {
// eslint-disable-next-line no-param-reassign
object[key] = state[key];
}
return object;
}, {});
ret.items = without(ret.items, action.id);
return ret;
case ActionTypes.IMPORT_MIRADOR_STATE:
return defaultState;
default:
return state;
}
};