Merge pull request #247 from lbryio/fix-noMatureSearchPagination
Fix no mature search pagination
This commit is contained in:
commit
9b11cfed62
4 changed files with 88 additions and 22 deletions
45
dist/bundle.es.js
vendored
45
dist/bundle.es.js
vendored
|
@ -1805,7 +1805,7 @@ const selectClaimsByUri = reselect.createSelector(selectState$2, selectClaimsByI
|
|||
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 || {});
|
||||
|
||||
|
@ -1891,6 +1891,16 @@ const makeSelectClaimsInChannelForPage = (uri, page) => reselect.createSelector(
|
|||
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 byChannel = allClaims[uri] || {};
|
||||
const claimIds = byChannel[page || 1];
|
||||
|
@ -2031,6 +2041,12 @@ const makeSelectNsfwCountForChannel = uri => reselect.createSelector(selectClaim
|
|||
}, 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),
|
||||
// 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
|
||||
|
@ -3981,7 +3997,7 @@ const reducers = {};
|
|||
const defaultState = {
|
||||
byId: {},
|
||||
claimsByUri: {},
|
||||
claimsByChannel: {},
|
||||
paginatedClaimsByChannel: {},
|
||||
channelClaimCounts: {},
|
||||
fetchingChannelClaims: {},
|
||||
resolvingUris: [],
|
||||
|
@ -4174,11 +4190,17 @@ reducers[FETCH_CHANNEL_CLAIMS_COMPLETED] = (state, action) => {
|
|||
uri,
|
||||
claims,
|
||||
claimsInChannel,
|
||||
page
|
||||
page,
|
||||
totalPages
|
||||
} = action.data;
|
||||
|
||||
// byChannel keeps claim_search relevant results by page. If the total changes, erase it.
|
||||
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 currentPageClaimIds = [];
|
||||
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.pageCount = totalPages;
|
||||
byChannel.itemCount = claimsInChannel;
|
||||
byChannel[page] = currentPageClaimIds;
|
||||
claimsByChannel[uri] = byChannel;
|
||||
paginatedClaimsByChannel[uri] = byChannel;
|
||||
delete fetchingChannelClaims[uri];
|
||||
|
||||
return Object.assign({}, state, {
|
||||
claimsByChannel,
|
||||
paginatedClaimsByChannel,
|
||||
byId,
|
||||
fetchingChannelClaims,
|
||||
claimsByUri,
|
||||
|
@ -5481,6 +5501,7 @@ exports.makeSelectMetadataItemForUri = makeSelectMetadataItemForUri;
|
|||
exports.makeSelectMyStreamUrlsForPage = makeSelectMyStreamUrlsForPage;
|
||||
exports.makeSelectNsfwCountForChannel = makeSelectNsfwCountForChannel;
|
||||
exports.makeSelectNsfwCountFromUris = makeSelectNsfwCountFromUris;
|
||||
exports.makeSelectOmittedCountForChannel = makeSelectOmittedCountForChannel;
|
||||
exports.makeSelectPendingByUri = makeSelectPendingByUri;
|
||||
exports.makeSelectPermanentUrlForUri = makeSelectPermanentUrlForUri;
|
||||
exports.makeSelectPublishFormValue = makeSelectPublishFormValue;
|
||||
|
@ -5495,8 +5516,10 @@ exports.makeSelectSupportsForUri = makeSelectSupportsForUri;
|
|||
exports.makeSelectTagsForUri = makeSelectTagsForUri;
|
||||
exports.makeSelectThumbnailForUri = makeSelectThumbnailForUri;
|
||||
exports.makeSelectTitleForUri = makeSelectTitleForUri;
|
||||
exports.makeSelectTotalClaimsInChannelSearch = makeSelectTotalClaimsInChannelSearch;
|
||||
exports.makeSelectTotalItemsForChannel = makeSelectTotalItemsForChannel;
|
||||
exports.makeSelectTotalPagesForChannel = makeSelectTotalPagesForChannel;
|
||||
exports.makeSelectTotalPagesInChannelSearch = makeSelectTotalPagesInChannelSearch;
|
||||
exports.makeSelectUriIsStreamable = makeSelectUriIsStreamable;
|
||||
exports.normalizeURI = normalizeURI;
|
||||
exports.notificationsReducer = notificationsReducer;
|
||||
|
|
|
@ -159,6 +159,8 @@ export {
|
|||
makeSelectClaimIsMine,
|
||||
makeSelectFetchingChannelClaims,
|
||||
makeSelectClaimsInChannelForPage,
|
||||
makeSelectTotalPagesInChannelSearch,
|
||||
makeSelectTotalClaimsInChannelSearch,
|
||||
makeSelectMetadataForUri,
|
||||
makeSelectMetadataItemForUri,
|
||||
makeSelectThumbnailForUri,
|
||||
|
@ -173,6 +175,7 @@ export {
|
|||
makeSelectTotalPagesForChannel,
|
||||
makeSelectNsfwCountFromUris,
|
||||
makeSelectNsfwCountForChannel,
|
||||
makeSelectOmittedCountForChannel,
|
||||
makeSelectClaimIsNsfw,
|
||||
makeSelectRecommendedContentForUri,
|
||||
makeSelectFirstRecommendedFileForUri,
|
||||
|
|
|
@ -28,9 +28,11 @@ type State = {
|
|||
claimSearchByQuery: { [string]: Array<string> },
|
||||
claimSearchByQueryLastPageReached: { [string]: Array<boolean> },
|
||||
creatingChannel: boolean,
|
||||
claimsByChannel: {
|
||||
paginatedClaimsByChannel: {
|
||||
[string]: {
|
||||
all: Array<string>,
|
||||
pageCount: number,
|
||||
itemCount: number,
|
||||
[number]: Array<string>,
|
||||
},
|
||||
},
|
||||
|
@ -43,7 +45,7 @@ const reducers = {};
|
|||
const defaultState = {
|
||||
byId: {},
|
||||
claimsByUri: {},
|
||||
claimsByChannel: {},
|
||||
paginatedClaimsByChannel: {},
|
||||
channelClaimCounts: {},
|
||||
fetchingChannelClaims: {},
|
||||
resolvingUris: [],
|
||||
|
@ -248,15 +250,22 @@ reducers[ACTIONS.FETCH_CHANNEL_CLAIMS_COMPLETED] = (state: State, action: any):
|
|||
claims,
|
||||
claimsInChannel,
|
||||
page,
|
||||
totalPages,
|
||||
}: {
|
||||
uri: string,
|
||||
claims: Array<StreamClaim>,
|
||||
claimsInChannel?: number,
|
||||
page: number,
|
||||
totalPages: number,
|
||||
} = action.data;
|
||||
|
||||
// byChannel keeps claim_search relevant results by page. If the total changes, erase it.
|
||||
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 currentPageClaimIds = [];
|
||||
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.pageCount = totalPages;
|
||||
byChannel.itemCount = claimsInChannel;
|
||||
byChannel[page] = currentPageClaimIds;
|
||||
claimsByChannel[uri] = byChannel;
|
||||
paginatedClaimsByChannel[uri] = byChannel;
|
||||
delete fetchingChannelClaims[uri];
|
||||
|
||||
return Object.assign({}, state, {
|
||||
claimsByChannel,
|
||||
paginatedClaimsByChannel,
|
||||
byId,
|
||||
fetchingChannelClaims,
|
||||
claimsByUri,
|
||||
|
|
|
@ -54,7 +54,7 @@ export const selectClaimsByUri = createSelector(
|
|||
|
||||
export const selectAllClaimsByChannel = createSelector(
|
||||
selectState,
|
||||
state => state.claimsByChannel || {}
|
||||
state => state.paginatedClaimsByChannel || {}
|
||||
);
|
||||
|
||||
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) =>
|
||||
createSelector(
|
||||
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 =>
|
||||
createSelector(
|
||||
makeSelectClaimForUri(uri),
|
||||
|
|
Loading…
Reference in a new issue