history.js 1.0 KB

12345678910111213141516171819202122232425262728
  1. import { HISTORY_FETCH_REQUEST, HISTORY_FETCH_SUCCESS, HISTORY_FETCH_FAIL } from 'mastodon/actions/history';
  2. import { Map as ImmutableMap, List as ImmutableList, fromJS } from 'immutable';
  3. const initialHistory = ImmutableMap({
  4. loading: false,
  5. items: ImmutableList(),
  6. });
  7. const initialState = ImmutableMap();
  8. export default function history(state = initialState, action) {
  9. switch(action.type) {
  10. case HISTORY_FETCH_REQUEST:
  11. return state.update(action.statusId, initialHistory, history => history.withMutations(map => {
  12. map.set('loading', true);
  13. map.set('items', ImmutableList());
  14. }));
  15. case HISTORY_FETCH_SUCCESS:
  16. return state.update(action.statusId, initialHistory, history => history.withMutations(map => {
  17. map.set('loading', false);
  18. map.set('items', fromJS(action.history.map((x, i) => ({ ...x, account: x.account.id, original: i === 0 })).reverse()));
  19. }));
  20. case HISTORY_FETCH_FAIL:
  21. return state.update(action.statusId, initialHistory, history => history.set('loading', false));
  22. default:
  23. return state;
  24. }
  25. }