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.

19 lines
642 B

  1. import { POLL_VOTE_SUCCESS, POLL_FETCH_SUCCESS } from 'mastodon/actions/polls';
  2. import { POLLS_IMPORT } from 'mastodon/actions/importer';
  3. import { Map as ImmutableMap, fromJS } from 'immutable';
  4. const importPolls = (state, polls) => state.withMutations(map => polls.forEach(poll => map.set(poll.id, fromJS(poll))));
  5. const initialState = ImmutableMap();
  6. export default function polls(state = initialState, action) {
  7. switch(action.type) {
  8. case POLLS_IMPORT:
  9. return importPolls(state, action.polls);
  10. case POLL_VOTE_SUCCESS:
  11. case POLL_FETCH_SUCCESS:
  12. return importPolls(state, [action.poll]);
  13. default:
  14. return state;
  15. }
  16. }