lbry-desktop/ui/js/reducers/content.js

57 lines
1.5 KiB
JavaScript
Raw Normal View History

2017-06-06 17:19:12 -04:00
import * as types from "constants/action_types";
2017-04-23 16:56:50 +07:00
2017-06-05 21:21:55 -07:00
const reducers = {};
const defaultState = {};
2017-04-23 16:56:50 +07:00
reducers[types.FETCH_FEATURED_CONTENT_STARTED] = function(state, action) {
return Object.assign({}, state, {
2017-06-06 17:19:12 -04:00
fetchingFeaturedContent: true,
});
2017-06-05 21:21:55 -07:00
};
2017-04-23 16:56:50 +07:00
reducers[types.FETCH_FEATURED_CONTENT_COMPLETED] = function(state, action) {
2017-06-06 17:19:12 -04:00
const { uris, success } = action.data;
2017-05-03 23:44:08 -04:00
2017-04-23 16:56:50 +07:00
return Object.assign({}, state, {
fetchingFeaturedContent: false,
2017-05-03 23:44:08 -04:00
fetchingFeaturedContentFailed: !success,
2017-06-06 17:19:12 -04:00
featuredUris: uris,
});
2017-06-05 21:21:55 -07:00
};
2017-04-23 16:56:50 +07:00
2017-04-23 21:01:00 +07:00
reducers[types.RESOLVE_URI_STARTED] = function(state, action) {
2017-06-06 17:19:12 -04:00
const { uri } = action.data;
2017-04-23 21:01:00 +07:00
2017-06-06 17:19:12 -04:00
const oldResolving = state.resolvingUris || [];
const newResolving = Object.assign([], oldResolving);
if (newResolving.indexOf(uri) === -1) newResolving.push(uri);
2017-04-23 21:01:00 +07:00
return Object.assign({}, state, {
2017-06-06 17:19:12 -04:00
resolvingUris: newResolving,
});
2017-06-05 21:21:55 -07:00
};
2017-04-23 21:01:00 +07:00
reducers[types.RESOLVE_URI_COMPLETED] = function(state, action) {
2017-06-06 17:19:12 -04:00
const { uri } = action.data;
const resolvingUris = state.resolvingUris;
const index = state.resolvingUris.indexOf(uri);
2017-04-23 21:01:00 +07:00
const newResolvingUris = [
...resolvingUris.slice(0, index),
2017-06-06 17:19:12 -04:00
...resolvingUris.slice(index + 1),
];
2017-04-23 21:01:00 +07:00
return Object.assign({}, state, {
resolvingUris: newResolvingUris,
2017-06-06 17:19:12 -04:00
});
2017-06-05 21:21:55 -07:00
};
reducers[types.RESOLVE_URI_CANCELED] = function(state, action) {
2017-06-06 17:19:12 -04:00
return reducers[types.RESOLVE_URI_COMPLETED](state, action);
2017-06-05 21:21:55 -07:00
};
2017-04-23 16:56:50 +07:00
export default function reducer(state = defaultState, action) {
const handler = reducers[action.type];
if (handler) return handler(state, action);
return state;
}