2017-12-21 18:32:51 +01:00
|
|
|
import * as ACTIONS 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-10-12 15:37:24 +02:00
|
|
|
channelClaimCounts: {},
|
2018-07-31 14:36:20 +02:00
|
|
|
positions: {},
|
2017-07-25 09:07:54 +02:00
|
|
|
};
|
2017-04-23 11:56:50 +02:00
|
|
|
|
2017-12-28 00:48:11 +01:00
|
|
|
reducers[ACTIONS.FETCH_FEATURED_CONTENT_STARTED] = state =>
|
|
|
|
Object.assign({}, state, {
|
2017-06-06 23:19:12 +02:00
|
|
|
fetchingFeaturedContent: true,
|
|
|
|
});
|
2017-04-23 11:56:50 +02:00
|
|
|
|
2017-12-28 00:48:11 +01:00
|
|
|
reducers[ACTIONS.FETCH_FEATURED_CONTENT_COMPLETED] = (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-12-28 00:48:11 +01:00
|
|
|
reducers[ACTIONS.FETCH_REWARD_CONTENT_COMPLETED] = (state, action) => {
|
2017-12-21 18:32:51 +01:00
|
|
|
const { claimIds } = action.data;
|
2017-07-25 09:07:54 +02:00
|
|
|
|
|
|
|
return Object.assign({}, state, {
|
2017-07-30 00:56:08 +02:00
|
|
|
rewardedContentClaimIds: claimIds,
|
2017-07-25 09:07:54 +02:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2017-12-28 00:48:11 +01:00
|
|
|
reducers[ACTIONS.RESOLVE_URIS_STARTED] = (state, action) => {
|
2017-12-13 22:36:30 +01:00
|
|
|
const { 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-12-21 18:32:51 +01:00
|
|
|
uris.forEach(uri => {
|
2017-10-09 08:23:44 +02:00
|
|
|
if (!newResolving.includes(uri)) {
|
|
|
|
newResolving.push(uri);
|
|
|
|
}
|
2017-12-21 18:32:51 +01:00
|
|
|
});
|
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-12-28 00:48:11 +01:00
|
|
|
reducers[ACTIONS.RESOLVE_URIS_COMPLETED] = (state, action) => {
|
2017-10-12 15:37:24 +02:00
|
|
|
const { resolveInfo } = action.data;
|
|
|
|
const channelClaimCounts = Object.assign({}, state.channelClaimCounts);
|
|
|
|
|
2017-12-21 18:32:51 +01:00
|
|
|
Object.entries(resolveInfo).forEach(([uri, { certificate, claimsInChannel }]) => {
|
|
|
|
if (certificate && !Number.isNaN(claimsInChannel)) {
|
|
|
|
channelClaimCounts[uri] = claimsInChannel;
|
2017-10-12 15:37:24 +02:00
|
|
|
}
|
2017-12-21 18:32:51 +01:00
|
|
|
});
|
2017-10-12 15:37:24 +02:00
|
|
|
|
|
|
|
return Object.assign({}, state, {
|
|
|
|
channelClaimCounts,
|
|
|
|
resolvingUris: (state.resolvingUris || []).filter(uri => !resolveInfo[uri]),
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2017-12-21 18:32:51 +01:00
|
|
|
reducers[ACTIONS.SET_PLAYING_URI] = (state, action) =>
|
2017-12-13 22:36:30 +01:00
|
|
|
Object.assign({}, state, {
|
2017-09-18 04:08:43 +02:00
|
|
|
playingUri: action.data.uri,
|
|
|
|
});
|
|
|
|
|
2017-12-28 00:48:11 +01:00
|
|
|
reducers[ACTIONS.FETCH_CHANNEL_CLAIM_COUNT_COMPLETED] = (state, action) => {
|
2017-10-12 15:37:24 +02:00
|
|
|
const channelClaimCounts = Object.assign({}, state.channelClaimCounts);
|
2017-08-24 23:12:23 +02:00
|
|
|
const { uri, totalClaims } = action.data;
|
2017-07-17 08:06:04 +02:00
|
|
|
|
2017-10-12 15:37:24 +02:00
|
|
|
channelClaimCounts[uri] = totalClaims;
|
2017-07-17 08:06:04 +02:00
|
|
|
|
|
|
|
return Object.assign({}, state, {
|
2017-10-12 15:37:24 +02:00
|
|
|
channelClaimCounts,
|
2017-07-17 08:06:04 +02:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2018-07-31 14:36:20 +02:00
|
|
|
reducers[ACTIONS.SET_CONTENT_POSITION] = (state, action) => {
|
|
|
|
const { claimId, outpoint, position } = action.data;
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
positions: {
|
|
|
|
...state.positions,
|
|
|
|
[claimId]: {
|
|
|
|
...state.positions[claimId],
|
|
|
|
[outpoint]: position,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
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;
|
|
|
|
}
|