tags.js 709 B

12345678910111213141516171819202122232425
  1. import {
  2. HASHTAG_FETCH_SUCCESS,
  3. HASHTAG_FOLLOW_REQUEST,
  4. HASHTAG_FOLLOW_FAIL,
  5. HASHTAG_UNFOLLOW_REQUEST,
  6. HASHTAG_UNFOLLOW_FAIL,
  7. } from 'mastodon/actions/tags';
  8. import { Map as ImmutableMap, fromJS } from 'immutable';
  9. const initialState = ImmutableMap();
  10. export default function tags(state = initialState, action) {
  11. switch(action.type) {
  12. case HASHTAG_FETCH_SUCCESS:
  13. return state.set(action.name, fromJS(action.tag));
  14. case HASHTAG_FOLLOW_REQUEST:
  15. case HASHTAG_UNFOLLOW_FAIL:
  16. return state.setIn([action.name, 'following'], true);
  17. case HASHTAG_FOLLOW_FAIL:
  18. case HASHTAG_UNFOLLOW_REQUEST:
  19. return state.setIn([action.name, 'following'], false);
  20. default:
  21. return state;
  22. }
  23. };