2022-03-16 19:52:20 -07:00
|
|
|
import { Map as ImmutableMap } from 'immutable';
|
2022-01-10 14:25:06 -08:00
|
|
|
|
2022-01-10 14:01:24 -08:00
|
|
|
import { POLLS_IMPORT } from 'soapbox/actions/importer';
|
2022-03-10 13:32:01 -08:00
|
|
|
import { normalizeStatus } from 'soapbox/normalizers/status';
|
2020-03-27 13:59:38 -07:00
|
|
|
|
2022-03-10 13:32:01 -08:00
|
|
|
// HOTFIX: Convert the poll into a fake status to normalize it...
|
|
|
|
// TODO: get rid of POLLS_IMPORT and use STATUS_IMPORT here.
|
|
|
|
const normalizePoll = poll => {
|
2022-03-16 19:52:20 -07:00
|
|
|
const status = { poll };
|
2022-03-10 13:32:01 -08:00
|
|
|
return normalizeStatus(status).poll;
|
|
|
|
};
|
|
|
|
|
|
|
|
const importPolls = (state, polls) => {
|
|
|
|
return state.withMutations(map => {
|
|
|
|
return polls.forEach(poll => map.set(poll.id, normalizePoll(poll)));
|
|
|
|
});
|
|
|
|
};
|
2020-03-27 13:59:38 -07:00
|
|
|
|
|
|
|
const initialState = ImmutableMap();
|
|
|
|
|
|
|
|
export default function polls(state = initialState, action) {
|
|
|
|
switch(action.type) {
|
|
|
|
case POLLS_IMPORT:
|
|
|
|
return importPolls(state, action.polls);
|
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
}
|