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 = {};
|
2017-07-25 03:07:54 -04:00
|
|
|
const defaultState = {
|
2017-09-17 22:08:43 -04:00
|
|
|
playingUri: null,
|
2017-07-29 18:56:08 -04:00
|
|
|
rewardedContentClaimIds: [],
|
2017-10-12 09:37:24 -04:00
|
|
|
channelClaimCounts: {},
|
2017-07-25 03:07:54 -04:00
|
|
|
};
|
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-08-08 10:36:14 +01:00
|
|
|
reducers[types.FETCH_REWARD_CONTENT_COMPLETED] = function(state, action) {
|
2017-07-25 03:07:54 -04:00
|
|
|
const { claimIds, success } = action.data;
|
|
|
|
|
|
|
|
return Object.assign({}, state, {
|
2017-07-29 18:56:08 -04:00
|
|
|
rewardedContentClaimIds: claimIds,
|
2017-07-25 03:07:54 -04:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2017-10-09 02:23:44 -04:00
|
|
|
reducers[types.RESOLVE_URIS_STARTED] = function(state, action) {
|
|
|
|
let { uris } = 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);
|
2017-04-23 21:01:00 +07:00
|
|
|
|
2017-10-09 02:23:44 -04:00
|
|
|
for (let uri of uris) {
|
|
|
|
if (!newResolving.includes(uri)) {
|
|
|
|
newResolving.push(uri);
|
|
|
|
}
|
|
|
|
}
|
2017-04-23 21:01:00 +07:00
|
|
|
|
2017-04-23 23:10:45 +07:00
|
|
|
return Object.assign({}, state, {
|
2017-10-09 02:23:44 -04:00
|
|
|
resolvingUris: newResolving,
|
2017-06-06 17:19:12 -04:00
|
|
|
});
|
2017-06-05 21:21:55 -07:00
|
|
|
};
|
2017-04-23 23:10:45 +07:00
|
|
|
|
2017-10-12 09:37:24 -04:00
|
|
|
reducers[types.RESOLVE_URIS_COMPLETED] = function(state, action) {
|
|
|
|
const { resolveInfo } = action.data;
|
|
|
|
const channelClaimCounts = Object.assign({}, state.channelClaimCounts);
|
|
|
|
|
|
|
|
for (let [uri, { certificate, claims_in_channel }] of Object.entries(
|
|
|
|
resolveInfo
|
|
|
|
)) {
|
|
|
|
if (certificate && !isNaN(claims_in_channel)) {
|
|
|
|
channelClaimCounts[uri] = claims_in_channel;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return Object.assign({}, state, {
|
|
|
|
channelClaimCounts,
|
|
|
|
resolvingUris: (state.resolvingUris || []).filter(uri => !resolveInfo[uri]),
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2017-09-17 22:08:43 -04:00
|
|
|
reducers[types.SET_PLAYING_URI] = (state, action) => {
|
|
|
|
return Object.assign({}, state, {
|
|
|
|
playingUri: action.data.uri,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2017-08-24 17:12:23 -04:00
|
|
|
reducers[types.FETCH_CHANNEL_CLAIM_COUNT_COMPLETED] = function(state, action) {
|
2017-10-12 09:37:24 -04:00
|
|
|
const channelClaimCounts = Object.assign({}, state.channelClaimCounts);
|
2017-08-24 17:12:23 -04:00
|
|
|
const { uri, totalClaims } = action.data;
|
2017-07-17 13:06:04 +07:00
|
|
|
|
2017-10-12 09:37:24 -04:00
|
|
|
channelClaimCounts[uri] = totalClaims;
|
2017-07-17 13:06:04 +07:00
|
|
|
|
|
|
|
return Object.assign({}, state, {
|
2017-10-12 09:37:24 -04:00
|
|
|
channelClaimCounts,
|
2017-07-17 13:06:04 +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;
|
|
|
|
}
|