canape/frontend/js/reducers/torrents.js
Grégoire Delattre 4b26080193
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing
Update redux state management
Use immer with native javascript objects instead of immutablejs.
2020-04-07 18:22:26 +02:00

35 lines
753 B
JavaScript

import { produce } from "immer";
const defaultState = {
fetching: false,
searching: false,
torrents: [],
searchResults: [],
};
export default (state = defaultState, action) =>
produce(state, (draft) => {
switch (action.type) {
case "TORRENTS_FETCH_PENDING":
draft.fetching = true;
break;
case "TORRENTS_FETCH_FULFILLED":
draft.fetching = false;
draft.torrents = action.payload.response.data;
break;
case "TORRENTS_SEARCH_PENDING":
draft.searching = true;
break;
case "TORRENTS_SEARCH_FULFILLED":
draft.searching = false;
draft.searchResults = action.payload.response.data;
break;
default:
return draft;
}
});