Merge pull request #247 from lbryio/fix-noMatureSearchPagination

Fix no mature search pagination
This commit is contained in:
jessopb 2019-12-03 18:01:06 -05:00 committed by GitHub
commit 9b11cfed62
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 88 additions and 22 deletions

45
dist/bundle.es.js vendored
View file

@ -1805,7 +1805,7 @@ const selectClaimsByUri = reselect.createSelector(selectState$2, selectClaimsByI
return claims; return claims;
}); });
const selectAllClaimsByChannel = reselect.createSelector(selectState$2, state => state.claimsByChannel || {}); const selectAllClaimsByChannel = reselect.createSelector(selectState$2, state => state.paginatedClaimsByChannel || {});
const selectPendingById = reselect.createSelector(selectState$2, state => state.pendingById || {}); const selectPendingById = reselect.createSelector(selectState$2, state => state.pendingById || {});
@ -1891,6 +1891,16 @@ const makeSelectClaimsInChannelForPage = (uri, page) => reselect.createSelector(
return claimIds.map(claimId => byId[claimId]); return claimIds.map(claimId => byId[claimId]);
}); });
const makeSelectTotalClaimsInChannelSearch = uri => reselect.createSelector(selectClaimsById, selectAllClaimsByChannel, (byId, allClaims) => {
const byChannel = allClaims[uri] || {};
return byChannel['itemCount'];
});
const makeSelectTotalPagesInChannelSearch = uri => reselect.createSelector(selectClaimsById, selectAllClaimsByChannel, (byId, allClaims) => {
const byChannel = allClaims[uri] || {};
return byChannel['pageCount'];
});
const makeSelectClaimsInChannelForCurrentPageState = uri => reselect.createSelector(selectClaimsById, selectAllClaimsByChannel, selectCurrentChannelPage, (byId, allClaims, page) => { const makeSelectClaimsInChannelForCurrentPageState = uri => reselect.createSelector(selectClaimsById, selectAllClaimsByChannel, selectCurrentChannelPage, (byId, allClaims, page) => {
const byChannel = allClaims[uri] || {}; const byChannel = allClaims[uri] || {};
const claimIds = byChannel[page || 1]; const claimIds = byChannel[page || 1];
@ -2031,6 +2041,12 @@ const makeSelectNsfwCountForChannel = uri => reselect.createSelector(selectClaim
}, 0); }, 0);
}); });
const makeSelectOmittedCountForChannel = uri => reselect.createSelector(makeSelectTotalItemsForChannel(uri), makeSelectTotalClaimsInChannelSearch(uri), (claimsInChannel, claimsInSearch) => {
if (claimsInChannel && claimsInSearch) {
return claimsInChannel - claimsInSearch;
} else return 0;
});
const makeSelectClaimIsNsfw = uri => reselect.createSelector(makeSelectClaimForUri(uri), const makeSelectClaimIsNsfw = uri => reselect.createSelector(makeSelectClaimForUri(uri),
// Eventually these will come from some list of tags that are considered adult // Eventually these will come from some list of tags that are considered adult
// Or possibly come from users settings of what tags they want to hide // Or possibly come from users settings of what tags they want to hide
@ -3981,7 +3997,7 @@ const reducers = {};
const defaultState = { const defaultState = {
byId: {}, byId: {},
claimsByUri: {}, claimsByUri: {},
claimsByChannel: {}, paginatedClaimsByChannel: {},
channelClaimCounts: {}, channelClaimCounts: {},
fetchingChannelClaims: {}, fetchingChannelClaims: {},
resolvingUris: [], resolvingUris: [],
@ -4174,11 +4190,17 @@ reducers[FETCH_CHANNEL_CLAIMS_COMPLETED] = (state, action) => {
uri, uri,
claims, claims,
claimsInChannel, claimsInChannel,
page page,
totalPages
} = action.data; } = action.data;
// byChannel keeps claim_search relevant results by page. If the total changes, erase it.
const channelClaimCounts = Object.assign({}, state.channelClaimCounts); const channelClaimCounts = Object.assign({}, state.channelClaimCounts);
const claimsByChannel = Object.assign({}, state.claimsByChannel);
const byChannel = Object.assign({}, claimsByChannel[uri]); const paginatedClaimsByChannel = Object.assign({}, state.paginatedClaimsByChannel);
// check if count has changed - that means cached pagination will be wrong, so clear it
const previousCount = paginatedClaimsByChannel[uri] && paginatedClaimsByChannel[uri]['itemCount'];
const byChannel = claimsInChannel === previousCount ? Object.assign({}, paginatedClaimsByChannel[uri]) : {};
const allClaimIds = new Set(byChannel.all); const allClaimIds = new Set(byChannel.all);
const currentPageClaimIds = []; const currentPageClaimIds = [];
const byId = Object.assign({}, state.byId); const byId = Object.assign({}, state.byId);
@ -4194,17 +4216,15 @@ reducers[FETCH_CHANNEL_CLAIMS_COMPLETED] = (state, action) => {
}); });
} }
if (claimsInChannel) {
channelClaimCounts[uri] = claimsInChannel;
}
byChannel.all = allClaimIds; byChannel.all = allClaimIds;
byChannel.pageCount = totalPages;
byChannel.itemCount = claimsInChannel;
byChannel[page] = currentPageClaimIds; byChannel[page] = currentPageClaimIds;
claimsByChannel[uri] = byChannel; paginatedClaimsByChannel[uri] = byChannel;
delete fetchingChannelClaims[uri]; delete fetchingChannelClaims[uri];
return Object.assign({}, state, { return Object.assign({}, state, {
claimsByChannel, paginatedClaimsByChannel,
byId, byId,
fetchingChannelClaims, fetchingChannelClaims,
claimsByUri, claimsByUri,
@ -5481,6 +5501,7 @@ exports.makeSelectMetadataItemForUri = makeSelectMetadataItemForUri;
exports.makeSelectMyStreamUrlsForPage = makeSelectMyStreamUrlsForPage; exports.makeSelectMyStreamUrlsForPage = makeSelectMyStreamUrlsForPage;
exports.makeSelectNsfwCountForChannel = makeSelectNsfwCountForChannel; exports.makeSelectNsfwCountForChannel = makeSelectNsfwCountForChannel;
exports.makeSelectNsfwCountFromUris = makeSelectNsfwCountFromUris; exports.makeSelectNsfwCountFromUris = makeSelectNsfwCountFromUris;
exports.makeSelectOmittedCountForChannel = makeSelectOmittedCountForChannel;
exports.makeSelectPendingByUri = makeSelectPendingByUri; exports.makeSelectPendingByUri = makeSelectPendingByUri;
exports.makeSelectPermanentUrlForUri = makeSelectPermanentUrlForUri; exports.makeSelectPermanentUrlForUri = makeSelectPermanentUrlForUri;
exports.makeSelectPublishFormValue = makeSelectPublishFormValue; exports.makeSelectPublishFormValue = makeSelectPublishFormValue;
@ -5495,8 +5516,10 @@ exports.makeSelectSupportsForUri = makeSelectSupportsForUri;
exports.makeSelectTagsForUri = makeSelectTagsForUri; exports.makeSelectTagsForUri = makeSelectTagsForUri;
exports.makeSelectThumbnailForUri = makeSelectThumbnailForUri; exports.makeSelectThumbnailForUri = makeSelectThumbnailForUri;
exports.makeSelectTitleForUri = makeSelectTitleForUri; exports.makeSelectTitleForUri = makeSelectTitleForUri;
exports.makeSelectTotalClaimsInChannelSearch = makeSelectTotalClaimsInChannelSearch;
exports.makeSelectTotalItemsForChannel = makeSelectTotalItemsForChannel; exports.makeSelectTotalItemsForChannel = makeSelectTotalItemsForChannel;
exports.makeSelectTotalPagesForChannel = makeSelectTotalPagesForChannel; exports.makeSelectTotalPagesForChannel = makeSelectTotalPagesForChannel;
exports.makeSelectTotalPagesInChannelSearch = makeSelectTotalPagesInChannelSearch;
exports.makeSelectUriIsStreamable = makeSelectUriIsStreamable; exports.makeSelectUriIsStreamable = makeSelectUriIsStreamable;
exports.normalizeURI = normalizeURI; exports.normalizeURI = normalizeURI;
exports.notificationsReducer = notificationsReducer; exports.notificationsReducer = notificationsReducer;

View file

@ -159,6 +159,8 @@ export {
makeSelectClaimIsMine, makeSelectClaimIsMine,
makeSelectFetchingChannelClaims, makeSelectFetchingChannelClaims,
makeSelectClaimsInChannelForPage, makeSelectClaimsInChannelForPage,
makeSelectTotalPagesInChannelSearch,
makeSelectTotalClaimsInChannelSearch,
makeSelectMetadataForUri, makeSelectMetadataForUri,
makeSelectMetadataItemForUri, makeSelectMetadataItemForUri,
makeSelectThumbnailForUri, makeSelectThumbnailForUri,
@ -173,6 +175,7 @@ export {
makeSelectTotalPagesForChannel, makeSelectTotalPagesForChannel,
makeSelectNsfwCountFromUris, makeSelectNsfwCountFromUris,
makeSelectNsfwCountForChannel, makeSelectNsfwCountForChannel,
makeSelectOmittedCountForChannel,
makeSelectClaimIsNsfw, makeSelectClaimIsNsfw,
makeSelectRecommendedContentForUri, makeSelectRecommendedContentForUri,
makeSelectFirstRecommendedFileForUri, makeSelectFirstRecommendedFileForUri,

View file

@ -28,9 +28,11 @@ type State = {
claimSearchByQuery: { [string]: Array<string> }, claimSearchByQuery: { [string]: Array<string> },
claimSearchByQueryLastPageReached: { [string]: Array<boolean> }, claimSearchByQueryLastPageReached: { [string]: Array<boolean> },
creatingChannel: boolean, creatingChannel: boolean,
claimsByChannel: { paginatedClaimsByChannel: {
[string]: { [string]: {
all: Array<string>, all: Array<string>,
pageCount: number,
itemCount: number,
[number]: Array<string>, [number]: Array<string>,
}, },
}, },
@ -43,7 +45,7 @@ const reducers = {};
const defaultState = { const defaultState = {
byId: {}, byId: {},
claimsByUri: {}, claimsByUri: {},
claimsByChannel: {}, paginatedClaimsByChannel: {},
channelClaimCounts: {}, channelClaimCounts: {},
fetchingChannelClaims: {}, fetchingChannelClaims: {},
resolvingUris: [], resolvingUris: [],
@ -248,15 +250,22 @@ reducers[ACTIONS.FETCH_CHANNEL_CLAIMS_COMPLETED] = (state: State, action: any):
claims, claims,
claimsInChannel, claimsInChannel,
page, page,
totalPages,
}: { }: {
uri: string, uri: string,
claims: Array<StreamClaim>, claims: Array<StreamClaim>,
claimsInChannel?: number, claimsInChannel?: number,
page: number, page: number,
totalPages: number,
} = action.data; } = action.data;
// byChannel keeps claim_search relevant results by page. If the total changes, erase it.
const channelClaimCounts = Object.assign({}, state.channelClaimCounts); const channelClaimCounts = Object.assign({}, state.channelClaimCounts);
const claimsByChannel = Object.assign({}, state.claimsByChannel);
const byChannel = Object.assign({}, claimsByChannel[uri]); const paginatedClaimsByChannel = Object.assign({}, state.paginatedClaimsByChannel);
// check if count has changed - that means cached pagination will be wrong, so clear it
const previousCount = paginatedClaimsByChannel[uri] && paginatedClaimsByChannel[uri]['itemCount'];
const byChannel = (claimsInChannel === previousCount) ? Object.assign({}, paginatedClaimsByChannel[uri]) : {};
const allClaimIds = new Set(byChannel.all); const allClaimIds = new Set(byChannel.all);
const currentPageClaimIds = []; const currentPageClaimIds = [];
const byId = Object.assign({}, state.byId); const byId = Object.assign({}, state.byId);
@ -272,17 +281,15 @@ reducers[ACTIONS.FETCH_CHANNEL_CLAIMS_COMPLETED] = (state: State, action: any):
}); });
} }
if (claimsInChannel) {
channelClaimCounts[uri] = claimsInChannel;
}
byChannel.all = allClaimIds; byChannel.all = allClaimIds;
byChannel.pageCount = totalPages;
byChannel.itemCount = claimsInChannel;
byChannel[page] = currentPageClaimIds; byChannel[page] = currentPageClaimIds;
claimsByChannel[uri] = byChannel; paginatedClaimsByChannel[uri] = byChannel;
delete fetchingChannelClaims[uri]; delete fetchingChannelClaims[uri];
return Object.assign({}, state, { return Object.assign({}, state, {
claimsByChannel, paginatedClaimsByChannel,
byId, byId,
fetchingChannelClaims, fetchingChannelClaims,
claimsByUri, claimsByUri,

View file

@ -54,7 +54,7 @@ export const selectClaimsByUri = createSelector(
export const selectAllClaimsByChannel = createSelector( export const selectAllClaimsByChannel = createSelector(
selectState, selectState,
state => state.claimsByChannel || {} state => state.paginatedClaimsByChannel || {}
); );
export const selectPendingById = createSelector( export const selectPendingById = createSelector(
@ -192,6 +192,27 @@ export const makeSelectClaimsInChannelForPage = (uri: string, page?: number) =>
} }
); );
export const makeSelectTotalClaimsInChannelSearch = (uri: string) =>
createSelector(
selectClaimsById,
selectAllClaimsByChannel,
(byId, allClaims) => {
const byChannel = allClaims[uri] || {};
return byChannel['itemCount'];
}
);
export const makeSelectTotalPagesInChannelSearch = (uri: string) =>
createSelector(
selectClaimsById,
selectAllClaimsByChannel,
(byId, allClaims) => {
const byChannel = allClaims[uri] || {};
return byChannel['pageCount'];
}
);
export const makeSelectClaimsInChannelForCurrentPageState = (uri: string) => export const makeSelectClaimsInChannelForCurrentPageState = (uri: string) =>
createSelector( createSelector(
selectClaimsById, selectClaimsById,
@ -445,6 +466,18 @@ export const makeSelectNsfwCountForChannel = (uri: string) =>
} }
); );
export const makeSelectOmittedCountForChannel = (uri: string) =>
createSelector(
makeSelectTotalItemsForChannel(uri),
makeSelectTotalClaimsInChannelSearch(uri),
(claimsInChannel, claimsInSearch) => {
if (claimsInChannel && claimsInSearch) {
return claimsInChannel - claimsInSearch;
}
else return 0;
}
);
export const makeSelectClaimIsNsfw = (uri: string): boolean => export const makeSelectClaimIsNsfw = (uri: string): boolean =>
createSelector( createSelector(
makeSelectClaimForUri(uri), makeSelectClaimForUri(uri),