canape/frontend/js/reducers/torrents.js
Grégoire Delattre bcadc48d5a Launch prettier with the --fix option
They've changed their default settings, this changes a lot of stuff in
our code base.
2020-04-01 17:55:34 +02:00

31 lines
785 B
JavaScript

import { Map, List, fromJS } from "immutable";
const defaultState = Map({
fetching: false,
searching: false,
torrents: List(),
searchResults: List(),
});
const handlers = {
TORRENTS_FETCH_PENDING: (state) => state.set("fetching", true),
TORRENTS_FETCH_FULFILLED: (state, action) =>
state.merge(
fromJS({
fetching: false,
torrents: action.payload.response.data,
})
),
TORRENTS_SEARCH_PENDING: (state) => state.set("searching", true),
TORRENTS_SEARCH_FULFILLED: (state, action) =>
state.merge(
fromJS({
searching: false,
searchResults: action.payload.response.data,
})
),
};
export default (state = defaultState, action) =>
handlers[action.type] ? handlers[action.type](state, action) : state;