bigbuffet-rw/app/soapbox/reducers/scheduled_statuses.js

37 lines
1.2 KiB
JavaScript
Raw Normal View History

2021-06-27 12:58:40 -07:00
import { STATUS_CREATE_SUCCESS } from 'soapbox/actions/statuses';
import {
SCHEDULED_STATUSES_FETCH_SUCCESS,
SCHEDULED_STATUS_CANCEL_REQUEST,
SCHEDULED_STATUS_CANCEL_SUCCESS,
} from 'soapbox/actions/scheduled_statuses';
2021-06-27 12:58:40 -07:00
import { STATUS_IMPORT, STATUSES_IMPORT } from '../actions/importer';
2021-06-27 11:59:10 -07:00
import { Map as ImmutableMap, fromJS } from 'immutable';
2021-06-27 12:58:40 -07:00
const importStatus = (state, status) => {
if (!status.scheduled_at) return state;
return state.set(status.id, fromJS(status));
};
2021-06-27 11:59:10 -07:00
const importStatuses = (state, statuses) =>
state.withMutations(mutable => statuses.forEach(status => importStatus(mutable, status)));
const deleteStatus = (state, id) => state.delete(id);
2021-06-27 11:59:10 -07:00
const initialState = ImmutableMap();
export default function statuses(state = initialState, action) {
switch(action.type) {
case STATUS_IMPORT:
2021-06-27 12:58:40 -07:00
case STATUS_CREATE_SUCCESS:
2021-06-27 11:59:10 -07:00
return importStatus(state, action.status);
case STATUSES_IMPORT:
case SCHEDULED_STATUSES_FETCH_SUCCESS:
2021-06-27 11:59:10 -07:00
return importStatuses(state, action.statuses);
case SCHEDULED_STATUS_CANCEL_REQUEST:
case SCHEDULED_STATUS_CANCEL_SUCCESS:
return deleteStatus(state, action.id);
2021-06-27 11:59:10 -07:00
default:
return state;
}
2021-08-03 12:22:51 -07:00
}