From 1fc5afa0c45cfb4126539513088b580db9c4aca1 Mon Sep 17 00:00:00 2001 From: jessop Date: Tue, 27 Oct 2020 15:42:53 -0400 Subject: [PATCH] add makeSelectTagInClaimOrChannelForUri --- dist/bundle.es.js | 7 +++++++ src/index.js | 1 + src/redux/selectors/claims.js | 31 +++++++++++++++++++++++++++---- 3 files changed, 35 insertions(+), 4 deletions(-) diff --git a/dist/bundle.es.js b/dist/bundle.es.js index 8134f62..67d88d2 100644 --- a/dist/bundle.es.js +++ b/dist/bundle.es.js @@ -2575,6 +2575,12 @@ const makeSelectMyStreamUrlsForPage = (page = 1) => reselect.createSelector(sele const selectMyStreamUrlsCount = reselect.createSelector(selectMyClaimUrisWithoutChannels, channels => channels.length); +const makeSelectTagInClaimOrChannelForUri = (uri, tag) => reselect.createSelector(makeSelectClaimForUri(uri), claim => { + const claimTags = claim && claim.value && claim.value.tags || []; + const channelTags = claim && claim.signing_channel && claim.signing_channel.value && claim.signing_channel.value.tags || []; + return claimTags.includes(tag) || channelTags.includes(tag); +}); + function numberWithCommas(x) { var parts = x.toString().split('.'); parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ','); @@ -6319,6 +6325,7 @@ exports.makeSelectSearchDownloadUrlsForPage = makeSelectSearchDownloadUrlsForPag exports.makeSelectShortUrlForUri = makeSelectShortUrlForUri; exports.makeSelectStreamingUrlForUri = makeSelectStreamingUrlForUri; exports.makeSelectSupportsForUri = makeSelectSupportsForUri; +exports.makeSelectTagInClaimOrChannelForUri = makeSelectTagInClaimOrChannelForUri; exports.makeSelectTagsForUri = makeSelectTagsForUri; exports.makeSelectThumbnailForUri = makeSelectThumbnailForUri; exports.makeSelectTitleForUri = makeSelectTitleForUri; diff --git a/src/index.js b/src/index.js index 71eac2f..5ef85db 100644 --- a/src/index.js +++ b/src/index.js @@ -161,6 +161,7 @@ export { makeSelectDateForUri, makeSelectAmountForUri, makeSelectTagsForUri, + makeSelectTagInClaimOrChannelForUri, makeSelectContentTypeForUri, makeSelectIsUriResolving, makeSelectTotalItemsForChannel, diff --git a/src/redux/selectors/claims.js b/src/redux/selectors/claims.js index 41c7e73..c472543 100644 --- a/src/redux/selectors/claims.js +++ b/src/redux/selectors/claims.js @@ -258,8 +258,8 @@ export const makeSelectMyPurchasesForPage = (query: ?string, page: number = 1) = const end = Number(page) * Number(PAGE_SIZE); return matchingFileInfos && matchingFileInfos.length ? matchingFileInfos - .slice(start, end) - .map(fileInfo => fileInfo.canonical_url || fileInfo.permanent_url) + .slice(start, end) + .map(fileInfo => fileInfo.canonical_url || fileInfo.permanent_url) : []; } ); @@ -365,8 +365,8 @@ export const makeSelectDateForUri = (uri: string) => (claim.value.release_time ? claim.value.release_time * 1000 : claim.meta && claim.meta.creation_timestamp - ? claim.meta.creation_timestamp * 1000 - : null); + ? claim.meta.creation_timestamp * 1000 + : null); if (!timestamp) { return undefined; } @@ -680,6 +680,14 @@ export const makeSelectTagsForUri = (uri: string) => } ); +export const makeSelectChannelTagsForUri = (uri: string) => + createSelector( + makeSelectMetadataForUri(uri), + (metadata: ?GenericMetadata) => { + return (metadata && metadata.tags) || []; + } + ); + export const selectFetchingClaimSearchByQuery = createSelector( selectState, state => state.fetchingClaimSearchByQuery || {} @@ -775,3 +783,18 @@ export const selectMyStreamUrlsCount = createSelector( selectMyClaimUrisWithoutChannels, channels => channels.length ); + +export const makeSelectTagInClaimOrChannelForUri = (uri: string, tag: string) => + createSelector( + makeSelectClaimForUri(uri), + claim => { + const claimTags = (claim && claim.value && claim.value.tags) || []; + const channelTags = + (claim && + claim.signing_channel && + claim.signing_channel.value && + claim.signing_channel.value.tags) || + []; + return claimTags.includes(tag) || channelTags.includes(tag); + } + );