about summary refs log tree commit diff
path: root/app/javascript/flavours/glitch/reducers/tags.js
blob: 266b21177f157cab5fb2274765a0f92c30f19105 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import {
  HASHTAG_FETCH_SUCCESS,
  HASHTAG_FOLLOW_REQUEST,
  HASHTAG_FOLLOW_FAIL,
  HASHTAG_UNFOLLOW_REQUEST,
  HASHTAG_UNFOLLOW_FAIL,
} from 'flavours/glitch/actions/tags';
import { Map as ImmutableMap, fromJS } from 'immutable';

const initialState = ImmutableMap();

export default function tags(state = initialState, action) {
  switch(action.type) {
  case HASHTAG_FETCH_SUCCESS:
    return state.set(action.name, fromJS(action.tag));
  case HASHTAG_FOLLOW_REQUEST:
  case HASHTAG_UNFOLLOW_FAIL:
    return state.setIn([action.name, 'following'], true);
  case HASHTAG_FOLLOW_FAIL:
  case HASHTAG_UNFOLLOW_REQUEST:
    return state.setIn([action.name, 'following'], false);
  default:
    return state;
  }
};