diff --git a/dist/bundle.es.js b/dist/bundle.es.js index abd01e3..600a060 100644 --- a/dist/bundle.es.js +++ b/dist/bundle.es.js @@ -3694,10 +3694,20 @@ const makeSelectClaimIdsForCollectionId = id => reselect.createSelector(makeSele return ids; }); -const makeSelectNextUrlForCollection = (id, index) => reselect.createSelector(makeSelectUrlsForCollectionId(id), urls => { - const url = urls[index + 1]; - if (url) { - return url; +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; }); @@ -7927,6 +7937,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; @@ -7940,7 +7951,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; diff --git a/src/index.js b/src/index.js index 6187fdf..db1ef86 100644 --- a/src/index.js +++ b/src/index.js @@ -179,7 +179,8 @@ export { makeSelectNameForCollectionId, makeSelectCountForCollectionId, makeSelectIsResolvingCollectionForId, - makeSelectNextUrlForCollection, + makeSelectIndexForUrlInCollection, + makeSelectNextUrlForCollectionAndUrl, makeSelectCollectionForIdHasClaimUrl, } from 'redux/selectors/collections'; diff --git a/src/redux/selectors/collections.js b/src/redux/selectors/collections.js index 68cdddf..b55fa40 100644 --- a/src/redux/selectors/collections.js +++ b/src/redux/selectors/collections.js @@ -184,13 +184,28 @@ export const makeSelectClaimIdsForCollectionId = (id: string) => } ); -export const makeSelectNextUrlForCollection = (id: string, index: number) => +export const makeSelectIndexForUrlInCollection = (url: string, id: string) => createSelector( makeSelectUrlsForCollectionId(id), urls => { - const url = urls[index + 1]; - if (url) { - return url; + 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; }