2017-06-06 23:19:12 +02:00
|
|
|
import * as types from "constants/action_types";
|
2017-04-23 11:56:50 +02:00
|
|
|
|
2017-06-06 06:21:55 +02:00
|
|
|
const reducers = {};
|
2017-07-25 09:07:54 +02:00
|
|
|
const defaultState = {
|
2017-09-18 04:08:43 +02:00
|
|
|
playingUri: null,
|
2017-07-30 00:56:08 +02:00
|
|
|
rewardedContentClaimIds: [],
|
2017-08-24 23:12:23 +02:00
|
|
|
channelPages: {},
|
2017-07-25 09:07:54 +02:00
|
|
|
};
|
2017-04-23 11:56:50 +02:00
|
|
|
|
|
|
|
reducers[types.FETCH_FEATURED_CONTENT_STARTED] = function(state, action) {
|
|
|
|
return Object.assign({}, state, {
|
2017-06-06 23:19:12 +02:00
|
|
|
fetchingFeaturedContent: true,
|
|
|
|
});
|
2017-06-06 06:21:55 +02:00
|
|
|
};
|
2017-04-23 11:56:50 +02:00
|
|
|
|
|
|
|
reducers[types.FETCH_FEATURED_CONTENT_COMPLETED] = function(state, action) {
|
2017-06-06 23:19:12 +02:00
|
|
|
const { uris, success } = action.data;
|
2017-05-04 05:44:08 +02:00
|
|
|
|
2017-04-23 11:56:50 +02:00
|
|
|
return Object.assign({}, state, {
|
|
|
|
fetchingFeaturedContent: false,
|
2017-05-04 05:44:08 +02:00
|
|
|
fetchingFeaturedContentFailed: !success,
|
2017-06-06 23:19:12 +02:00
|
|
|
featuredUris: uris,
|
|
|
|
});
|
2017-06-06 06:21:55 +02:00
|
|
|
};
|
2017-04-23 11:56:50 +02:00
|
|
|
|
2017-08-08 11:36:14 +02:00
|
|
|
reducers[types.FETCH_REWARD_CONTENT_COMPLETED] = function(state, action) {
|
2017-07-25 09:07:54 +02:00
|
|
|
const { claimIds, success } = action.data;
|
|
|
|
|
|
|
|
return Object.assign({}, state, {
|
2017-07-30 00:56:08 +02:00
|
|
|
rewardedContentClaimIds: claimIds,
|
2017-07-25 09:07:54 +02:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2017-10-09 08:23:44 +02:00
|
|
|
reducers[types.RESOLVE_URIS_STARTED] = function(state, action) {
|
|
|
|
let { uris } = action.data;
|
2017-04-23 16:01:00 +02:00
|
|
|
|
2017-06-06 23:19:12 +02:00
|
|
|
const oldResolving = state.resolvingUris || [];
|
|
|
|
const newResolving = Object.assign([], oldResolving);
|
2017-04-23 16:01:00 +02:00
|
|
|
|
2017-10-09 08:23:44 +02:00
|
|
|
for (let uri of uris) {
|
|
|
|
if (!newResolving.includes(uri)) {
|
|
|
|
newResolving.push(uri);
|
|
|
|
}
|
|
|
|
}
|
2017-04-23 16:01:00 +02:00
|
|
|
|
2017-04-23 18:10:45 +02:00
|
|
|
return Object.assign({}, state, {
|
2017-10-09 08:23:44 +02:00
|
|
|
resolvingUris: newResolving,
|
2017-06-06 23:19:12 +02:00
|
|
|
});
|
2017-06-06 06:21:55 +02:00
|
|
|
};
|
2017-04-23 18:10:45 +02:00
|
|
|
|
2017-09-18 04:08:43 +02:00
|
|
|
reducers[types.SET_PLAYING_URI] = (state, action) => {
|
|
|
|
return Object.assign({}, state, {
|
|
|
|
playingUri: action.data.uri,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2017-08-24 23:12:23 +02:00
|
|
|
// reducers[types.FETCH_CHANNEL_CLAIMS_COMPLETED] = function(state, action) {
|
|
|
|
// const channelPages = Object.assign({}, state.channelPages);
|
|
|
|
// const { uri, claims } = action.data;
|
|
|
|
//
|
|
|
|
// channelPages[uri] = totalPages;
|
|
|
|
//
|
|
|
|
// return Object.assign({}, state, {
|
|
|
|
// channelPages,
|
|
|
|
// });
|
|
|
|
// };
|
|
|
|
|
|
|
|
reducers[types.FETCH_CHANNEL_CLAIM_COUNT_COMPLETED] = function(state, action) {
|
2017-07-17 08:06:04 +02:00
|
|
|
const channelPages = Object.assign({}, state.channelPages);
|
2017-08-24 23:12:23 +02:00
|
|
|
const { uri, totalClaims } = action.data;
|
2017-07-17 08:06:04 +02:00
|
|
|
|
2017-09-20 19:12:53 +02:00
|
|
|
channelPages[uri] = Math.ceil(totalClaims / 10);
|
2017-07-17 08:06:04 +02:00
|
|
|
|
|
|
|
return Object.assign({}, state, {
|
|
|
|
channelPages,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2017-04-23 11:56:50 +02:00
|
|
|
export default function reducer(state = defaultState, action) {
|
|
|
|
const handler = reducers[action.type];
|
|
|
|
if (handler) return handler(state, action);
|
|
|
|
return state;
|
|
|
|
}
|