@bigfishtv/cockpit
Version:
45 lines (38 loc) • 1.15 kB
JavaScript
/**
* @module Reducers/imageFilterPresets
*/
import {
IMAGE_FILTER_PRESET_ADDED,
IMAGE_FILTER_PRESETS_ADDED,
IMAGE_FILTER_PRESET_REMOVED,
IMAGE_FILTER_PRESETS_REMOVED,
} from '../constants/ActionTypes'
const initialState = []
/**
* Reducer for managing image editing filter presets
* @param {Object} state
* @param {Object} action
* @param {String} action.type - const action type from constants/ActionTypes
* @return {Object} returns state
*/
export default function(state = initialState, action) {
switch (action.type) {
case IMAGE_FILTER_PRESET_ADDED:
if (!state.filter(preset => preset.title == action.preset.title).length) {
state.push(action.preset)
}
return state
case IMAGE_FILTER_PRESETS_ADDED:
for (let preset of action.presets) {
if (!state.filter(_preset => _preset.title == preset.title).length) {
state.push(preset)
}
}
return state
case IMAGE_FILTER_PRESET_REMOVED:
return state.filter(preset => preset.title != action.presetTitle)
case IMAGE_FILTER_PRESETS_REMOVED:
return state.filter(preset => action.presetTitles.indexOf(preset.title) < 0)
}
return state
}