~cytrogen/masto-fe

ref: f8dc013b0d81d5d463c086e291ce99ab1d796a9d masto-fe/app/javascript/mastodon/reducers/server.js -rw-r--r-- 1.3 KiB
f8dc013b — Cytrogen [feature] Add language selector to local settings 5 days 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
import { Map as ImmutableMap, List as ImmutableList, fromJS } from "immutable";

import {
  SERVER_FETCH_REQUEST,
  SERVER_FETCH_SUCCESS,
  SERVER_FETCH_FAIL,
  SERVER_DOMAIN_BLOCKS_FETCH_REQUEST,
  SERVER_DOMAIN_BLOCKS_FETCH_SUCCESS,
  SERVER_DOMAIN_BLOCKS_FETCH_FAIL,
} from "mastodon/actions/server";

const initialState = ImmutableMap({
  server: ImmutableMap({
    isLoading: false,
  }),

  domainBlocks: ImmutableMap({
    isLoading: false,
    isAvailable: true,
    items: ImmutableList(),
  }),
});

export default function server(state = initialState, action) {
  switch (action.type) {
    case SERVER_FETCH_REQUEST:
      return state.setIn(["server", "isLoading"], true);
    case SERVER_FETCH_SUCCESS:
      return state.set("server", fromJS(action.server)).setIn(["server", "isLoading"], false);
    case SERVER_FETCH_FAIL:
      return state.setIn(["server", "isLoading"], false);
    case SERVER_DOMAIN_BLOCKS_FETCH_REQUEST:
      return state.setIn(["domainBlocks", "isLoading"], true);
    case SERVER_DOMAIN_BLOCKS_FETCH_SUCCESS:
      return state.setIn(["domainBlocks", "items"], fromJS(action.blocks)).setIn(["domainBlocks", "isLoading"], false).setIn(["domainBlocks", "isAvailable"], action.isAvailable);
    case SERVER_DOMAIN_BLOCKS_FETCH_FAIL:
      return state.setIn(["domainBlocks", "isLoading"], false);
    default:
      return state;
  }
}