From 2cdc43b271d828d917a81d31f701ea3214be41cd Mon Sep 17 00:00:00 2001 From: jessop Date: Mon, 23 Sep 2019 13:00:12 -0400 Subject: [PATCH 1/3] selectors for library and download pagination --- dist/bundle.es.js | 21 ++++++++++++++++++++- src/index.js | 4 ++++ src/redux/selectors/claims.js | 19 ++++++++++++++++++- src/redux/selectors/file_info.js | 18 ++++++++++++++++++ 4 files changed, 60 insertions(+), 2 deletions(-) diff --git a/dist/bundle.es.js b/dist/bundle.es.js index f2f4831..798a3b2 100644 --- a/dist/bundle.es.js +++ b/dist/bundle.es.js @@ -1494,7 +1494,6 @@ function concatClaims(claimList = [], concatClaimList = []) { } // - const selectState$2 = state => state.claims || {}; const selectClaimsById = reselect.createSelector(selectState$2, state => state.byId || {}); @@ -1843,6 +1842,14 @@ const selectUpdatingChannel = reselect.createSelector(selectState$2, state => st const selectUpdateChannelError = reselect.createSelector(selectState$2, state => state.updateChannelError); +const makeSelectMyStreamUrisForPage = (page = 0) => reselect.createSelector(selectMyClaimUrisWithoutChannels, uris => { + const start = Number(page) * Number(PAGE_SIZE); + const end = (Number(page) + 1) * Number(PAGE_SIZE); + return uris && uris.length ? uris.slice(start, end) : []; +}); + +const selectMyStreamUrisCount = reselect.createSelector(selectMyClaimUrisWithoutChannels, channels => channels.length); + function formatCredits(amount, precision, shortFormat = false) { let actualAmount = parseFloat(amount), suffix = ''; @@ -2707,6 +2714,14 @@ const makeSelectFileNameForUri = uri => reselect.createSelector(makeSelectFileIn return fileInfo && fileInfo.file_name; }); +const makeSelectDownloadUrisForPage = (page = 0) => reselect.createSelector(selectDownloadedUris, uris => { + const start = Number(page) * Number(PAGE_SIZE); + const end = (Number(page) + 1) * Number(PAGE_SIZE); + return uris && uris.length ? uris.slice(start, end) : []; +}); + +const selectDownloadUrisCount = reselect.createSelector(selectDownloadedUris, uris => uris.length); + // const selectState$4 = state => state.file || {}; @@ -5059,6 +5074,7 @@ exports.makeSelectContentTypeForUri = makeSelectContentTypeForUri; exports.makeSelectCoverForUri = makeSelectCoverForUri; exports.makeSelectDateForUri = makeSelectDateForUri; exports.makeSelectDownloadPathForUri = makeSelectDownloadPathForUri; +exports.makeSelectDownloadUrisForPage = makeSelectDownloadUrisForPage; exports.makeSelectDownloadingForUri = makeSelectDownloadingForUri; exports.makeSelectFetchingChannelClaims = makeSelectFetchingChannelClaims; exports.makeSelectFileInfoForUri = makeSelectFileInfoForUri; @@ -5071,6 +5087,7 @@ exports.makeSelectLoadingForUri = makeSelectLoadingForUri; exports.makeSelectMediaTypeForUri = makeSelectMediaTypeForUri; exports.makeSelectMetadataForUri = makeSelectMetadataForUri; exports.makeSelectMetadataItemForUri = makeSelectMetadataItemForUri; +exports.makeSelectMyStreamUrisForPage = makeSelectMyStreamUrisForPage; exports.makeSelectNsfwCountForChannel = makeSelectNsfwCountForChannel; exports.makeSelectNsfwCountFromUris = makeSelectNsfwCountFromUris; exports.makeSelectPendingByUri = makeSelectPendingByUri; @@ -5116,6 +5133,7 @@ exports.selectClaimsByUri = selectClaimsByUri; exports.selectCreateChannelError = selectCreateChannelError; exports.selectCreatingChannel = selectCreatingChannel; exports.selectCurrentChannelPage = selectCurrentChannelPage; +exports.selectDownloadUrisCount = selectDownloadUrisCount; exports.selectDownloadedUris = selectDownloadedUris; exports.selectDownloadingByOutpoint = selectDownloadingByOutpoint; exports.selectDownloadingFileInfos = selectDownloadingFileInfos; @@ -5152,6 +5170,7 @@ exports.selectMyClaims = selectMyClaims; exports.selectMyClaimsOutpoints = selectMyClaimsOutpoints; exports.selectMyClaimsRaw = selectMyClaimsRaw; exports.selectMyClaimsWithoutChannels = selectMyClaimsWithoutChannels; +exports.selectMyStreamUrisCount = selectMyStreamUrisCount; exports.selectPendingById = selectPendingById; exports.selectPendingClaims = selectPendingClaims; exports.selectPlayingUri = selectPlayingUri; diff --git a/src/index.js b/src/index.js index ce4c00a..290d53c 100644 --- a/src/index.js +++ b/src/index.js @@ -206,6 +206,8 @@ export { selectCreatingChannel, selectCreateChannelError, selectChannelImportPending, + makeSelectMyStreamUrisForPage, + selectMyStreamUrisCount, } from 'redux/selectors/claims'; export { makeSelectCommentsForUri } from 'redux/selectors/comments'; @@ -230,6 +232,8 @@ export { makeSelectDownloadPathForUri, makeSelectFileNameForUri, makeSelectFilePartlyDownloaded, + makeSelectDownloadUrisForPage, + selectDownloadUrisCount, } from 'redux/selectors/file_info'; export { diff --git a/src/redux/selectors/claims.js b/src/redux/selectors/claims.js index 723f8d3..23785df 100644 --- a/src/redux/selectors/claims.js +++ b/src/redux/selectors/claims.js @@ -5,7 +5,7 @@ import { selectSupportsByOutpoint } from 'redux/selectors/wallet'; import { createSelector } from 'reselect'; import { isClaimNsfw, createNormalizedClaimSearchKey } from 'util/claim'; import { getSearchQueryString } from 'util/query-params'; - +import { PAGE_SIZE } from 'constants/claim'; const selectState = state => state.claims || {}; export const selectClaimsById = createSelector( @@ -591,3 +591,20 @@ export const selectUpdateChannelError = createSelector( selectState, state => state.updateChannelError ); + +export const makeSelectMyStreamUrisForPage = (page: number = 0) => + createSelector( + selectMyClaimUrisWithoutChannels, + uris => { + const start = (Number(page) * Number(PAGE_SIZE)); + const end = ((Number(page) + 1) * Number(PAGE_SIZE)); + return (uris && uris.length) + ? uris.slice(start, end) + : []; + } + ); + +export const selectMyStreamUrisCount = createSelector( + selectMyClaimUrisWithoutChannels, + channels => channels.length +); diff --git a/src/redux/selectors/file_info.js b/src/redux/selectors/file_info.js index d805eff..f9d209f 100644 --- a/src/redux/selectors/file_info.js +++ b/src/redux/selectors/file_info.js @@ -9,6 +9,7 @@ import { import { createSelector } from 'reselect'; import { buildURI } from 'lbryURI'; import Lbry from 'lbry'; +import { PAGE_SIZE } from 'constants/claim'; export const selectState = state => state.fileInfo || {}; @@ -202,3 +203,20 @@ export const makeSelectFileNameForUri = uri => return fileInfo && fileInfo.file_name; } ); + +export const makeSelectDownloadUrisForPage = (page = 0) => + createSelector( + selectDownloadedUris, + uris => { + const start = (Number(page) * Number(PAGE_SIZE)); + const end = ((Number(page) + 1) * Number(PAGE_SIZE)); + return (uris && uris.length) + ? uris.slice(start, end) + : []; + } + ); + +export const selectDownloadUrisCount = createSelector( + selectDownloadedUris, + uris => uris.length +); From 41d10218337e6d21fd0473d451ce8fc1337afbbe Mon Sep 17 00:00:00 2001 From: jessop Date: Wed, 25 Sep 2019 17:16:27 -0400 Subject: [PATCH 2/3] off by 1 modifications --- dist/bundle.es.js | 12 ++++++------ src/redux/selectors/claims.js | 6 +++--- src/redux/selectors/file_info.js | 6 +++--- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/dist/bundle.es.js b/dist/bundle.es.js index 798a3b2..31792c8 100644 --- a/dist/bundle.es.js +++ b/dist/bundle.es.js @@ -1842,9 +1842,9 @@ const selectUpdatingChannel = reselect.createSelector(selectState$2, state => st const selectUpdateChannelError = reselect.createSelector(selectState$2, state => state.updateChannelError); -const makeSelectMyStreamUrisForPage = (page = 0) => reselect.createSelector(selectMyClaimUrisWithoutChannels, uris => { - const start = Number(page) * Number(PAGE_SIZE); - const end = (Number(page) + 1) * Number(PAGE_SIZE); +const makeSelectMyStreamUrisForPage = (page = 1) => reselect.createSelector(selectMyClaimUrisWithoutChannels, uris => { + const start = (Number(page) - 1) * Number(PAGE_SIZE); + const end = Number(page) * Number(PAGE_SIZE); return uris && uris.length ? uris.slice(start, end) : []; }); @@ -2714,9 +2714,9 @@ const makeSelectFileNameForUri = uri => reselect.createSelector(makeSelectFileIn return fileInfo && fileInfo.file_name; }); -const makeSelectDownloadUrisForPage = (page = 0) => reselect.createSelector(selectDownloadedUris, uris => { - const start = Number(page) * Number(PAGE_SIZE); - const end = (Number(page) + 1) * Number(PAGE_SIZE); +const makeSelectDownloadUrisForPage = (page = 1) => reselect.createSelector(selectDownloadedUris, uris => { + const start = (Number(page) - 1) * Number(PAGE_SIZE); + const end = Number(page) * Number(PAGE_SIZE); return uris && uris.length ? uris.slice(start, end) : []; }); diff --git a/src/redux/selectors/claims.js b/src/redux/selectors/claims.js index 23785df..eb9757a 100644 --- a/src/redux/selectors/claims.js +++ b/src/redux/selectors/claims.js @@ -592,12 +592,12 @@ export const selectUpdateChannelError = createSelector( state => state.updateChannelError ); -export const makeSelectMyStreamUrisForPage = (page: number = 0) => +export const makeSelectMyStreamUrisForPage = (page: number = 1) => createSelector( selectMyClaimUrisWithoutChannels, uris => { - const start = (Number(page) * Number(PAGE_SIZE)); - const end = ((Number(page) + 1) * Number(PAGE_SIZE)); + const start = ((Number(page) - 1) * Number(PAGE_SIZE)); + const end = (Number(page) * Number(PAGE_SIZE)); return (uris && uris.length) ? uris.slice(start, end) : []; diff --git a/src/redux/selectors/file_info.js b/src/redux/selectors/file_info.js index f9d209f..484b3fd 100644 --- a/src/redux/selectors/file_info.js +++ b/src/redux/selectors/file_info.js @@ -204,12 +204,12 @@ export const makeSelectFileNameForUri = uri => } ); -export const makeSelectDownloadUrisForPage = (page = 0) => +export const makeSelectDownloadUrisForPage = (page = 1) => createSelector( selectDownloadedUris, uris => { - const start = (Number(page) * Number(PAGE_SIZE)); - const end = ((Number(page) + 1) * Number(PAGE_SIZE)); + const start = ((Number(page) - 1) * Number(PAGE_SIZE)); + const end = (Number(page) * Number(PAGE_SIZE)); return (uris && uris.length) ? uris.slice(start, end) : []; From 64383d57873ce59dea9df7216ee6cf52c4e95dc6 Mon Sep 17 00:00:00 2001 From: jessop Date: Wed, 25 Sep 2019 17:37:21 -0400 Subject: [PATCH 3/3] uri to url --- dist/bundle.es.js | 20 ++++++++++---------- src/index.js | 8 ++++---- src/redux/selectors/claims.js | 10 +++++----- src/redux/selectors/file_info.js | 10 +++++----- 4 files changed, 24 insertions(+), 24 deletions(-) diff --git a/dist/bundle.es.js b/dist/bundle.es.js index 31792c8..5350c64 100644 --- a/dist/bundle.es.js +++ b/dist/bundle.es.js @@ -1842,13 +1842,13 @@ const selectUpdatingChannel = reselect.createSelector(selectState$2, state => st const selectUpdateChannelError = reselect.createSelector(selectState$2, state => state.updateChannelError); -const makeSelectMyStreamUrisForPage = (page = 1) => reselect.createSelector(selectMyClaimUrisWithoutChannels, uris => { +const makeSelectMyStreamUrlsForPage = (page = 1) => reselect.createSelector(selectMyClaimUrisWithoutChannels, urls => { const start = (Number(page) - 1) * Number(PAGE_SIZE); const end = Number(page) * Number(PAGE_SIZE); - return uris && uris.length ? uris.slice(start, end) : []; + return urls && urls.length ? urls.slice(start, end) : []; }); -const selectMyStreamUrisCount = reselect.createSelector(selectMyClaimUrisWithoutChannels, channels => channels.length); +const selectMyStreamUrlsCount = reselect.createSelector(selectMyClaimUrisWithoutChannels, channels => channels.length); function formatCredits(amount, precision, shortFormat = false) { let actualAmount = parseFloat(amount), @@ -2714,13 +2714,13 @@ const makeSelectFileNameForUri = uri => reselect.createSelector(makeSelectFileIn return fileInfo && fileInfo.file_name; }); -const makeSelectDownloadUrisForPage = (page = 1) => reselect.createSelector(selectDownloadedUris, uris => { +const makeSelectDownloadUrlsForPage = (page = 1) => reselect.createSelector(selectDownloadedUris, urls => { const start = (Number(page) - 1) * Number(PAGE_SIZE); const end = Number(page) * Number(PAGE_SIZE); - return uris && uris.length ? uris.slice(start, end) : []; + return urls && urls.length ? urls.slice(start, end) : []; }); -const selectDownloadUrisCount = reselect.createSelector(selectDownloadedUris, uris => uris.length); +const selectDownloadUrlsCount = reselect.createSelector(selectDownloadedUris, uris => uris.length); // @@ -5074,7 +5074,7 @@ exports.makeSelectContentTypeForUri = makeSelectContentTypeForUri; exports.makeSelectCoverForUri = makeSelectCoverForUri; exports.makeSelectDateForUri = makeSelectDateForUri; exports.makeSelectDownloadPathForUri = makeSelectDownloadPathForUri; -exports.makeSelectDownloadUrisForPage = makeSelectDownloadUrisForPage; +exports.makeSelectDownloadUrlsForPage = makeSelectDownloadUrlsForPage; exports.makeSelectDownloadingForUri = makeSelectDownloadingForUri; exports.makeSelectFetchingChannelClaims = makeSelectFetchingChannelClaims; exports.makeSelectFileInfoForUri = makeSelectFileInfoForUri; @@ -5087,7 +5087,7 @@ exports.makeSelectLoadingForUri = makeSelectLoadingForUri; exports.makeSelectMediaTypeForUri = makeSelectMediaTypeForUri; exports.makeSelectMetadataForUri = makeSelectMetadataForUri; exports.makeSelectMetadataItemForUri = makeSelectMetadataItemForUri; -exports.makeSelectMyStreamUrisForPage = makeSelectMyStreamUrisForPage; +exports.makeSelectMyStreamUrlsForPage = makeSelectMyStreamUrlsForPage; exports.makeSelectNsfwCountForChannel = makeSelectNsfwCountForChannel; exports.makeSelectNsfwCountFromUris = makeSelectNsfwCountFromUris; exports.makeSelectPendingByUri = makeSelectPendingByUri; @@ -5133,7 +5133,7 @@ exports.selectClaimsByUri = selectClaimsByUri; exports.selectCreateChannelError = selectCreateChannelError; exports.selectCreatingChannel = selectCreatingChannel; exports.selectCurrentChannelPage = selectCurrentChannelPage; -exports.selectDownloadUrisCount = selectDownloadUrisCount; +exports.selectDownloadUrlsCount = selectDownloadUrlsCount; exports.selectDownloadedUris = selectDownloadedUris; exports.selectDownloadingByOutpoint = selectDownloadingByOutpoint; exports.selectDownloadingFileInfos = selectDownloadingFileInfos; @@ -5170,7 +5170,7 @@ exports.selectMyClaims = selectMyClaims; exports.selectMyClaimsOutpoints = selectMyClaimsOutpoints; exports.selectMyClaimsRaw = selectMyClaimsRaw; exports.selectMyClaimsWithoutChannels = selectMyClaimsWithoutChannels; -exports.selectMyStreamUrisCount = selectMyStreamUrisCount; +exports.selectMyStreamUrlsCount = selectMyStreamUrlsCount; exports.selectPendingById = selectPendingById; exports.selectPendingClaims = selectPendingClaims; exports.selectPlayingUri = selectPlayingUri; diff --git a/src/index.js b/src/index.js index 290d53c..94dc1b8 100644 --- a/src/index.js +++ b/src/index.js @@ -206,8 +206,8 @@ export { selectCreatingChannel, selectCreateChannelError, selectChannelImportPending, - makeSelectMyStreamUrisForPage, - selectMyStreamUrisCount, + makeSelectMyStreamUrlsForPage, + selectMyStreamUrlsCount, } from 'redux/selectors/claims'; export { makeSelectCommentsForUri } from 'redux/selectors/comments'; @@ -232,8 +232,8 @@ export { makeSelectDownloadPathForUri, makeSelectFileNameForUri, makeSelectFilePartlyDownloaded, - makeSelectDownloadUrisForPage, - selectDownloadUrisCount, + makeSelectDownloadUrlsForPage, + selectDownloadUrlsCount, } from 'redux/selectors/file_info'; export { diff --git a/src/redux/selectors/claims.js b/src/redux/selectors/claims.js index eb9757a..bc67fe1 100644 --- a/src/redux/selectors/claims.js +++ b/src/redux/selectors/claims.js @@ -592,19 +592,19 @@ export const selectUpdateChannelError = createSelector( state => state.updateChannelError ); -export const makeSelectMyStreamUrisForPage = (page: number = 1) => +export const makeSelectMyStreamUrlsForPage = (page: number = 1) => createSelector( selectMyClaimUrisWithoutChannels, - uris => { + urls => { const start = ((Number(page) - 1) * Number(PAGE_SIZE)); const end = (Number(page) * Number(PAGE_SIZE)); - return (uris && uris.length) - ? uris.slice(start, end) + return (urls && urls.length) + ? urls.slice(start, end) : []; } ); -export const selectMyStreamUrisCount = createSelector( +export const selectMyStreamUrlsCount = createSelector( selectMyClaimUrisWithoutChannels, channels => channels.length ); diff --git a/src/redux/selectors/file_info.js b/src/redux/selectors/file_info.js index 484b3fd..195150a 100644 --- a/src/redux/selectors/file_info.js +++ b/src/redux/selectors/file_info.js @@ -204,19 +204,19 @@ export const makeSelectFileNameForUri = uri => } ); -export const makeSelectDownloadUrisForPage = (page = 1) => +export const makeSelectDownloadUrlsForPage = (page = 1) => createSelector( selectDownloadedUris, - uris => { + urls => { const start = ((Number(page) - 1) * Number(PAGE_SIZE)); const end = (Number(page) * Number(PAGE_SIZE)); - return (uris && uris.length) - ? uris.slice(start, end) + return (urls && urls.length) + ? urls.slice(start, end) : []; } ); -export const selectDownloadUrisCount = createSelector( +export const selectDownloadUrlsCount = createSelector( selectDownloadedUris, uris => uris.length );