refactor select collection index / next

This commit is contained in:
zeppi 2021-06-07 16:21:31 -04:00
parent 6d160b3d14
commit 97cd2dbd6a
3 changed files with 37 additions and 10 deletions

15
dist/bundle.es.js vendored
View file

@ -3694,11 +3694,21 @@ const makeSelectClaimIdsForCollectionId = id => reselect.createSelector(makeSele
return ids;
});
const makeSelectNextUrlForCollection = (id, index) => reselect.createSelector(makeSelectUrlsForCollectionId(id), urls => {
const makeSelectIndexForUrlInCollection = (url, id) => reselect.createSelector(makeSelectUrlsForCollectionId(id), urls => {
const index = urls.findIndex(u => u === url);
if (index > -1) {
return index;
}
return null;
});
const makeSelectNextUrlForCollectionAndUrl = (id, url) => reselect.createSelector(makeSelectIndexForUrlInCollection(url, id), makeSelectUrlsForCollectionId(id), (index, urls) => {
if (urls && index >= -1) {
const url = urls[index + 1];
if (url) {
return url;
}
}
return null;
});
@ -7916,6 +7926,7 @@ exports.makeSelectFileInfoForUri = makeSelectFileInfoForUri;
exports.makeSelectFileNameForUri = makeSelectFileNameForUri;
exports.makeSelectFilePartlyDownloaded = makeSelectFilePartlyDownloaded;
exports.makeSelectFilteredTransactionsForPage = makeSelectFilteredTransactionsForPage;
exports.makeSelectIndexForUrlInCollection = makeSelectIndexForUrlInCollection;
exports.makeSelectIsAbandoningClaimForUri = makeSelectIsAbandoningClaimForUri;
exports.makeSelectIsResolvingCollectionForId = makeSelectIsResolvingCollectionForId;
exports.makeSelectIsUriResolving = makeSelectIsUriResolving;
@ -7929,7 +7940,7 @@ exports.makeSelectMyPublishedCollectionForId = makeSelectMyPublishedCollectionFo
exports.makeSelectMyPurchasesForPage = makeSelectMyPurchasesForPage;
exports.makeSelectMyStreamUrlsForPage = makeSelectMyStreamUrlsForPage;
exports.makeSelectNameForCollectionId = makeSelectNameForCollectionId;
exports.makeSelectNextUrlForCollection = makeSelectNextUrlForCollection;
exports.makeSelectNextUrlForCollectionAndUrl = makeSelectNextUrlForCollectionAndUrl;
exports.makeSelectNsfwCountForChannel = makeSelectNsfwCountForChannel;
exports.makeSelectNsfwCountFromUris = makeSelectNsfwCountFromUris;
exports.makeSelectOmittedCountForChannel = makeSelectOmittedCountForChannel;

View file

@ -179,7 +179,8 @@ export {
makeSelectNameForCollectionId,
makeSelectCountForCollectionId,
makeSelectIsResolvingCollectionForId,
makeSelectNextUrlForCollection,
makeSelectIndexForUrlInCollection,
makeSelectNextUrlForCollectionAndUrl,
makeSelectCollectionForIdHasClaimUrl,
} from 'redux/selectors/collections';

View file

@ -184,14 +184,29 @@ export const makeSelectClaimIdsForCollectionId = (id: string) =>
}
);
export const makeSelectNextUrlForCollection = (id: string, index: number) =>
export const makeSelectIndexForUrlInCollection = (url: string, id: string) =>
createSelector(
makeSelectUrlsForCollectionId(id),
urls => {
const index = urls.findIndex(u => u === url);
if (index > -1) {
return index;
}
return null;
}
);
export const makeSelectNextUrlForCollectionAndUrl = (id: string, url: string) =>
createSelector(
makeSelectIndexForUrlInCollection(url, id),
makeSelectUrlsForCollectionId(id),
(index, urls) => {
if (urls && index >= -1) {
const url = urls[index + 1];
if (url) {
return url;
}
}
return null;
}
);