canape/frontend/js/reducers/torrents.js

31 lines
777 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;