Cost Info selector fixes
- no memo required since they are just directly accessing the store.
This commit is contained in:
parent
b351617d2f
commit
0941667150
17 changed files with 52 additions and 72 deletions
|
@ -40,8 +40,8 @@ export { syncReducer } from './redux/reducers/sync';
|
|||
// selectors
|
||||
export { selectAuthToken, selectIsAuthenticating } from './redux/selectors/auth';
|
||||
export {
|
||||
makeSelectFetchingCostInfoForUri,
|
||||
makeSelectCostInfoForUri,
|
||||
selectFetchingCostInfoForUri,
|
||||
selectCostInfoForUri,
|
||||
selectAllCostInfoByUri,
|
||||
selectFetchingCostInfo,
|
||||
} from './redux/selectors/cost_info';
|
||||
|
|
|
@ -1,13 +1,16 @@
|
|||
import { createSelector } from 'reselect';
|
||||
// @flow
|
||||
type State = { costInfo: any };
|
||||
|
||||
export const selectState = state => state.costInfo || {};
|
||||
export const selectState = (state: State) => state.costInfo || {};
|
||||
export const selectAllCostInfoByUri = (state: State) => selectState(state).byUri;
|
||||
export const selectFetchingCostInfo = (state: State) => selectState(state).fetching;
|
||||
|
||||
export const selectAllCostInfoByUri = createSelector(selectState, state => state.byUri || {});
|
||||
export const selectCostInfoForUri = (state: State, uri: string) => {
|
||||
const costInfos = selectAllCostInfoByUri(state);
|
||||
return costInfos && costInfos[uri];
|
||||
};
|
||||
|
||||
export const makeSelectCostInfoForUri = uri =>
|
||||
createSelector(selectAllCostInfoByUri, costInfos => costInfos && costInfos[uri]);
|
||||
|
||||
export const selectFetchingCostInfo = createSelector(selectState, state => state.fetching || {});
|
||||
|
||||
export const makeSelectFetchingCostInfoForUri = uri =>
|
||||
createSelector(selectFetchingCostInfo, fetchingByUri => fetchingByUri && fetchingByUri[uri]);
|
||||
export const selectFetchingCostInfoForUri = (state: State, uri: string) => {
|
||||
const fetchingByUri = selectFetchingCostInfo(state);
|
||||
return fetchingByUri && fetchingByUri[uri];
|
||||
};
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
import { connect } from 'react-redux';
|
||||
import { makeSelectInsufficientCreditsForUri } from 'redux/selectors/content';
|
||||
import { selectInsufficientCreditsForUri } from 'redux/selectors/content';
|
||||
import { makeSelectClaimWasPurchased } from 'redux/selectors/claims';
|
||||
import ClaimInsufficientCredits from './view';
|
||||
|
||||
const select = (state, props) => ({
|
||||
isInsufficientCredits: makeSelectInsufficientCreditsForUri(props.uri)(state),
|
||||
isInsufficientCredits: selectInsufficientCreditsForUri(state, props.uri),
|
||||
claimWasPurchased: makeSelectClaimWasPurchased(props.uri)(state),
|
||||
});
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ import { connect } from 'react-redux';
|
|||
import { selectThumbnailForUri, makeSelectClaimForUri } from 'redux/selectors/claims';
|
||||
import { doResolveUri } from 'redux/actions/claims';
|
||||
import * as SETTINGS from 'constants/settings';
|
||||
import { doFetchCostInfoForUri, makeSelectCostInfoForUri } from 'lbryinc';
|
||||
import { doFetchCostInfoForUri, selectCostInfoForUri } from 'lbryinc';
|
||||
import { doPlayUri, doSetPlayingUri } from 'redux/actions/content';
|
||||
import { doAnaltyicsPurchaseEvent } from 'redux/actions/app';
|
||||
import { makeSelectClientSetting } from 'redux/selectors/settings';
|
||||
|
@ -14,7 +14,7 @@ const select = (state, props) => ({
|
|||
thumbnail: selectThumbnailForUri(state, props.uri),
|
||||
claim: makeSelectClaimForUri(props.uri)(state),
|
||||
floatingPlayerEnabled: makeSelectClientSetting(SETTINGS.FLOATING_PLAYER)(state),
|
||||
costInfo: makeSelectCostInfoForUri(props.uri)(state),
|
||||
costInfo: selectCostInfoForUri(state, props.uri),
|
||||
renderMode: makeSelectFileRenderModeForUri(props.uri)(state),
|
||||
});
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ import {
|
|||
import { makeSelectStreamingUrlForUri, makeSelectFileInfoForUri } from 'redux/selectors/file_info';
|
||||
import { doPrepareEdit } from 'redux/actions/publish';
|
||||
import { DISABLE_COMMENTS_TAG } from 'constants/tags';
|
||||
import { makeSelectCostInfoForUri } from 'lbryinc';
|
||||
import { selectCostInfoForUri } from 'lbryinc';
|
||||
import { doSetPlayingUri, doPlayUri } from 'redux/actions/content';
|
||||
import { doToast } from 'redux/actions/notifications';
|
||||
import { doOpenModal, doSetActiveChannel, doSetIncognito, doAnalyticsView } from 'redux/actions/app';
|
||||
|
@ -25,7 +25,7 @@ const select = (state, props) => {
|
|||
claimIsMine: selectClaimIsMine(state, claim),
|
||||
fileInfo: makeSelectFileInfoForUri(props.uri)(state),
|
||||
renderMode: makeSelectFileRenderModeForUri(props.uri)(state),
|
||||
costInfo: makeSelectCostInfoForUri(props.uri)(state),
|
||||
costInfo: selectCostInfoForUri(state, props.uri),
|
||||
hasChannels: selectHasChannels(state),
|
||||
isLivestreamClaim: selectIsStreamPlaceholderForUri(state, props.uri),
|
||||
reactionsDisabled: makeSelectTagInClaimOrChannelForUri(props.uri, DISABLE_COMMENTS_TAG)(state),
|
||||
|
|
|
@ -6,7 +6,7 @@ import {
|
|||
makeSelectLoadingForUri,
|
||||
makeSelectStreamingUrlForUri,
|
||||
} from 'redux/selectors/file_info';
|
||||
import { makeSelectCostInfoForUri } from 'lbryinc';
|
||||
import { selectCostInfoForUri } from 'lbryinc';
|
||||
import { doOpenModal, doAnalyticsView } from 'redux/actions/app';
|
||||
import { doSetPlayingUri, doPlayUri } from 'redux/actions/content';
|
||||
import FileDownloadLink from './view';
|
||||
|
@ -20,7 +20,7 @@ const select = (state, props) => {
|
|||
loading: makeSelectLoadingForUri(props.uri)(state),
|
||||
claimIsMine: selectClaimIsMine(state, claim),
|
||||
claim,
|
||||
costInfo: makeSelectCostInfoForUri(props.uri)(state),
|
||||
costInfo: selectCostInfoForUri(state, props.uri),
|
||||
claimWasPurchased: makeSelectClaimWasPurchased(props.uri)(state),
|
||||
streamingUrl: makeSelectStreamingUrlForUri(props.uri)(state),
|
||||
};
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { connect } from 'react-redux';
|
||||
import { selectClaimForUri, makeSelectClaimWasPurchased, selectClaimIsMine } from 'redux/selectors/claims';
|
||||
import { makeSelectCostInfoForUri, doFetchCostInfoForUri, makeSelectFetchingCostInfoForUri } from 'lbryinc';
|
||||
import { selectCostInfoForUri, doFetchCostInfoForUri, selectFetchingCostInfoForUri } from 'lbryinc';
|
||||
import FilePrice from './view';
|
||||
|
||||
const select = (state, props) => {
|
||||
|
@ -10,8 +10,8 @@ const select = (state, props) => {
|
|||
claim,
|
||||
claimIsMine: selectClaimIsMine(state, claim),
|
||||
claimWasPurchased: makeSelectClaimWasPurchased(props.uri)(state),
|
||||
costInfo: makeSelectCostInfoForUri(props.uri)(state),
|
||||
fetching: makeSelectFetchingCostInfoForUri(props.uri)(state),
|
||||
costInfo: selectCostInfoForUri(state, props.uri),
|
||||
fetching: selectFetchingCostInfoForUri(state, props.uri),
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ import {
|
|||
makeSelectFileRenderModeForUri,
|
||||
} from 'redux/selectors/content';
|
||||
import { makeSelectClientSetting } from 'redux/selectors/settings';
|
||||
import { makeSelectCostInfoForUri } from 'lbryinc';
|
||||
import { selectCostInfoForUri } from 'lbryinc';
|
||||
import { doPlayUri, doSetPlayingUri } from 'redux/actions/content';
|
||||
import { doFetchRecommendedContent } from 'redux/actions/search';
|
||||
import { doAnaltyicsPurchaseEvent } from 'redux/actions/app';
|
||||
|
@ -38,7 +38,7 @@ const select = (state, props) => {
|
|||
floatingPlayerEnabled: makeSelectClientSetting(SETTINGS.FLOATING_PLAYER)(state),
|
||||
renderMode: makeSelectFileRenderModeForUri(uri)(state),
|
||||
videoTheaterMode: makeSelectClientSetting(SETTINGS.VIDEO_THEATER_MODE)(state),
|
||||
costInfo: makeSelectCostInfoForUri(uri)(state),
|
||||
costInfo: selectCostInfoForUri(state, uri),
|
||||
claimWasPurchased: makeSelectClaimWasPurchased(uri)(state),
|
||||
nextListUri: collectionId && makeSelectNextUrlForCollectionAndUrl(collectionId, uri)(state),
|
||||
previousListUri: collectionId && makeSelectPreviousUrlForCollectionAndUrl(collectionId, uri)(state),
|
||||
|
|
|
@ -4,14 +4,14 @@ import { selectThumbnailForUri, makeSelectClaimForUri, makeSelectClaimWasPurchas
|
|||
import { makeSelectFileInfoForUri } from 'redux/selectors/file_info';
|
||||
import * as SETTINGS from 'constants/settings';
|
||||
import * as COLLECTIONS_CONSTS from 'constants/collections';
|
||||
import { makeSelectCostInfoForUri } from 'lbryinc';
|
||||
import { selectCostInfoForUri } from 'lbryinc';
|
||||
import { selectUserVerifiedEmail } from 'redux/selectors/user';
|
||||
import { makeSelectClientSetting } from 'redux/selectors/settings';
|
||||
import { withRouter } from 'react-router';
|
||||
import {
|
||||
makeSelectIsPlaying,
|
||||
selectShouldObscurePreviewForUri,
|
||||
makeSelectInsufficientCreditsForUri,
|
||||
selectInsufficientCreditsForUri,
|
||||
makeSelectFileRenderModeForUri,
|
||||
} from 'redux/selectors/content';
|
||||
import FileRenderInitiator from './view';
|
||||
|
@ -27,9 +27,9 @@ const select = (state, props) => {
|
|||
fileInfo: makeSelectFileInfoForUri(props.uri)(state),
|
||||
obscurePreview: selectShouldObscurePreviewForUri(state, props.uri),
|
||||
isPlaying: makeSelectIsPlaying(props.uri)(state),
|
||||
insufficientCredits: makeSelectInsufficientCreditsForUri(props.uri)(state),
|
||||
insufficientCredits: selectInsufficientCreditsForUri(state, props.uri),
|
||||
autoplay: makeSelectClientSetting(SETTINGS.AUTOPLAY_MEDIA)(state),
|
||||
costInfo: makeSelectCostInfoForUri(props.uri)(state),
|
||||
costInfo: selectCostInfoForUri(state, props.uri),
|
||||
renderMode: makeSelectFileRenderModeForUri(props.uri)(state),
|
||||
claim: makeSelectClaimForUri(props.uri)(state),
|
||||
claimWasPurchased: makeSelectClaimWasPurchased(props.uri)(state),
|
||||
|
|
|
@ -6,14 +6,14 @@ import { makeSelectFileRenderModeForUri, selectPrimaryUri } from 'redux/selector
|
|||
import { withRouter } from 'react-router';
|
||||
import { doAnalyticsView } from 'redux/actions/app';
|
||||
import FileRenderInline from './view';
|
||||
import { makeSelectCostInfoForUri } from 'lbryinc';
|
||||
import { selectCostInfoForUri } from 'lbryinc';
|
||||
|
||||
const select = (state, props) => ({
|
||||
fileInfo: makeSelectFileInfoForUri(props.uri)(state),
|
||||
isPlaying: selectPrimaryUri(state) === props.uri,
|
||||
streamingUrl: makeSelectStreamingUrlForUri(props.uri)(state),
|
||||
renderMode: makeSelectFileRenderModeForUri(props.uri)(state),
|
||||
costInfo: makeSelectCostInfoForUri(props.uri)(state),
|
||||
costInfo: selectCostInfoForUri(state, props.uri),
|
||||
claimWasPurchased: makeSelectClaimWasPurchased(props.uri)(state),
|
||||
});
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { connect } from 'react-redux';
|
||||
import { doFetchSubCount, selectSubCountForUri } from 'lbryinc';
|
||||
import { selectTitleForUri, selectClaimForUri } from 'redux/selectors/claims';
|
||||
import { makeSelectInsufficientCreditsForUri } from 'redux/selectors/content';
|
||||
import { selectInsufficientCreditsForUri } from 'redux/selectors/content';
|
||||
import FileTitleSection from './view';
|
||||
|
||||
const select = (state, props) => {
|
||||
|
@ -11,7 +11,7 @@ const select = (state, props) => {
|
|||
const subCount = channelUri && selectSubCountForUri(state, channelUri);
|
||||
|
||||
return {
|
||||
isInsufficientCredits: makeSelectInsufficientCreditsForUri(props.uri)(state),
|
||||
isInsufficientCredits: selectInsufficientCreditsForUri(state, props.uri),
|
||||
title: selectTitleForUri(state, props.uri),
|
||||
channelClaimId,
|
||||
subCount,
|
||||
|
|
|
@ -5,7 +5,7 @@ import { makeSelectStreamingUrlForUri } from 'redux/selectors/file_info';
|
|||
import { doResolveUri } from 'redux/actions/claims';
|
||||
import { buildURI } from 'util/lbryURI';
|
||||
import { doPlayUri } from 'redux/actions/content';
|
||||
import { makeSelectCostInfoForUri, doFetchCostInfoForUri, selectBlackListedOutpoints } from 'lbryinc';
|
||||
import { selectCostInfoForUri, doFetchCostInfoForUri, selectBlackListedOutpoints } from 'lbryinc';
|
||||
|
||||
const select = (state, props) => {
|
||||
const { match } = props;
|
||||
|
@ -15,7 +15,7 @@ const select = (state, props) => {
|
|||
return {
|
||||
uri,
|
||||
claim: makeSelectClaimForUri(uri)(state),
|
||||
costInfo: makeSelectCostInfoForUri(uri)(state),
|
||||
costInfo: selectCostInfoForUri(state, uri),
|
||||
streamingUrl: makeSelectStreamingUrlForUri(uri)(state),
|
||||
isResolvingUri: selectIsUriResolving(state, uri),
|
||||
blackListedOutpoints: selectBlackListedOutpoints(state),
|
||||
|
|
|
@ -11,7 +11,7 @@ import { doFetchFileInfo } from 'redux/actions/file_info';
|
|||
import { makeSelectCollectionForId } from 'redux/selectors/collections';
|
||||
import * as COLLECTIONS_CONSTS from 'constants/collections';
|
||||
import * as SETTINGS from 'constants/settings';
|
||||
import { makeSelectCostInfoForUri, doFetchCostInfoForUri } from 'lbryinc';
|
||||
import { selectCostInfoForUri, doFetchCostInfoForUri } from 'lbryinc';
|
||||
import { selectShowMatureContent, makeSelectClientSetting } from 'redux/selectors/settings';
|
||||
import { makeSelectFileRenderModeForUri, makeSelectContentPositionForUri } from 'redux/selectors/content';
|
||||
import { DISABLE_COMMENTS_TAG } from 'constants/tags';
|
||||
|
@ -25,7 +25,7 @@ const select = (state, props) => {
|
|||
|
||||
return {
|
||||
linkedCommentId: urlParams.get('lc'),
|
||||
costInfo: makeSelectCostInfoForUri(props.uri)(state),
|
||||
costInfo: selectCostInfoForUri(state, props.uri),
|
||||
obscureNsfw: !selectShowMatureContent(state),
|
||||
isMature: selectClaimIsNsfwForUri(state, props.uri),
|
||||
fileInfo: makeSelectFileInfoForUri(props.uri)(state),
|
||||
|
|
|
@ -17,7 +17,7 @@ import { doToast } from 'redux/actions/notifications';
|
|||
import { doPurchaseUri } from 'redux/actions/file';
|
||||
import Lbry from 'lbry';
|
||||
import * as SETTINGS from 'constants/settings';
|
||||
import { makeSelectCostInfoForUri, Lbryio } from 'lbryinc';
|
||||
import { selectCostInfoForUri, Lbryio } from 'lbryinc';
|
||||
import { makeSelectClientSetting, selectosNotificationsEnabled, selectDaemonSettings } from 'redux/selectors/settings';
|
||||
|
||||
const DOWNLOAD_POLL_INTERVAL = 1000;
|
||||
|
@ -164,7 +164,7 @@ export function doPlayUri(
|
|||
}
|
||||
|
||||
const daemonSettings = selectDaemonSettings(state);
|
||||
const costInfo = makeSelectCostInfoForUri(uri)(state);
|
||||
const costInfo = selectCostInfoForUri(state, uri);
|
||||
const cost = (costInfo && Number(costInfo.cost)) || 0;
|
||||
const saveFile = !IS_WEB && (!uriIsStreamable ? true : daemonSettings.save_files || saveFileOverride || cost > 0);
|
||||
const instantPurchaseEnabled = makeSelectClientSetting(SETTINGS.INSTANT_PURCHASE_ENABLED)(state);
|
||||
|
|
|
@ -22,7 +22,7 @@ import {
|
|||
} from 'redux/selectors/file_info';
|
||||
|
||||
type Dispatch = (action: any) => any;
|
||||
type GetState = () => { file: FileState, content: any };
|
||||
type GetState = () => { claims: any, file: FileState, content: any };
|
||||
export function doOpenFileInFolder(path: string) {
|
||||
return () => {
|
||||
shell.showItemInFolder(path);
|
||||
|
|
|
@ -247,26 +247,6 @@ export const selectClaimIsMineForUri = (state: State, rawUri: string) => {
|
|||
return selectClaimIsMine(state, claimsByUri && claimsByUri[uri]);
|
||||
};
|
||||
|
||||
// DEPRECATED - use selectClaimIsMineForUri instead.
|
||||
export const makeSelectClaimIsMine = (rawUri: string) => {
|
||||
let uri;
|
||||
try {
|
||||
uri = normalizeURI(rawUri);
|
||||
} catch (e) {}
|
||||
|
||||
return createSelector(selectClaimsByUri, selectMyActiveClaims, (claims, myClaims) => {
|
||||
if (!isURIValid(uri, false)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return (
|
||||
claims &&
|
||||
claims[uri] &&
|
||||
(claims[uri].is_my_output || (claims[uri].claim_id && myClaims.has(claims[uri].claim_id)))
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
export const selectMyPurchases = (state: State) => selectState(state).myPurchases;
|
||||
export const selectPurchaseUriSuccess = (state: State) => selectState(state).purchaseUriSuccess;
|
||||
export const selectMyPurchasesCount = (state: State) => selectState(state).myPurchasesPageTotalResults;
|
||||
|
|
|
@ -4,12 +4,12 @@ import {
|
|||
makeSelectClaimForUri,
|
||||
selectClaimsByUri,
|
||||
selectClaimIsNsfwForUri,
|
||||
makeSelectClaimIsMine,
|
||||
selectClaimIsMineForUri,
|
||||
makeSelectContentTypeForUri,
|
||||
} from 'redux/selectors/claims';
|
||||
import { makeSelectMediaTypeForUri, makeSelectFileNameForUri } from 'redux/selectors/file_info';
|
||||
import { selectBalance } from 'redux/selectors/wallet';
|
||||
import { makeSelectCostInfoForUri } from 'lbryinc';
|
||||
import { selectCostInfoForUri } from 'lbryinc';
|
||||
import { selectShowMatureContent } from 'redux/selectors/settings';
|
||||
import * as RENDER_MODES from 'constants/file_render_modes';
|
||||
import path from 'path';
|
||||
|
@ -18,7 +18,7 @@ import { FORCE_CONTENT_TYPE_PLAYER, FORCE_CONTENT_TYPE_COMIC } from 'constants/c
|
|||
const RECENT_HISTORY_AMOUNT = 10;
|
||||
const HISTORY_ITEMS_PER_PAGE = 50;
|
||||
|
||||
type State = { content: any };
|
||||
type State = { claims: any, content: any };
|
||||
|
||||
export const selectState = (state: State) => state.content || {};
|
||||
|
||||
|
@ -157,12 +157,9 @@ export const makeSelectFileRenderModeForUri = (uri: string) =>
|
|||
}
|
||||
);
|
||||
|
||||
export const makeSelectInsufficientCreditsForUri = (uri: string) =>
|
||||
createSelector(
|
||||
makeSelectClaimIsMine(uri),
|
||||
makeSelectCostInfoForUri(uri),
|
||||
selectBalance,
|
||||
(isMine, costInfo, balance) => {
|
||||
return !isMine && costInfo && costInfo.cost > 0 && costInfo.cost > balance;
|
||||
}
|
||||
);
|
||||
export const selectInsufficientCreditsForUri = (state: State, uri: string) => {
|
||||
const isMine = selectClaimIsMineForUri(state, uri);
|
||||
const costInfo = selectCostInfoForUri(state, uri);
|
||||
const balance = selectBalance(state);
|
||||
return !isMine && costInfo && costInfo.cost > 0 && costInfo.cost > balance;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue