The code powering m.abunchtell.com https://m.abunchtell.com
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

38 lines
1.3 KiB

  1. import {
  2. SUGGESTIONS_FETCH_REQUEST,
  3. SUGGESTIONS_FETCH_SUCCESS,
  4. SUGGESTIONS_FETCH_FAIL,
  5. SUGGESTIONS_DISMISS,
  6. } from '../actions/suggestions';
  7. import { ACCOUNT_BLOCK_SUCCESS, ACCOUNT_MUTE_SUCCESS } from 'mastodon/actions/accounts';
  8. import { DOMAIN_BLOCK_SUCCESS } from 'mastodon/actions/domain_blocks';
  9. import { Map as ImmutableMap, List as ImmutableList, fromJS } from 'immutable';
  10. const initialState = ImmutableMap({
  11. items: ImmutableList(),
  12. isLoading: false,
  13. });
  14. export default function suggestionsReducer(state = initialState, action) {
  15. switch(action.type) {
  16. case SUGGESTIONS_FETCH_REQUEST:
  17. return state.set('isLoading', true);
  18. case SUGGESTIONS_FETCH_SUCCESS:
  19. return state.withMutations(map => {
  20. map.set('items', fromJS(action.accounts.map(x => x.id)));
  21. map.set('isLoading', false);
  22. });
  23. case SUGGESTIONS_FETCH_FAIL:
  24. return state.set('isLoading', false);
  25. case SUGGESTIONS_DISMISS:
  26. return state.update('items', list => list.filterNot(id => id === action.id));
  27. case ACCOUNT_BLOCK_SUCCESS:
  28. case ACCOUNT_MUTE_SUCCESS:
  29. return state.update('items', list => list.filterNot(id => id === action.relationship.id));
  30. case DOMAIN_BLOCK_SUCCESS:
  31. return state.update('items', list => list.filterNot(id => action.accounts.includes(id)));
  32. default:
  33. return state;
  34. }
  35. };