Recommendations: factor out a selector for raw results

1606
This commit is contained in:
infinite-persistence 2022-06-01 20:05:39 +08:00 committed by Thomas Zarebczan
parent 05376490a8
commit 2edf1ca564

View file

@ -52,16 +52,31 @@ export const makeSelectHasReachedMaxResultsLength = (query: string): ((state: St
return hasReachedMaxResultsLength[query]; return hasReachedMaxResultsLength[query];
}); });
export const selectRecommendedContentRawForUri = createCachedSelector(
(state, uri) => uri,
selectClaimsByUri,
selectShowMatureContent,
selectClaimIsNsfwForUri, // (state, uri)
selectSearchResultByQuery,
(uri, claimsByUri, matureEnabled, isMature, searchUrisByQuery) => {
const claim = claimsByUri[uri];
if (claim?.value?.title) {
const options = getRecommendationSearchOptions(matureEnabled, isMature, claim.claim_id);
const normalizedSearchQuery = getRecommendationSearchKey(claim.value.title, options);
return searchUrisByQuery[normalizedSearchQuery];
}
return undefined;
}
)((state, uri) => String(uri));
export const selectRecommendedContentForUri = createCachedSelector( export const selectRecommendedContentForUri = createCachedSelector(
(state, uri) => uri, (state, uri) => uri,
selectHistory, selectHistory,
selectRecommendedContentRawForUri, // (state, uri)
selectClaimsByUri, selectClaimsByUri,
selectShowMatureContent,
selectMutedChannels, selectMutedChannels,
selectAllCostInfoByUri, selectAllCostInfoByUri,
selectSearchResultByQuery, (uri, history, rawRecommendations, claimsByUri, blockedChannels, costInfoByUri) => {
selectClaimIsNsfwForUri, // (state, uri)
(uri, history, claimsByUri, matureEnabled, blockedChannels, costInfoByUri, searchUrisByQuery, isMature) => {
const claim = claimsByUri[uri]; const claim = claimsByUri[uri];
if (!claim) return; if (!claim) return;
@ -69,13 +84,7 @@ export const selectRecommendedContentForUri = createCachedSelector(
// always grab the claimId - this value won't change for filtering // always grab the claimId - this value won't change for filtering
const currentClaimId = claim.claim_id; const currentClaimId = claim.claim_id;
const { title } = claim.value; const searchResult = rawRecommendations;
if (!title) return;
const options = getRecommendationSearchOptions(matureEnabled, isMature, claim.claim_id);
const normalizedSearchQuery = getRecommendationSearchKey(title, options);
let searchResult = searchUrisByQuery[normalizedSearchQuery];
if (searchResult) { if (searchResult) {
// Filter from recommended: The same claim and blocked channels // Filter from recommended: The same claim and blocked channels