added content fetching reducers to claims

This commit is contained in:
Akinwale Ariwodola 2018-03-10 08:46:35 +01:00
parent 5901b8d4af
commit 618a1baf1b
2 changed files with 152 additions and 0 deletions

View file

@ -4268,6 +4268,91 @@ reducers[ACTIONS.CREATE_CHANNEL_COMPLETED] = function (state, action) {
});
};
reducers[ACTIONS.FETCH_FEATURED_CONTENT_STARTED] = function (state) {
return Object.assign({}, state, {
fetchingFeaturedContent: true
});
};
reducers[ACTIONS.FETCH_FEATURED_CONTENT_COMPLETED] = function (state, action) {
var _action$data3 = action.data,
uris = _action$data3.uris,
success = _action$data3.success;
return Object.assign({}, state, {
fetchingFeaturedContent: false,
fetchingFeaturedContentFailed: !success,
featuredUris: uris
});
};
reducers[ACTIONS.FETCH_REWARD_CONTENT_COMPLETED] = function (state, action) {
var claimIds = action.data.claimIds;
return Object.assign({}, state, {
rewardedContentClaimIds: claimIds
});
};
reducers[ACTIONS.RESOLVE_URIS_STARTED] = function (state, action) {
var uris = action.data.uris;
var oldResolving = state.resolvingUris || [];
var newResolving = Object.assign([], oldResolving);
uris.forEach(function (uri) {
if (!newResolving.includes(uri)) {
newResolving.push(uri);
}
});
return Object.assign({}, state, {
resolvingUris: newResolving
});
};
reducers[ACTIONS.RESOLVE_URIS_COMPLETED] = function (state, action) {
var resolveInfo = action.data.resolveInfo;
var channelClaimCounts = Object.assign({}, state.channelClaimCounts);
Object.entries(resolveInfo).forEach(function (_ref3) {
var _ref4 = _slicedToArray(_ref3, 2),
uri = _ref4[0],
_ref4$ = _ref4[1],
certificate = _ref4$.certificate,
claimsInChannel = _ref4$.claimsInChannel;
if (certificate && !Number.isNaN(claimsInChannel)) {
channelClaimCounts[uri] = claimsInChannel;
}
});
return Object.assign({}, state, {
channelClaimCounts: channelClaimCounts,
resolvingUris: (state.resolvingUris || []).filter(function (uri) {
return !resolveInfo[uri];
})
});
};
reducers[ACTIONS.FETCH_CHANNEL_CLAIM_COUNT_COMPLETED] = function (state, action) {
var channelClaimCounts = Object.assign({}, state.channelClaimCounts);
var _action$data4 = action.data,
uri = _action$data4.uri,
totalClaims = _action$data4.totalClaims;
channelClaimCounts[uri] = totalClaims;
return Object.assign({}, state, {
channelClaimCounts: channelClaimCounts
});
};
function claimsReducer() {
var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultState;
var action = arguments[1];

View file

@ -176,6 +176,73 @@ reducers[ACTIONS.CREATE_CHANNEL_COMPLETED] = (state, action) => {
});
};
reducers[ACTIONS.FETCH_FEATURED_CONTENT_STARTED] = state =>
Object.assign({}, state, {
fetchingFeaturedContent: true,
});
reducers[ACTIONS.FETCH_FEATURED_CONTENT_COMPLETED] = (state, action) => {
const { uris, success } = action.data;
return Object.assign({}, state, {
fetchingFeaturedContent: false,
fetchingFeaturedContentFailed: !success,
featuredUris: uris,
});
};
reducers[ACTIONS.FETCH_REWARD_CONTENT_COMPLETED] = (state, action) => {
const { claimIds } = action.data;
return Object.assign({}, state, {
rewardedContentClaimIds: claimIds,
});
};
reducers[ACTIONS.RESOLVE_URIS_STARTED] = (state, action) => {
const { uris } = action.data;
const oldResolving = state.resolvingUris || [];
const newResolving = Object.assign([], oldResolving);
uris.forEach(uri => {
if (!newResolving.includes(uri)) {
newResolving.push(uri);
}
});
return Object.assign({}, state, {
resolvingUris: newResolving,
});
};
reducers[ACTIONS.RESOLVE_URIS_COMPLETED] = (state, action) => {
const { resolveInfo } = action.data;
const channelClaimCounts = Object.assign({}, state.channelClaimCounts);
Object.entries(resolveInfo).forEach(([uri, { certificate, claimsInChannel }]) => {
if (certificate && !Number.isNaN(claimsInChannel)) {
channelClaimCounts[uri] = claimsInChannel;
}
});
return Object.assign({}, state, {
channelClaimCounts,
resolvingUris: (state.resolvingUris || []).filter(uri => !resolveInfo[uri]),
});
};
reducers[ACTIONS.FETCH_CHANNEL_CLAIM_COUNT_COMPLETED] = (state, action) => {
const channelClaimCounts = Object.assign({}, state.channelClaimCounts);
const { uri, totalClaims } = action.data;
channelClaimCounts[uri] = totalClaims;
return Object.assign({}, state, {
channelClaimCounts,
});
};
export function claimsReducer(state = defaultState, action) {
const handler = reducers[action.type];
if (handler) return handler(state, action);