You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
1.9 KiB
61 lines
1.9 KiB
8 years ago
|
import {
|
||
|
REPORT_INIT,
|
||
|
REPORT_SUBMIT_REQUEST,
|
||
|
REPORT_SUBMIT_SUCCESS,
|
||
|
REPORT_SUBMIT_FAIL,
|
||
|
REPORT_CANCEL,
|
||
8 years ago
|
REPORT_STATUS_TOGGLE,
|
||
8 years ago
|
REPORT_COMMENT_CHANGE,
|
||
7 years ago
|
} from 'flavours/glitch/actions/reports';
|
||
8 years ago
|
import { Map as ImmutableMap, Set as ImmutableSet } from 'immutable';
|
||
8 years ago
|
|
||
8 years ago
|
const initialState = ImmutableMap({
|
||
|
new: ImmutableMap({
|
||
8 years ago
|
isSubmitting: false,
|
||
|
account_id: null,
|
||
8 years ago
|
status_ids: ImmutableSet(),
|
||
8 years ago
|
comment: '',
|
||
|
}),
|
||
8 years ago
|
});
|
||
|
|
||
|
export default function reports(state = initialState, action) {
|
||
|
switch(action.type) {
|
||
|
case REPORT_INIT:
|
||
|
return state.withMutations(map => {
|
||
|
map.setIn(['new', 'isSubmitting'], false);
|
||
|
map.setIn(['new', 'account_id'], action.account.get('id'));
|
||
|
|
||
|
if (state.getIn(['new', 'account_id']) !== action.account.get('id')) {
|
||
8 years ago
|
map.setIn(['new', 'status_ids'], action.status ? ImmutableSet([action.status.getIn(['reblog', 'id'], action.status.get('id'))]) : ImmutableSet());
|
||
8 years ago
|
map.setIn(['new', 'comment'], '');
|
||
7 years ago
|
} else if (action.status) {
|
||
8 years ago
|
map.updateIn(['new', 'status_ids'], ImmutableSet(), set => set.add(action.status.getIn(['reblog', 'id'], action.status.get('id'))));
|
||
8 years ago
|
}
|
||
|
});
|
||
|
case REPORT_STATUS_TOGGLE:
|
||
8 years ago
|
return state.updateIn(['new', 'status_ids'], ImmutableSet(), set => {
|
||
8 years ago
|
if (action.checked) {
|
||
|
return set.add(action.statusId);
|
||
|
}
|
||
|
|
||
|
return set.remove(action.statusId);
|
||
|
});
|
||
8 years ago
|
case REPORT_COMMENT_CHANGE:
|
||
|
return state.setIn(['new', 'comment'], action.comment);
|
||
8 years ago
|
case REPORT_SUBMIT_REQUEST:
|
||
|
return state.setIn(['new', 'isSubmitting'], true);
|
||
|
case REPORT_SUBMIT_FAIL:
|
||
|
return state.setIn(['new', 'isSubmitting'], false);
|
||
|
case REPORT_CANCEL:
|
||
|
case REPORT_SUBMIT_SUCCESS:
|
||
|
return state.withMutations(map => {
|
||
|
map.setIn(['new', 'account_id'], null);
|
||
8 years ago
|
map.setIn(['new', 'status_ids'], ImmutableSet());
|
||
8 years ago
|
map.setIn(['new', 'comment'], '');
|
||
|
map.setIn(['new', 'isSubmitting'], false);
|
||
|
});
|
||
|
default:
|
||
|
return state;
|
||
|
}
|
||
|
};
|