~cytrogen/masto-fe

ref: 8a2677649214ff96a63267ef5294256e814f46b1 masto-fe/app/javascript/mastodon/reducers/trends.js -rw-r--r-- 1.3 KiB
8a267764 — Zoë Bijl [docs] Add changelog based on “Keep a Changelog” (#80) 6 months ago
                                                                                
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import { Map as ImmutableMap, List as ImmutableList, fromJS } from 'immutable';

import {
  TRENDS_TAGS_FETCH_REQUEST,
  TRENDS_TAGS_FETCH_SUCCESS,
  TRENDS_TAGS_FETCH_FAIL,
  TRENDS_LINKS_FETCH_REQUEST,
  TRENDS_LINKS_FETCH_SUCCESS,
  TRENDS_LINKS_FETCH_FAIL,
} from 'mastodon/actions/trends';

const initialState = ImmutableMap({
  tags: ImmutableMap({
    items: ImmutableList(),
    isLoading: false,
  }),

  links: ImmutableMap({
    items: ImmutableList(),
    isLoading: false,
  }),
});

export default function trendsReducer(state = initialState, action) {
  switch(action.type) {
  case TRENDS_TAGS_FETCH_REQUEST:
    return state.setIn(['tags', 'isLoading'], true);
  case TRENDS_TAGS_FETCH_SUCCESS:
    return state.withMutations(map => {
      map.setIn(['tags', 'items'], fromJS(action.trends));
      map.setIn(['tags', 'isLoading'], false);
    });
  case TRENDS_TAGS_FETCH_FAIL:
    return state.setIn(['tags', 'isLoading'], false);
  case TRENDS_LINKS_FETCH_REQUEST:
    return state.setIn(['links', 'isLoading'], true);
  case TRENDS_LINKS_FETCH_SUCCESS:
    return state.withMutations(map => {
      map.setIn(['links', 'items'], fromJS(action.trends));
      map.setIn(['links', 'isLoading'], false);
    });
  case TRENDS_LINKS_FETCH_FAIL:
    return state.setIn(['links', 'isLoading'], false);
  default:
    return state;
  }
}