Add new selector for first item in related content #110

Merged
neb-b merged 2 commits from autoplay-related into master 2019-01-28 21:06:02 +01:00
4 changed files with 79 additions and 64 deletions

View file

@ -1,6 +1,5 @@
{ {
"trailingComma": "es5", "trailingComma": "es5",
"printWidth": 100, "printWidth": 100,
"singleQuote": true, "singleQuote": true
"arrowParens": "always"
} }

18
dist/bundle.js vendored
View file

@ -89,8 +89,8 @@ return /******/ (function(modules) { // webpackBootstrap
Object.defineProperty(exports, "__esModule", { Object.defineProperty(exports, "__esModule", {
value: true value: true
}); });
exports.selectTransactionListFilter = exports.selectWalletUnlockResult = exports.selectWalletUnlockSucceeded = exports.selectWalletUnlockPending = exports.selectWalletDecryptResult = exports.selectWalletDecryptSucceeded = exports.selectWalletDecryptPending = exports.selectWalletEncryptResult = exports.selectWalletEncryptSucceeded = exports.selectWalletEncryptPending = exports.selectWalletState = exports.selectWalletIsEncrypted = exports.selectBlocks = exports.selectDraftTransactionError = exports.selectDraftTransactionAddress = exports.selectDraftTransactionAmount = exports.selectDraftTransaction = exports.selectGettingNewAddress = exports.selectReceiveAddress = exports.selectIsSendingSupport = exports.selectIsFetchingTransactions = exports.selectHasTransactions = exports.selectRecentTransactions = exports.selectTransactionItems = exports.selectTransactionsById = exports.selectBalance = exports.makeSelectBlockDate = exports.selectSearchSuggestions = exports.selectSearchBarFocused = exports.selectWunderBarAddress = exports.selectSearchUrisByQuery = exports.selectIsSearching = exports.selectSearchValue = exports.selectSearchQuery = exports.makeSelectSearchUris = exports.selectSearchState = exports.selectActiveHistoryEntry = exports.selectHistoryStack = exports.selectHistoryIndex = exports.selectIsForwardDisabled = exports.selectIsBackDisabled = exports.selectPathAfterAuth = exports.selectPageTitle = exports.selectHeaderLinks = exports.selectCurrentParams = exports.selectCurrentPage = exports.selectCurrentPath = exports.makeSelectCurrentParam = exports.computePageFromPath = exports.selectFileListPublishedSort = exports.selectFileListDownloadedSort = exports.selectSearchDownloadUris = exports.selectTotalDownloadProgress = exports.selectDownloadingFileInfos = exports.selectFileInfosDownloaded = exports.selectUrisLoading = exports.selectDownloadingByOutpoint = exports.selectIsFetchingFileListDownloadedOrPublished = exports.selectIsFetchingFileList = exports.selectFileInfosByOutpoint = exports.makeSelectLoadingForUri = exports.makeSelectDownloadingForUri = exports.makeSelectFileInfoForUri = exports.selectFetchingCostInfo = exports.selectCostForCurrentPageUri = exports.selectAllCostInfoByUri = exports.makeSelectCostInfoForUri = exports.makeSelectFetchingCostInfoForUri = exports.selectChannelClaimCounts = exports.selectPlayingUri = exports.selectFetchingTrendingUris = exports.selectTrendingUris = exports.selectFetchingFeaturedUris = exports.selectFeaturedUris = exports.selectResolvingUris = exports.selectMyChannelClaims = exports.selectFetchingMyChannels = exports.selectMyClaimsOutpoints = exports.selectAllMyClaimsByOutpoint = exports.selectMyClaimsWithoutChannels = exports.selectMyClaims = undefined; exports.selectTransactionListFilter = exports.selectWalletUnlockResult = exports.selectWalletUnlockSucceeded = exports.selectWalletUnlockPending = exports.selectWalletDecryptResult = exports.selectWalletDecryptSucceeded = exports.selectWalletDecryptPending = exports.selectWalletEncryptResult = exports.selectWalletEncryptSucceeded = exports.selectWalletEncryptPending = exports.selectWalletState = exports.selectWalletIsEncrypted = exports.selectBlocks = exports.selectDraftTransactionError = exports.selectDraftTransactionAddress = exports.selectDraftTransactionAmount = exports.selectDraftTransaction = exports.selectGettingNewAddress = exports.selectReceiveAddress = exports.selectIsSendingSupport = exports.selectIsFetchingTransactions = exports.selectHasTransactions = exports.selectRecentTransactions = exports.selectTransactionItems = exports.selectTransactionsById = exports.selectBalance = exports.makeSelectBlockDate = exports.selectSearchSuggestions = exports.selectSearchBarFocused = exports.selectWunderBarAddress = exports.selectSearchUrisByQuery = exports.selectIsSearching = exports.selectSearchValue = exports.selectSearchQuery = exports.makeSelectSearchUris = exports.selectSearchState = exports.selectActiveHistoryEntry = exports.selectHistoryStack = exports.selectHistoryIndex = exports.selectIsForwardDisabled = exports.selectIsBackDisabled = exports.selectPathAfterAuth = exports.selectPageTitle = exports.selectHeaderLinks = exports.selectCurrentParams = exports.selectCurrentPage = exports.selectCurrentPath = exports.makeSelectCurrentParam = exports.computePageFromPath = exports.selectFileListPublishedSort = exports.selectFileListDownloadedSort = exports.selectSearchDownloadUris = exports.selectTotalDownloadProgress = exports.selectDownloadingFileInfos = exports.selectFileInfosDownloaded = exports.selectUrisLoading = exports.selectDownloadingByOutpoint = exports.selectIsFetchingFileListDownloadedOrPublished = exports.selectIsFetchingFileList = exports.selectFileInfosByOutpoint = exports.makeSelectLoadingForUri = exports.makeSelectDownloadingForUri = exports.makeSelectFileInfoForUri = exports.selectFetchingCostInfo = exports.selectCostForCurrentPageUri = exports.selectAllCostInfoByUri = exports.makeSelectCostInfoForUri = exports.makeSelectFetchingCostInfoForUri = exports.selectChannelClaimCounts = exports.selectPlayingUri = exports.selectFetchingTrendingUris = exports.selectTrendingUris = exports.selectFetchingFeaturedUris = exports.selectFeaturedUris = exports.selectResolvingUris = exports.selectMyChannelClaims = exports.selectFetchingMyChannels = exports.selectMyClaimsOutpoints = exports.selectAllMyClaimsByOutpoint = exports.selectMyClaimsWithoutChannels = exports.selectMyClaims = exports.selectPendingClaims = undefined;
exports.selectPendingClaims = exports.selectIsFetchingClaimListMine = exports.selectAllFetchingChannelClaims = exports.selectMyActiveClaims = exports.selectAbandoningIds = exports.selectMyClaimsRaw = exports.selectAllClaimsByChannel = exports.selectClaimsByUri = exports.selectClaimsById = exports.selectPendingById = exports.makeSelectPendingByUri = exports.makeSelectClaimIsPending = exports.makeSelectChannelForClaimUri = exports.makeSelectRecommendedContentForUri = exports.makeSelectNsfwCountForChannel = exports.makeSelectNsfwCountFromUris = exports.makeSelectTotalPagesForChannel = exports.makeSelectTotalItemsForChannel = exports.makeSelectIsUriResolving = exports.makeSelectContentTypeForUri = exports.makeSelectTitleForUri = exports.makeSelectMetadataForUri = exports.makeSelectClaimsInChannelForPage = exports.makeSelectClaimsInChannelForCurrentPage = exports.makeSelectFetchingChannelClaims = exports.makeSelectClaimIsMine = exports.makeSelectClaimForUri = exports.selectError = exports.selectToast = exports.selectBlackListedOutpoints = exports.blacklistReducer = exports.walletReducer = exports.searchReducer = exports.notificationsReducer = exports.fileInfoReducer = exports.costInfoReducer = exports.claimsReducer = exports.creditsToString = exports.formatFullPrice = exports.formatCredits = exports.toQueryString = exports.parseQueryParams = exports.batchActions = exports.doUpdateBlockHeight = exports.doSetTransactionListFilter = exports.doWalletStatus = exports.doWalletUnlock = exports.doWalletDecrypt = exports.doWalletEncrypt = exports.doSendTip = exports.doSetDraftTransactionAddress = exports.doSetDraftTransactionAmount = exports.doSendDraftTransaction = exports.doCheckAddressIsMine = exports.doGetNewAddress = exports.doFetchBlock = exports.doFetchTransactions = exports.doBalanceSubscribe = exports.doUpdateBalance = exports.doBlackListedOutpointsSubscribe = exports.doBlurSearchInput = exports.doFocusSearchInput = exports.doUpdateSearchQuery = exports.doSearch = exports.doSetFileListSort = exports.doFetchFileInfosAndPublishedClaims = exports.doFileList = exports.doFetchFileInfo = exports.doFetchCostInfoForUri = exports.doFetchTrendingUris = exports.doFetchFeaturedUris = exports.doResolveUri = exports.doResolveUris = exports.doAbandonClaim = exports.doFetchClaimListMine = exports.doFetchClaimCountByChannel = exports.doFetchClaimsByChannel = exports.doDismissError = exports.doError = exports.doDismissToast = exports.doToast = exports.convertToShareLink = exports.isNameValid = exports.isURIClaimable = exports.isURIValid = exports.normalizeURI = exports.buildURI = exports.parseURI = exports.regexAddress = exports.regexInvalidURI = exports.Lbryapi = exports.Lbry = exports.PAGES = exports.SORT_OPTIONS = exports.TRANSACTIONS = exports.SETTINGS = exports.SEARCH_TYPES = exports.THUMBNAIL_STATUSES = exports.ACTIONS = exports.Toast = undefined; exports.selectIsFetchingClaimListMine = exports.selectAllFetchingChannelClaims = exports.selectMyActiveClaims = exports.selectAbandoningIds = exports.selectMyClaimsRaw = exports.selectAllClaimsByChannel = exports.selectClaimsByUri = exports.selectClaimsById = exports.selectPendingById = exports.makeSelectPendingByUri = exports.makeSelectClaimIsPending = exports.makeSelectChannelForClaimUri = exports.makeSelectFirstRecommendedFileForUri = exports.makeSelectRecommendedContentForUri = exports.makeSelectNsfwCountForChannel = exports.makeSelectNsfwCountFromUris = exports.makeSelectTotalPagesForChannel = exports.makeSelectTotalItemsForChannel = exports.makeSelectIsUriResolving = exports.makeSelectContentTypeForUri = exports.makeSelectTitleForUri = exports.makeSelectMetadataForUri = exports.makeSelectClaimsInChannelForPage = exports.makeSelectClaimsInChannelForCurrentPage = exports.makeSelectFetchingChannelClaims = exports.makeSelectClaimIsMine = exports.makeSelectClaimForUri = exports.selectError = exports.selectToast = exports.selectBlackListedOutpoints = exports.blacklistReducer = exports.walletReducer = exports.searchReducer = exports.notificationsReducer = exports.fileInfoReducer = exports.costInfoReducer = exports.claimsReducer = exports.creditsToString = exports.formatFullPrice = exports.formatCredits = exports.toQueryString = exports.parseQueryParams = exports.batchActions = exports.doUpdateBlockHeight = exports.doSetTransactionListFilter = exports.doWalletStatus = exports.doWalletUnlock = exports.doWalletDecrypt = exports.doWalletEncrypt = exports.doSendTip = exports.doSetDraftTransactionAddress = exports.doSetDraftTransactionAmount = exports.doSendDraftTransaction = exports.doCheckAddressIsMine = exports.doGetNewAddress = exports.doFetchBlock = exports.doFetchTransactions = exports.doBalanceSubscribe = exports.doUpdateBalance = exports.doBlackListedOutpointsSubscribe = exports.doBlurSearchInput = exports.doFocusSearchInput = exports.doUpdateSearchQuery = exports.doSearch = exports.doSetFileListSort = exports.doFetchFileInfosAndPublishedClaims = exports.doFileList = exports.doFetchFileInfo = exports.doFetchCostInfoForUri = exports.doFetchTrendingUris = exports.doFetchFeaturedUris = exports.doResolveUri = exports.doResolveUris = exports.doAbandonClaim = exports.doFetchClaimListMine = exports.doFetchClaimCountByChannel = exports.doFetchClaimsByChannel = exports.doDismissError = exports.doError = exports.doDismissToast = exports.doToast = exports.convertToShareLink = exports.isNameValid = exports.isURIClaimable = exports.isURIValid = exports.normalizeURI = exports.buildURI = exports.parseURI = exports.regexAddress = exports.regexInvalidURI = exports.Lbryapi = exports.Lbry = exports.PAGES = exports.SORT_OPTIONS = exports.TRANSACTIONS = exports.SETTINGS = exports.SEARCH_TYPES = exports.THUMBNAIL_STATUSES = exports.ACTIONS = exports.Toast = undefined;
var _Notification = __webpack_require__(1); var _Notification = __webpack_require__(1);
@ -625,6 +625,12 @@ Object.defineProperty(exports, 'makeSelectRecommendedContentForUri', {
return _claims3.makeSelectRecommendedContentForUri; return _claims3.makeSelectRecommendedContentForUri;
} }
}); });
Object.defineProperty(exports, 'makeSelectFirstRecommendedFileForUri', {
enumerable: true,
get: function get() {
return _claims3.makeSelectFirstRecommendedFileForUri;
}
});
Object.defineProperty(exports, 'makeSelectChannelForClaimUri', { Object.defineProperty(exports, 'makeSelectChannelForClaimUri', {
enumerable: true, enumerable: true,
get: function get() { get: function get() {
@ -3258,7 +3264,7 @@ var objectKeys = Object.keys || function (obj) {
Object.defineProperty(exports, "__esModule", { Object.defineProperty(exports, "__esModule", {
value: true value: true
}); });
exports.makeSelectChannelForClaimUri = exports.makeSelectRecommendedContentForUri = exports.makeSelectNsfwCountForChannel = exports.makeSelectNsfwCountFromUris = exports.makeSelectTotalPagesForChannel = exports.makeSelectTotalItemsForChannel = exports.selectChannelClaimCounts = exports.selectPlayingUri = exports.selectFetchingTrendingUris = exports.selectTrendingUris = exports.selectFetchingFeaturedUris = exports.selectFeaturedUris = exports.makeSelectIsUriResolving = exports.selectResolvingUris = exports.selectMyChannelClaims = exports.selectFetchingMyChannels = exports.selectMyClaimsOutpoints = exports.selectAllMyClaimsByOutpoint = exports.selectMyClaimsWithoutChannels = exports.selectMyClaims = exports.selectIsFetchingClaimListMine = exports.makeSelectContentTypeForUri = exports.makeSelectTitleForUri = exports.makeSelectMetadataForUri = exports.makeSelectClaimsInChannelForCurrentPage = exports.makeSelectClaimsInChannelForPage = exports.makeSelectFetchingChannelClaims = exports.selectAllFetchingChannelClaims = exports.makeSelectClaimIsMine = exports.selectMyActiveClaims = exports.selectAbandoningIds = exports.selectMyClaimsRaw = exports.makeSelectClaimForUri = exports.makeSelectPendingByUri = exports.makeSelectClaimIsPending = exports.selectPendingClaims = exports.selectPendingById = exports.selectAllClaimsByChannel = exports.selectClaimsByUri = exports.selectClaimsById = undefined; exports.makeSelectChannelForClaimUri = exports.makeSelectFirstRecommendedFileForUri = exports.makeSelectRecommendedContentForUri = exports.makeSelectNsfwCountForChannel = exports.makeSelectNsfwCountFromUris = exports.makeSelectTotalPagesForChannel = exports.makeSelectTotalItemsForChannel = exports.selectChannelClaimCounts = exports.selectPlayingUri = exports.selectFetchingTrendingUris = exports.selectTrendingUris = exports.selectFetchingFeaturedUris = exports.selectFeaturedUris = exports.makeSelectIsUriResolving = exports.selectResolvingUris = exports.selectMyChannelClaims = exports.selectFetchingMyChannels = exports.selectMyClaimsOutpoints = exports.selectAllMyClaimsByOutpoint = exports.selectMyClaimsWithoutChannels = exports.selectMyClaims = exports.selectIsFetchingClaimListMine = exports.makeSelectContentTypeForUri = exports.makeSelectTitleForUri = exports.makeSelectMetadataForUri = exports.makeSelectClaimsInChannelForCurrentPage = exports.makeSelectClaimsInChannelForPage = exports.makeSelectFetchingChannelClaims = exports.selectAllFetchingChannelClaims = exports.makeSelectClaimIsMine = exports.selectMyActiveClaims = exports.selectAbandoningIds = exports.selectMyClaimsRaw = exports.makeSelectClaimForUri = exports.makeSelectPendingByUri = exports.makeSelectClaimIsPending = exports.selectPendingClaims = exports.selectPendingById = exports.selectAllClaimsByChannel = exports.selectClaimsByUri = exports.selectClaimsById = undefined;
var _lbryURI = __webpack_require__(3); var _lbryURI = __webpack_require__(3);
@ -3587,6 +3593,12 @@ var makeSelectRecommendedContentForUri = exports.makeSelectRecommendedContentFor
}); });
}; };
var makeSelectFirstRecommendedFileForUri = exports.makeSelectFirstRecommendedFileForUri = function makeSelectFirstRecommendedFileForUri(uri) {
return (0, _reselect.createSelector)(makeSelectRecommendedContentForUri(uri), function (recommendedContent) {
return recommendedContent ? recommendedContent[0] : null;
});
};
// Returns the associated channel uri for a given claim uri // Returns the associated channel uri for a given claim uri
var makeSelectChannelForClaimUri = exports.makeSelectChannelForClaimUri = function makeSelectChannelForClaimUri(uri) { var makeSelectChannelForClaimUri = exports.makeSelectChannelForClaimUri = function makeSelectChannelForClaimUri(uri) {
var includePrefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; var includePrefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;

View file

@ -115,6 +115,7 @@ export {
makeSelectNsfwCountFromUris, makeSelectNsfwCountFromUris,
makeSelectNsfwCountForChannel, makeSelectNsfwCountForChannel,
makeSelectRecommendedContentForUri, makeSelectRecommendedContentForUri,
makeSelectFirstRecommendedFileForUri,
makeSelectChannelForClaimUri, makeSelectChannelForClaimUri,
makeSelectClaimIsPending, makeSelectClaimIsPending,
makeSelectPendingByUri, makeSelectPendingByUri,

View file

@ -4,15 +4,15 @@ import { selectSearchUrisByQuery } from 'redux/selectors/search';
import { createSelector } from 'reselect'; import { createSelector } from 'reselect';
import { isClaimNsfw } from 'util/claim'; import { isClaimNsfw } from 'util/claim';
const selectState = (state) => state.claims || {}; const selectState = state => state.claims || {};
neb-b commented 2019-01-28 20:37:54 +01:00 (Migrated from github.com)
Review

We added a prettier rule in this repo for this, but since we aren't using it in other projects, i removed it.

We added a prettier rule in this repo for this, but since we aren't using it in other projects, i removed it.
export const selectClaimsById = createSelector(selectState, (state) => state.byId || {}); export const selectClaimsById = createSelector(selectState, state => state.byId || {});
export const selectClaimsByUri = createSelector(selectState, selectClaimsById, (state, byId) => { export const selectClaimsByUri = createSelector(selectState, selectClaimsById, (state, byId) => {
const byUri = state.claimsByUri || {}; const byUri = state.claimsByUri || {};
const claims = {}; const claims = {};
Object.keys(byUri).forEach((uri) => { Object.keys(byUri).forEach(uri => {
const claimId = byUri[uri]; const claimId = byUri[uri];
// NOTE returning a null claim allows us to differentiate between an // NOTE returning a null claim allows us to differentiate between an
@ -30,28 +30,28 @@ export const selectClaimsByUri = createSelector(selectState, selectClaimsById, (
export const selectAllClaimsByChannel = createSelector( export const selectAllClaimsByChannel = createSelector(
selectState, selectState,
(state) => state.claimsByChannel || {} state => state.claimsByChannel || {}
); );
export const selectPendingById = createSelector(selectState, (state) => state.pendingById || {}); export const selectPendingById = createSelector(selectState, state => state.pendingById || {});
export const selectPendingClaims = createSelector(selectState, (state) => export const selectPendingClaims = createSelector(selectState, state =>
Object.values(state.pendingById || []) Object.values(state.pendingById || [])
); );
export const makeSelectClaimIsPending = (uri) => export const makeSelectClaimIsPending = uri =>
createSelector(selectPendingById, (pendingById) => { createSelector(selectPendingById, pendingById => {
const { claimId } = parseURI(uri); const { claimId } = parseURI(uri);
return Boolean(pendingById[claimId]); return Boolean(pendingById[claimId]);
}); });
export const makeSelectPendingByUri = (uri) => export const makeSelectPendingByUri = uri =>
createSelector(selectPendingById, (pendingById) => { createSelector(selectPendingById, pendingById => {
const { claimId } = parseURI(uri); const { claimId } = parseURI(uri);
return pendingById[claimId]; return pendingById[claimId];
}); });
export const makeSelectClaimForUri = (uri) => export const makeSelectClaimForUri = uri =>
createSelector(selectClaimsByUri, selectPendingById, (byUri, pendingById) => { createSelector(selectClaimsByUri, selectPendingById, (byUri, pendingById) => {
// Check if a claim is pending first // Check if a claim is pending first
// It won't be in claimsByUri because resolving it will return nothing // It won't be in claimsByUri because resolving it will return nothing
@ -64,9 +64,9 @@ export const makeSelectClaimForUri = (uri) =>
return byUri && byUri[normalizeURI(uri)]; return byUri && byUri[normalizeURI(uri)];
}); });
export const selectMyClaimsRaw = createSelector(selectState, (state) => state.myClaims); export const selectMyClaimsRaw = createSelector(selectState, state => state.myClaims);
export const selectAbandoningIds = createSelector(selectState, (state) => export const selectAbandoningIds = createSelector(selectState, state =>
Object.keys(state.abandoningById || {}) Object.keys(state.abandoningById || {})
); );
@ -77,12 +77,12 @@ export const selectMyActiveClaims = createSelector(
new Set( new Set(
claims && claims &&
claims claims
.map((claim) => claim.claim_id) .map(claim => claim.claim_id)
.filter((claimId) => Object.keys(abandoningIds).indexOf(claimId) === -1) .filter(claimId => Object.keys(abandoningIds).indexOf(claimId) === -1)
) )
); );
export const makeSelectClaimIsMine = (rawUri) => { export const makeSelectClaimIsMine = rawUri => {
const uri = normalizeURI(rawUri); const uri = normalizeURI(rawUri);
return createSelector( return createSelector(
selectClaimsByUri, selectClaimsByUri,
@ -94,11 +94,11 @@ export const makeSelectClaimIsMine = (rawUri) => {
export const selectAllFetchingChannelClaims = createSelector( export const selectAllFetchingChannelClaims = createSelector(
selectState, selectState,
(state) => state.fetchingChannelClaims || {} state => state.fetchingChannelClaims || {}
); );
export const makeSelectFetchingChannelClaims = (uri) => export const makeSelectFetchingChannelClaims = uri =>
createSelector(selectAllFetchingChannelClaims, (fetching) => fetching && fetching[uri]); createSelector(selectAllFetchingChannelClaims, fetching => fetching && fetching[uri]);
export const makeSelectClaimsInChannelForPage = (uri, page) => export const makeSelectClaimsInChannelForPage = (uri, page) =>
createSelector(selectClaimsById, selectAllClaimsByChannel, (byId, allClaims) => { createSelector(selectClaimsById, selectAllClaimsByChannel, (byId, allClaims) => {
@ -107,10 +107,10 @@ export const makeSelectClaimsInChannelForPage = (uri, page) =>
if (!claimIds) return claimIds; if (!claimIds) return claimIds;
return claimIds.map((claimId) => byId[claimId]); return claimIds.map(claimId => byId[claimId]);
}); });
export const makeSelectClaimsInChannelForCurrentPage = (uri) => { export const makeSelectClaimsInChannelForCurrentPage = uri => {
const pageSelector = makeSelectCurrentParam('page'); const pageSelector = makeSelectCurrentParam('page');
return createSelector( return createSelector(
@ -123,30 +123,30 @@ export const makeSelectClaimsInChannelForCurrentPage = (uri) => {
if (!claimIds) return claimIds; if (!claimIds) return claimIds;
return claimIds.map((claimId) => byId[claimId]); return claimIds.map(claimId => byId[claimId]);
} }
); );
}; };
export const makeSelectMetadataForUri = (uri) => export const makeSelectMetadataForUri = uri =>
createSelector(makeSelectClaimForUri(uri), (claim) => { createSelector(makeSelectClaimForUri(uri), claim => {
const metadata = claim && claim.value && claim.value.stream && claim.value.stream.metadata; const metadata = claim && claim.value && claim.value.stream && claim.value.stream.metadata;
return metadata || (claim === undefined ? undefined : null); return metadata || (claim === undefined ? undefined : null);
}); });
export const makeSelectTitleForUri = (uri) => export const makeSelectTitleForUri = uri =>
createSelector(makeSelectMetadataForUri(uri), (metadata) => metadata && metadata.title); createSelector(makeSelectMetadataForUri(uri), metadata => metadata && metadata.title);
export const makeSelectContentTypeForUri = (uri) => export const makeSelectContentTypeForUri = uri =>
createSelector(makeSelectClaimForUri(uri), (claim) => { createSelector(makeSelectClaimForUri(uri), claim => {
const source = claim && claim.value && claim.value.stream && claim.value.stream.source; const source = claim && claim.value && claim.value.stream && claim.value.stream.source;
return source ? source.contentType : undefined; return source ? source.contentType : undefined;
}); });
export const selectIsFetchingClaimListMine = createSelector( export const selectIsFetchingClaimListMine = createSelector(
selectState, selectState,
(state) => state.isFetchingClaimListMine state => state.isFetchingClaimListMine
); );
export const selectMyClaims = createSelector( export const selectMyClaims = createSelector(
@ -157,7 +157,7 @@ export const selectMyClaims = createSelector(
(myClaimIds, byId, abandoningIds, pendingClaims) => { (myClaimIds, byId, abandoningIds, pendingClaims) => {
const claims = []; const claims = [];
myClaimIds.forEach((id) => { myClaimIds.forEach(id => {
const claim = byId[id]; const claim = byId[id];
if (claim && abandoningIds.indexOf(id) === -1) claims.push(claim); if (claim && abandoningIds.indexOf(id) === -1) claims.push(claim);
@ -167,27 +167,27 @@ export const selectMyClaims = createSelector(
} }
); );
export const selectMyClaimsWithoutChannels = createSelector(selectMyClaims, (myClaims) => export const selectMyClaimsWithoutChannels = createSelector(selectMyClaims, myClaims =>
myClaims.filter((claim) => !claim.name.match(/^@/)) myClaims.filter(claim => !claim.name.match(/^@/))
); );
export const selectAllMyClaimsByOutpoint = createSelector( export const selectAllMyClaimsByOutpoint = createSelector(
selectMyClaimsRaw, selectMyClaimsRaw,
(claims) => claims =>
new Set(claims && claims.length ? claims.map((claim) => `${claim.txid}:${claim.nout}`) : null) new Set(claims && claims.length ? claims.map(claim => `${claim.txid}:${claim.nout}`) : null)
); );
export const selectMyClaimsOutpoints = createSelector(selectMyClaims, (myClaims) => { export const selectMyClaimsOutpoints = createSelector(selectMyClaims, myClaims => {
const outpoints = []; const outpoints = [];
myClaims.forEach((claim) => outpoints.push(`${claim.txid}:${claim.nout}`)); myClaims.forEach(claim => outpoints.push(`${claim.txid}:${claim.nout}`));
return outpoints; return outpoints;
}); });
export const selectFetchingMyChannels = createSelector( export const selectFetchingMyChannels = createSelector(
selectState, selectState,
(state) => state.fetchingMyChannels state => state.fetchingMyChannels
); );
export const selectMyChannelClaims = createSelector( export const selectMyChannelClaims = createSelector(
@ -197,7 +197,7 @@ export const selectMyChannelClaims = createSelector(
const ids = state.myChannelClaims || []; const ids = state.myChannelClaims || [];
const claims = []; const claims = [];
ids.forEach((id) => { ids.forEach(id => {
if (byId[id]) { if (byId[id]) {
// I'm not sure why this check is necessary, but it ought to be a quick fix for https://github.com/lbryio/lbry-desktop/issues/544 // I'm not sure why this check is necessary, but it ought to be a quick fix for https://github.com/lbryio/lbry-desktop/issues/544
claims.push(byId[id]); claims.push(byId[id]);
@ -208,49 +208,46 @@ export const selectMyChannelClaims = createSelector(
} }
); );
export const selectResolvingUris = createSelector( export const selectResolvingUris = createSelector(selectState, state => state.resolvingUris || []);
selectState,
(state) => state.resolvingUris || []
);
export const makeSelectIsUriResolving = (uri) => export const makeSelectIsUriResolving = uri =>
createSelector( createSelector(
selectResolvingUris, selectResolvingUris,
(resolvingUris) => resolvingUris && resolvingUris.indexOf(uri) !== -1 resolvingUris => resolvingUris && resolvingUris.indexOf(uri) !== -1
); );
export const selectFeaturedUris = createSelector(selectState, (state) => state.featuredUris); export const selectFeaturedUris = createSelector(selectState, state => state.featuredUris);
export const selectFetchingFeaturedUris = createSelector( export const selectFetchingFeaturedUris = createSelector(
selectState, selectState,
(state) => state.fetchingFeaturedContent state => state.fetchingFeaturedContent
); );
export const selectTrendingUris = createSelector(selectState, (state) => state.trendingUris); export const selectTrendingUris = createSelector(selectState, state => state.trendingUris);
export const selectFetchingTrendingUris = createSelector( export const selectFetchingTrendingUris = createSelector(
selectState, selectState,
(state) => state.fetchingTrendingContent state => state.fetchingTrendingContent
); );
export const selectPlayingUri = createSelector(selectState, (state) => state.playingUri); export const selectPlayingUri = createSelector(selectState, state => state.playingUri);
export const selectChannelClaimCounts = createSelector( export const selectChannelClaimCounts = createSelector(
selectState, selectState,
(state) => state.channelClaimCounts || {} state => state.channelClaimCounts || {}
); );
export const makeSelectTotalItemsForChannel = (uri) => export const makeSelectTotalItemsForChannel = uri =>
createSelector(selectChannelClaimCounts, (byUri) => byUri && byUri[uri]); createSelector(selectChannelClaimCounts, byUri => byUri && byUri[uri]);
export const makeSelectTotalPagesForChannel = (uri, pageSize = 10) => export const makeSelectTotalPagesForChannel = (uri, pageSize = 10) =>
createSelector( createSelector(
selectChannelClaimCounts, selectChannelClaimCounts,
(byUri) => byUri && byUri[uri] && Math.ceil(byUri[uri] / pageSize) byUri => byUri && byUri[uri] && Math.ceil(byUri[uri] / pageSize)
); );
export const makeSelectNsfwCountFromUris = (uris) => export const makeSelectNsfwCountFromUris = uris =>
createSelector(selectClaimsByUri, (claims) => createSelector(selectClaimsByUri, claims =>
uris.reduce((acc, uri) => { uris.reduce((acc, uri) => {
const claim = claims[uri]; const claim = claims[uri];
if (isClaimNsfw(claim)) { if (isClaimNsfw(claim)) {
@ -260,7 +257,7 @@ export const makeSelectNsfwCountFromUris = (uris) =>
}, 0) }, 0)
); );
export const makeSelectNsfwCountForChannel = (uri) => { export const makeSelectNsfwCountForChannel = uri => {
const pageSelector = makeSelectCurrentParam('page'); const pageSelector = makeSelectCurrentParam('page');
return createSelector( return createSelector(
@ -284,7 +281,7 @@ export const makeSelectNsfwCountForChannel = (uri) => {
); );
}; };
export const makeSelectRecommendedContentForUri = (uri) => export const makeSelectRecommendedContentForUri = uri =>
createSelector( createSelector(
makeSelectClaimForUri(uri), makeSelectClaimForUri(uri),
selectSearchUrisByQuery, selectSearchUrisByQuery,
@ -302,7 +299,7 @@ export const makeSelectRecommendedContentForUri = (uri) =>
let searchUris = searchUrisByQuery[title.replace(/\//, ' ')]; let searchUris = searchUrisByQuery[title.replace(/\//, ' ')];
if (searchUris) { if (searchUris) {
searchUris = searchUris.filter((searchUri) => searchUri !== currentUri); searchUris = searchUris.filter(searchUri => searchUri !== currentUri);
recommendedContent = searchUris; recommendedContent = searchUris;
} }
} }
@ -311,9 +308,15 @@ export const makeSelectRecommendedContentForUri = (uri) =>
} }
); );
export const makeSelectFirstRecommendedFileForUri = uri =>
createSelector(
makeSelectRecommendedContentForUri(uri),
recommendedContent => (recommendedContent ? recommendedContent[0] : null)
);
// Returns the associated channel uri for a given claim uri // Returns the associated channel uri for a given claim uri
export const makeSelectChannelForClaimUri = (uri, includePrefix = false) => export const makeSelectChannelForClaimUri = (uri, includePrefix = false) =>
createSelector(makeSelectClaimForUri(uri), (claim) => { createSelector(makeSelectClaimForUri(uri), claim => {
if (!claim) { if (!claim) {
return null; return null;
} }