|
|
@ -1,6 +1,6 @@
|
|
|
|
import { CONTEXT_FETCH_SUCCESS } from '../actions/statuses';
|
|
|
|
import { CONTEXT_FETCH_SUCCESS } from '../actions/statuses';
|
|
|
|
import { TIMELINE_DELETE } from '../actions/timelines';
|
|
|
|
import { TIMELINE_DELETE, TIMELINE_CONTEXT_UPDATE } from '../actions/timelines';
|
|
|
|
import { Map as ImmutableMap, List as ImmutableList, fromJS } from 'immutable';
|
|
|
|
import { Map as ImmutableMap, List as ImmutableList } from 'immutable';
|
|
|
|
|
|
|
|
|
|
|
|
const initialState = ImmutableMap({
|
|
|
|
const initialState = ImmutableMap({
|
|
|
|
ancestors: ImmutableMap(),
|
|
|
|
ancestors: ImmutableMap(),
|
|
|
@ -8,8 +8,8 @@ const initialState = ImmutableMap({
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
const normalizeContext = (state, id, ancestors, descendants) => {
|
|
|
|
const normalizeContext = (state, id, ancestors, descendants) => {
|
|
|
|
const ancestorsIds = ancestors.map(ancestor => ancestor.get('id'));
|
|
|
|
const ancestorsIds = ImmutableList(ancestors.map(ancestor => ancestor.id));
|
|
|
|
const descendantsIds = descendants.map(descendant => descendant.get('id'));
|
|
|
|
const descendantsIds = ImmutableList(descendants.map(descendant => descendant.id));
|
|
|
|
|
|
|
|
|
|
|
|
return state.withMutations(map => {
|
|
|
|
return state.withMutations(map => {
|
|
|
|
map.setIn(['ancestors', id], ancestorsIds);
|
|
|
|
map.setIn(['ancestors', id], ancestorsIds);
|
|
|
@ -31,12 +31,24 @@ const deleteFromContexts = (state, id) => {
|
|
|
|
return state;
|
|
|
|
return state;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const updateContext = (state, status, references) => {
|
|
|
|
|
|
|
|
return state.update('descendants', map => {
|
|
|
|
|
|
|
|
references.forEach(parentId => {
|
|
|
|
|
|
|
|
map = map.update(parentId, ImmutableList(), list => list.push(status.id));
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return map;
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
export default function contexts(state = initialState, action) {
|
|
|
|
export default function contexts(state = initialState, action) {
|
|
|
|
switch(action.type) {
|
|
|
|
switch(action.type) {
|
|
|
|
case CONTEXT_FETCH_SUCCESS:
|
|
|
|
case CONTEXT_FETCH_SUCCESS:
|
|
|
|
return normalizeContext(state, action.id, fromJS(action.ancestors), fromJS(action.descendants));
|
|
|
|
return normalizeContext(state, action.id, action.ancestors, action.descendants);
|
|
|
|
case TIMELINE_DELETE:
|
|
|
|
case TIMELINE_DELETE:
|
|
|
|
return deleteFromContexts(state, action.id);
|
|
|
|
return deleteFromContexts(state, action.id);
|
|
|
|
|
|
|
|
case TIMELINE_CONTEXT_UPDATE:
|
|
|
|
|
|
|
|
return updateContext(state, action.status, action.references);
|
|
|
|
default:
|
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
}
|
|
|
|