Add circle adder
This commit is contained in:
parent
df0b1a4632
commit
9c4577ab7c
8 changed files with 89 additions and 46 deletions
|
@ -1,47 +1,47 @@
|
|||
import { Map as ImmutableMap, List as ImmutableList } from 'immutable';
|
||||
|
||||
import {
|
||||
LIST_ADDER_RESET,
|
||||
LIST_ADDER_SETUP,
|
||||
LIST_ADDER_LISTS_FETCH_REQUEST,
|
||||
LIST_ADDER_LISTS_FETCH_SUCCESS,
|
||||
LIST_ADDER_LISTS_FETCH_FAIL,
|
||||
LIST_EDITOR_ADD_SUCCESS,
|
||||
LIST_EDITOR_REMOVE_SUCCESS,
|
||||
} from '../actions/lists';
|
||||
CIRCLE_ADDER_RESET,
|
||||
CIRCLE_ADDER_SETUP,
|
||||
CIRCLE_ADDER_CIRCLES_FETCH_REQUEST,
|
||||
CIRCLE_ADDER_CIRCLES_FETCH_SUCCESS,
|
||||
CIRCLE_ADDER_CIRCLES_FETCH_FAIL,
|
||||
CIRCLE_EDITOR_ADD_SUCCESS,
|
||||
CIRCLE_EDITOR_REMOVE_SUCCESS,
|
||||
} from '../actions/circles';
|
||||
|
||||
const initialState = ImmutableMap({
|
||||
accountId: null,
|
||||
|
||||
lists: ImmutableMap({
|
||||
circles: ImmutableMap({
|
||||
items: ImmutableList(),
|
||||
loaded: false,
|
||||
isLoading: false,
|
||||
}),
|
||||
});
|
||||
|
||||
export default function listAdderReducer(state = initialState, action) {
|
||||
export default function circleAdderReducer(state = initialState, action) {
|
||||
switch(action.type) {
|
||||
case LIST_ADDER_RESET:
|
||||
case CIRCLE_ADDER_RESET:
|
||||
return initialState;
|
||||
case LIST_ADDER_SETUP:
|
||||
case CIRCLE_ADDER_SETUP:
|
||||
return state.withMutations(map => {
|
||||
map.set('accountId', action.account.get('id'));
|
||||
});
|
||||
case LIST_ADDER_LISTS_FETCH_REQUEST:
|
||||
return state.setIn(['lists', 'isLoading'], true);
|
||||
case LIST_ADDER_LISTS_FETCH_FAIL:
|
||||
return state.setIn(['lists', 'isLoading'], false);
|
||||
case LIST_ADDER_LISTS_FETCH_SUCCESS:
|
||||
return state.update('lists', lists => lists.withMutations(map => {
|
||||
case CIRCLE_ADDER_CIRCLES_FETCH_REQUEST:
|
||||
return state.setIn(['circles', 'isLoading'], true);
|
||||
case CIRCLE_ADDER_CIRCLES_FETCH_FAIL:
|
||||
return state.setIn(['circles', 'isLoading'], false);
|
||||
case CIRCLE_ADDER_CIRCLES_FETCH_SUCCESS:
|
||||
return state.update('circles', circles => circles.withMutations(map => {
|
||||
map.set('isLoading', false);
|
||||
map.set('loaded', true);
|
||||
map.set('items', ImmutableList(action.lists.map(item => item.id)));
|
||||
map.set('items', ImmutableList(action.circles.map(item => item.id)));
|
||||
}));
|
||||
case LIST_EDITOR_ADD_SUCCESS:
|
||||
return state.updateIn(['lists', 'items'], list => list.unshift(action.listId));
|
||||
case LIST_EDITOR_REMOVE_SUCCESS:
|
||||
return state.updateIn(['lists', 'items'], list => list.filterNot(item => item === action.listId));
|
||||
case CIRCLE_EDITOR_ADD_SUCCESS:
|
||||
return state.updateIn(['circles', 'items'], circle => circle.unshift(action.circleId));
|
||||
case CIRCLE_EDITOR_REMOVE_SUCCESS:
|
||||
return state.updateIn(['circles', 'items'], circle => circle.filterNot(item => item === action.circleId));
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue