Simplify makeSelectTitleForUri

No need to memo given no transformation.
This commit is contained in:
infinite-persistence 2021-11-16 12:23:18 +08:00
parent d03b3fd50d
commit bf324a1b79
No known key found for this signature in database
GPG key ID: B9C3252EDC3D0AA0
21 changed files with 47 additions and 44 deletions

View file

@ -1,6 +1,6 @@
import { connect } from 'react-redux';
import {
makeSelectTitleForUri,
selectTitleForUri,
selectThumbnailForUri,
makeSelectCoverForUri,
makeSelectMetadataItemForUri,
@ -21,7 +21,7 @@ import ChannelForm from './view';
const select = (state, props) => ({
claim: makeSelectClaimForUri(props.uri)(state),
title: makeSelectTitleForUri(props.uri)(state),
title: selectTitleForUri(state, props.uri),
thumbnailUrl: selectThumbnailForUri(state, props.uri),
coverUrl: makeSelectCoverForUri(props.uri)(state),
description: makeSelectMetadataItemForUri(props.uri, 'description')(state),

View file

@ -1,9 +1,9 @@
import { connect } from 'react-redux';
import { makeSelectClaimForUri, makeSelectTitleForUri } from 'redux/selectors/claims';
import { makeSelectClaimForUri, selectTitleForUri } from 'redux/selectors/claims';
import ChannelTitle from './view';
const select = (state, props) => ({
title: makeSelectTitleForUri(props.uri)(state),
title: selectTitleForUri(state, props.uri),
claim: makeSelectClaimForUri(props.uri)(state),
});

View file

@ -7,7 +7,7 @@ import {
makeSelectReflectingClaimForUri,
makeSelectClaimWasPurchased,
isStreamPlaceholderClaim,
makeSelectTitleForUri,
selectTitleForUri,
selectDateForUri,
} from 'redux/selectors/claims';
import { makeSelectStreamingUrlForUri } from 'redux/selectors/file_info';
@ -39,7 +39,7 @@ const select = (state, props) => {
claim,
mediaDuration,
date: props.uri && selectDateForUri(state, props.uri),
title: props.uri && makeSelectTitleForUri(props.uri)(state),
title: props.uri && selectTitleForUri(state, props.uri),
pending: props.uri && makeSelectClaimIsPending(props.uri)(state),
reflectingProgress: props.uri && makeSelectReflectingClaimForUri(props.uri)(state),
obscureNsfw: selectShowMatureContent(state) === false,

View file

@ -3,7 +3,7 @@ import {
makeSelectClaimForUri,
makeSelectIsUriResolving,
getThumbnailFromClaim,
makeSelectTitleForUri,
selectTitleForUri,
isStreamPlaceholderClaim,
selectDateForUri,
} from 'redux/selectors/claims';
@ -28,7 +28,7 @@ const select = (state, props) => {
date: props.uri && selectDateForUri(state, props.uri),
isResolvingUri: props.uri && makeSelectIsUriResolving(props.uri)(state),
thumbnail: getThumbnailFromClaim(claim),
title: props.uri && makeSelectTitleForUri(props.uri)(state),
title: props.uri && selectTitleForUri(state, props.uri),
banState: selectBanStateForUri(state, props.uri),
showMature: selectShowMatureContent(state),
isMature: claim ? isClaimNsfw(claim) : false,

View file

@ -1,10 +1,10 @@
import { connect } from 'react-redux';
import { makeSelectClaimForUri, makeSelectTitleForUri } from 'redux/selectors/claims';
import { makeSelectClaimForUri, selectTitleForUri } from 'redux/selectors/claims';
import ClaimPreviewTitle from './view';
const select = (state, props) => ({
claim: makeSelectClaimForUri(props.uri)(state),
title: makeSelectTitleForUri(props.uri)(state),
title: selectTitleForUri(state, props.uri),
});
export default connect(select)(ClaimPreviewTitle);

View file

@ -1,6 +1,6 @@
import { connect } from 'react-redux';
import {
makeSelectTitleForUri,
selectTitleForUri,
selectThumbnailForUri,
makeSelectMetadataItemForUri,
makeSelectAmountForUri,
@ -25,7 +25,7 @@ import { doSetActiveChannel, doSetIncognito } from 'redux/actions/app';
const select = (state, props) => ({
claim: makeSelectClaimForUri(props.uri)(state),
title: makeSelectTitleForUri(props.uri)(state),
title: selectTitleForUri(state, props.uri),
thumbnailUrl: selectThumbnailForUri(state, props.uri),
description: makeSelectMetadataItemForUri(props.uri, 'description')(state),
tags: makeSelectMetadataItemForUri(props.uri, 'tags')(state),

View file

@ -2,7 +2,7 @@ import { connect } from 'react-redux';
import {
makeSelectIsUriResolving,
getThumbnailFromClaim,
makeSelectTitleForUri,
selectTitleForUri,
makeSelectChannelForClaimUri,
selectClaimIsNsfwForUri,
selectClaimIdForUri,
@ -41,7 +41,7 @@ const select = (state, props) => {
channelClaim: collectionUri && makeSelectChannelForClaimUri(collectionUri)(state),
isResolvingUri: collectionUri && makeSelectIsUriResolving(collectionUri)(state),
thumbnail: getThumbnailFromClaim(claim),
title: collectionUri && makeSelectTitleForUri(collectionUri)(state),
title: collectionUri && selectTitleForUri(state, collectionUri),
blackListedOutpoints: selectBlackListedOutpoints(state),
filteredOutpoints: selectFilteredOutpoints(state),
blockedChannelUris: selectMutedChannels(state),

View file

@ -1,5 +1,5 @@
import { connect } from 'react-redux';
import { makeSelectTitleForUri, selectClaimIsNsfwForUri, makeSelectClaimWasPurchased } from 'redux/selectors/claims';
import { selectTitleForUri, selectClaimIsNsfwForUri, makeSelectClaimWasPurchased } from 'redux/selectors/claims';
import { makeSelectFileInfoForUri, makeSelectStreamingUrlForUri } from 'redux/selectors/file_info';
import {
makeSelectNextUrlForCollectionAndUrl,
@ -30,7 +30,7 @@ const select = (state, props) => {
uri,
primaryUri,
playingUri,
title: makeSelectTitleForUri(uri)(state),
title: selectTitleForUri(state, uri),
fileInfo: makeSelectFileInfoForUri(uri)(state),
mature: selectClaimIsNsfwForUri(state, uri),
isFloating: makeSelectIsPlayerFloating(props.location)(state),

View file

@ -1,9 +1,9 @@
import { connect } from 'react-redux';
import { makeSelectTitleForUri } from 'redux/selectors/claims';
import { selectTitleForUri } from 'redux/selectors/claims';
import FileTitleSection from './view';
const select = (state, props) => ({
title: makeSelectTitleForUri(props.uri)(state),
title: selectTitleForUri(state, props.uri),
});
export default connect(select)(FileTitleSection);

View file

@ -1,6 +1,6 @@
import { connect } from 'react-redux';
import { doFetchSubCount, selectSubCountForUri } from 'lbryinc';
import { makeSelectTitleForUri, makeSelectClaimForUri } from 'redux/selectors/claims';
import { selectTitleForUri, makeSelectClaimForUri } from 'redux/selectors/claims';
import { makeSelectInsufficientCreditsForUri } from 'redux/selectors/content';
import { makeSelectViewersForId } from 'redux/selectors/livestream';
import FileTitleSection from './view';
@ -15,7 +15,7 @@ const select = (state, props) => {
return {
viewers,
isInsufficientCredits: makeSelectInsufficientCreditsForUri(props.uri)(state),
title: makeSelectTitleForUri(props.uri)(state),
title: selectTitleForUri(state, props.uri),
channelClaimId,
subCount,
};

View file

@ -1,11 +1,11 @@
import { connect } from 'react-redux';
import fileViewerEmbeddedTitle from './view';
import { makeSelectTagInClaimOrChannelForUri, makeSelectTitleForUri } from 'redux/selectors/claims';
import { makeSelectTagInClaimOrChannelForUri, selectTitleForUri } from 'redux/selectors/claims';
import { PREFERENCE_EMBED } from 'constants/tags';
export default connect((state, props) => {
return {
title: makeSelectTitleForUri(props.uri)(state),
title: selectTitleForUri(state, props.uri),
preferEmbed: makeSelectTagInClaimOrChannelForUri(props.uri, PREFERENCE_EMBED)(state),
};
})(fileViewerEmbeddedTitle);

View file

@ -1,7 +1,7 @@
import { connect } from 'react-redux';
import {
selectClaimIsMine,
makeSelectTitleForUri,
selectTitleForUri,
getThumbnailFromClaim,
selectClaimForUri,
makeSelectIsUriResolving,
@ -17,7 +17,7 @@ const select = (state, props) => {
return {
uri: props.uri,
claim,
title: makeSelectTitleForUri(props.uri)(state),
title: selectTitleForUri(state, props.uri),
thumbnail: getThumbnailFromClaim(claim),
description: makeSelectMetadataItemForUri(props.uri, 'description')(state),
channelIsMine: selectClaimIsMine(state, claim),

View file

@ -2,7 +2,7 @@ import { connect } from 'react-redux';
import { doHideModal } from 'redux/actions/app';
import {
makeSelectClaimForUri,
makeSelectTitleForUri,
selectTitleForUri,
selectRepostError,
selectRepostLoading,
selectMyClaimsWithoutChannels,
@ -29,7 +29,7 @@ const select = (state, props) => ({
enteredContentClaim: makeSelectClaimForUri(props.contentUri)(state),
enteredRepostClaim: makeSelectClaimForUri(props.repostUri, false)(state),
enteredRepostAmount: makeSelectEffectiveAmountForUri(props.repostUri)(state),
title: makeSelectTitleForUri(props.uri)(state),
title: selectTitleForUri(state, props.uri),
balance: selectBalance(state),
error: selectRepostError(state),
reposting: selectRepostLoading(state),

View file

@ -4,7 +4,7 @@ import { selectHasNavigated, selectScrollStartingPosition, selectWelcomeVersion
import { selectHomepageData } from 'redux/selectors/settings';
import Router from './view';
import { normalizeURI } from 'util/lbryURI';
import { makeSelectTitleForUri } from 'redux/selectors/claims';
import { selectTitleForUri } from 'redux/selectors/claims';
import { doSetHasNavigated } from 'redux/actions/app';
import { doUserSetReferrer } from 'redux/actions/user';
import { selectHasUnclaimedRefereeReward } from 'redux/selectors/rewards';
@ -28,7 +28,7 @@ const select = (state) => {
return {
uri,
title: makeSelectTitleForUri(uri)(state),
title: selectTitleForUri(state, uri),
currentScroll: selectScrollStartingPosition(state),
isAuthenticated: selectUserVerifiedEmail(state),
welcomeVersion: selectWelcomeVersion(state),

View file

@ -1,5 +1,5 @@
import { connect } from 'react-redux';
import { makeSelectClaimForUri, makeSelectTitleForUri } from 'redux/selectors/claims';
import { makeSelectClaimForUri, selectTitleForUri } from 'redux/selectors/claims';
import SocialShare from './view';
import { selectUserInviteReferralCode, selectUser } from 'redux/selectors/user';
import { makeSelectContentPositionForUri } from 'redux/selectors/content';
@ -8,7 +8,7 @@ const select = (state, props) => ({
claim: makeSelectClaimForUri(props.uri)(state),
referralCode: selectUserInviteReferralCode(state),
user: selectUser(state),
title: makeSelectTitleForUri(props.uri)(state),
title: selectTitleForUri(state, props.uri),
position: makeSelectContentPositionForUri(props.uri)(state),
});

View file

@ -1,6 +1,6 @@
import { connect } from 'react-redux';
import {
makeSelectTitleForUri,
selectTitleForUri,
makeSelectClaimForUri,
selectClaimIsMineForUri,
selectFetchingMyChannels,
@ -24,7 +24,7 @@ const select = (state, props) => ({
instantTipEnabled: makeSelectClientSetting(SETTINGS.INSTANT_PURCHASE_ENABLED)(state),
instantTipMax: makeSelectClientSetting(SETTINGS.INSTANT_PURCHASE_MAX)(state),
isPending: selectIsSendingSupport(state),
title: makeSelectTitleForUri(props.uri)(state),
title: selectTitleForUri(state, props.uri),
});
export default withRouter(connect(select, { doHideModal, doSendTip, doSendCashTip })(WalletSendTip));

View file

@ -1,7 +1,7 @@
import { connect } from 'react-redux';
import { doDeleteFileAndMaybeGoBack } from 'redux/actions/file';
import {
makeSelectTitleForUri,
selectTitleForUri,
makeSelectClaimForUri,
makeSelectIsAbandoningClaimForUri,
selectClaimIsMineForUri,
@ -12,7 +12,7 @@ import ModalRemoveFile from './view';
const select = (state, props) => ({
claimIsMine: selectClaimIsMineForUri(state, props.uri),
title: makeSelectTitleForUri(props.uri)(state),
title: selectTitleForUri(state, props.uri),
claim: makeSelectClaimForUri(props.uri)(state),
isAbandoning: makeSelectIsAbandoningClaimForUri(props.uri)(state),
});

View file

@ -1,7 +1,7 @@
import { connect } from 'react-redux';
import {
selectClaimIsMine,
makeSelectTitleForUri,
selectTitleForUri,
getThumbnailFromClaim,
makeSelectCoverForUri,
selectCurrentChannelPage,
@ -21,7 +21,7 @@ const select = (state, props) => {
const claim = selectClaimForUri(state, props.uri);
return {
title: makeSelectTitleForUri(props.uri)(state),
title: selectTitleForUri(state, props.uri),
thumbnail: getThumbnailFromClaim(claim),
cover: makeSelectCoverForUri(props.uri)(state),
channelIsMine: selectClaimIsMine(state, claim),

View file

@ -3,7 +3,7 @@ import { connect } from 'react-redux';
import { withRouter } from 'react-router-dom';
import CollectionPage from './view';
import {
makeSelectTitleForUri,
selectTitleForUri,
getThumbnailFromClaim,
selectClaimIsMine,
makeSelectClaimIsPending,
@ -38,7 +38,7 @@ const select = (state, props) => {
collectionUrls: makeSelectUrlsForCollectionId(collectionId)(state),
collectionCount: makeSelectCountForCollectionId(collectionId)(state),
isResolvingCollection: makeSelectIsResolvingCollectionForId(collectionId)(state),
title: makeSelectTitleForUri(uri)(state),
title: selectTitleForUri(state, uri),
thumbnail: getThumbnailFromClaim(claim),
isMyClaim: selectClaimIsMine(state, claim), // or collection is mine?
isMyCollection: makeSelectCollectionIsMine(collectionId)(state),

View file

@ -7,7 +7,7 @@ import {
makeSelectClaimForUri,
makeSelectIsUriResolving,
makeSelectTotalPagesForChannel,
makeSelectTitleForUri,
selectTitleForUri,
selectClaimIsMine,
makeSelectClaimIsPending,
selectIsStreamPlaceholderForUri,
@ -76,7 +76,7 @@ const select = (state, props) => {
blackListedOutpoints: selectBlackListedOutpoints(state),
totalPages: makeSelectTotalPagesForChannel(uri, PAGE_SIZE)(state),
isSubscribed: makeSelectChannelInSubscriptions(uri)(state),
title: makeSelectTitleForUri(uri)(state),
title: selectTitleForUri(state, uri),
claimIsMine: selectClaimIsMine(state, claim),
claimIsPending: makeSelectClaimIsPending(uri)(state),
isLivestream: selectIsStreamPlaceholderForUri(state, uri),

View file

@ -332,10 +332,11 @@ export const makeSelectTotalPagesInChannelSearch = (uri: string) =>
return byChannel['pageCount'];
});
export const selectMetadataForUri = createCachedSelector(selectClaimForUri, (claim, uri) => {
export const selectMetadataForUri = (state: State, uri: string) => {
const claim = selectClaimForUri(state, uri);
const metadata = claim && claim.value;
return metadata || (claim === undefined ? undefined : null);
})((state, uri) => String(uri));
};
export const makeSelectMetadataForUri = (uri: string) =>
createSelector(makeSelectClaimForUri(uri), (claim) => {
@ -348,8 +349,10 @@ export const makeSelectMetadataItemForUri = (uri: string, key: string) =>
return metadata ? metadata[key] : undefined;
});
export const makeSelectTitleForUri = (uri: string) =>
createSelector(makeSelectMetadataForUri(uri), (metadata) => metadata && metadata.title);
export const selectTitleForUri = (state: State, uri: string) => {
const metadata = selectMetadataForUri(state, uri);
return metadata && metadata.title;
};
export const selectDateForUri = createCachedSelector(
selectClaimForUri, // input: (state, uri, ?returnRepost)