diff --git a/dist/bundle.es.js b/dist/bundle.es.js index 12358cb..a72ace1 100644 --- a/dist/bundle.es.js +++ b/dist/bundle.es.js @@ -3727,23 +3727,51 @@ const makeSelectClaimIdsForCollectionId = id => reselect.createSelector(makeSele return ids; }); -const makeSelectIndexForUrlInCollection = (url, id) => reselect.createSelector(makeSelectUrlsForCollectionId(id), makeSelectClaimForUri(url), (urls, claim) => { - const index = urls && urls.findIndex(u => u === url); +const makeSelectIndexForUrlInCollection = (url, id) => reselect.createSelector(state => state.content.shuffleList, makeSelectUrlsForCollectionId(id), makeSelectClaimForUri(url), (shuffleState, urls, claim) => { + const shuffleUrls = shuffleState && shuffleState.collectionId === id && shuffleState.newUrls; + const listUrls = shuffleUrls || urls; + + const index = listUrls && listUrls.findIndex(u => u === url); if (index > -1) { return index; } else if (claim) { - const index = urls && urls.findIndex(u => u === claim.permanent_url); + const index = listUrls && listUrls.findIndex(u => u === claim.permanent_url); if (index > -1) return index; return claim; } return null; }); -const makeSelectNextUrlForCollectionAndUrl = (id, url) => reselect.createSelector(makeSelectIndexForUrlInCollection(url, id), selectClaimsByUri, makeSelectUrlsForCollectionId(id), (index, claims, urls) => { +const makeSelectPreviousUrlForCollectionAndUrl = (id, url) => reselect.createSelector(state => state.content.shuffleList, state => state.content.loopList, makeSelectIndexForUrlInCollection(url, id), makeSelectUrlsForCollectionId(id), (shuffleState, loopState, index, urls) => { + const loopList = loopState && loopState.collectionId === id && loopState.loop; + const shuffleUrls = shuffleState && shuffleState.collectionId === id && shuffleState.newUrls; + if (index > -1) { + const listUrls = shuffleUrls || urls; + let nextUrl; + if (index === 0 && loopList) { + nextUrl = listUrls[listUrls.length - 1]; + } else { + nextUrl = listUrls[index - 1]; + } + return nextUrl || null; + } else { + return null; + } +}); + +const makeSelectNextUrlForCollectionAndUrl = (id, url) => reselect.createSelector(state => state.content.shuffleList, state => state.content.loopList, makeSelectIndexForUrlInCollection(url, id), makeSelectUrlsForCollectionId(id), (shuffleState, loopState, index, urls) => { + const loopList = loopState && loopState.collectionId === id && loopState.loop; + const shuffleUrls = shuffleState && shuffleState.collectionId === id && shuffleState.newUrls; + + if (index > -1) { + const listUrls = shuffleUrls || urls; // We'll get the next playble url - const remainingUrls = urls.slice(index + 1); - const nextUrl = remainingUrls.find(u => claims[u].value.stream_type && (claims[u].value.stream_type === 'video' || claims[u].value.stream_type === 'audio')); + let remainingUrls = listUrls.slice(index + 1); + if (!remainingUrls.length && loopList) { + remainingUrls = listUrls.slice(0); + } + const nextUrl = remainingUrls && remainingUrls[0]; return nextUrl || null; } else { return null; @@ -3759,7 +3787,13 @@ const makeSelectCountForCollectionId = id => reselect.createSelector(makeSelectC if (collection.itemCount !== undefined) { return collection.itemCount; } - return collection.items.length; + let itemCount = 0; + collection.items.map(item => { + if (item) { + itemCount += 1; + } + }); + return itemCount; } return null; }); @@ -4465,15 +4499,11 @@ function doCollectionPublish(options, localId) { }; } -function doCollectionPublishUpdate(options, isBackgroundUpdate) { - return (dispatch, getState) => { +function doCollectionPublishUpdate(options) { + return dispatch => { // TODO: implement one click update - const updateParams = isBackgroundUpdate ? { - blocking: true, - claim_id: options.claim_id, - clear_claims: true - } : { + const updateParams = { bid: creditsToString(options.bid), title: options.title, thumbnail_url: options.thumbnail_url, @@ -4486,17 +4516,13 @@ function doCollectionPublishUpdate(options, isBackgroundUpdate) { clear_claims: true }; - if (isBackgroundUpdate && updateParams.claim_id) { - const state = getState(); - updateParams['claims'] = makeSelectClaimIdsForCollectionId(updateParams.claim_id)(state); - } else if (options.claims) { - updateParams['claims'] = options.claims; - } - if (options.tags) { updateParams['tags'] = options.tags.map(tag => tag.name); } + if (options.claims) { + updateParams['claims'] = options.claims; + } return new Promise(resolve => { dispatch({ type: COLLECTION_PUBLISH_UPDATE_STARTED @@ -8061,6 +8087,7 @@ exports.makeSelectPendingAmountByUri = makeSelectPendingAmountByUri; exports.makeSelectPendingClaimForUri = makeSelectPendingClaimForUri; exports.makeSelectPendingCollectionForId = makeSelectPendingCollectionForId; exports.makeSelectPermanentUrlForUri = makeSelectPermanentUrlForUri; +exports.makeSelectPreviousUrlForCollectionAndUrl = makeSelectPreviousUrlForCollectionAndUrl; exports.makeSelectPublishFormValue = makeSelectPublishFormValue; exports.makeSelectPublishedCollectionForId = makeSelectPublishedCollectionForId; exports.makeSelectReflectingClaimForUri = makeSelectReflectingClaimForUri; diff --git a/src/index.js b/src/index.js index fd1090c..079665f 100644 --- a/src/index.js +++ b/src/index.js @@ -183,6 +183,7 @@ export { makeSelectCountForCollectionId, makeSelectIsResolvingCollectionForId, makeSelectIndexForUrlInCollection, + makeSelectPreviousUrlForCollectionAndUrl, makeSelectNextUrlForCollectionAndUrl, makeSelectCollectionForIdHasClaimUrl, } from 'redux/selectors/collections'; diff --git a/src/redux/actions/claims.js b/src/redux/actions/claims.js index f5bf190..37212a1 100644 --- a/src/redux/actions/claims.js +++ b/src/redux/actions/claims.js @@ -19,10 +19,7 @@ import { creditsToString } from 'util/format-credits'; import { batchActions } from 'util/batch-actions'; import { createNormalizedClaimSearchKey } from 'util/claim'; import { PAGE_SIZE } from 'constants/claim'; -import { - selectPendingCollections, - makeSelectClaimIdsForCollectionId, -} from 'redux/selectors/collections'; +import { selectPendingCollections } from 'redux/selectors/collections'; import { doFetchItemsInCollection, doFetchItemsInCollections, @@ -79,7 +76,7 @@ export function doResolveUris( const collectionIds: Array = []; return Lbry.resolve({ urls: urisToResolve, ...options }).then( - async (result: ResolveResponse) => { + async(result: ResolveResponse) => { let repostedResults = {}; const repostsToResolve = []; const fallbackResolveInfo = { @@ -651,7 +648,7 @@ export function doClaimSearch( } ) { const query = createNormalizedClaimSearchKey(options); - return async (dispatch: Dispatch) => { + return async(dispatch: Dispatch) => { dispatch({ type: ACTIONS.CLAIM_SEARCH_STARTED, data: { query: query }, @@ -831,21 +828,18 @@ export function doCollectionPublish( }; } -export function doCollectionPublishUpdate( - options: { - bid?: string, - blocking?: true, - title?: string, - thumbnail_url?: string, - description?: string, - claim_id: string, - tags?: Array, - languages?: Array, - claims?: Array, - }, - isBackgroundUpdate?: boolean -) { - return (dispatch: Dispatch, getState: GetState): Promise => { +export function doCollectionPublishUpdate(options: { + bid?: string, + blocking?: true, + title?: string, + thumbnail_url?: string, + description?: string, + claim_id: string, + tags?: Array, + languages?: Array, + claims?: Array, +}) { + return (dispatch: Dispatch): Promise => { // TODO: implement one click update const updateParams: { @@ -859,36 +853,26 @@ export function doCollectionPublishUpdate( languages?: Array, claims?: Array, clear_claims: boolean, - } = isBackgroundUpdate - ? { - blocking: true, - claim_id: options.claim_id, - clear_claims: true, - } - : { - bid: creditsToString(options.bid), - title: options.title, - thumbnail_url: options.thumbnail_url, - description: options.description, - tags: [], - languages: options.languages || [], - locations: [], - blocking: true, - claim_id: options.claim_id, - clear_claims: true, - }; - - if (isBackgroundUpdate && updateParams.claim_id) { - const state = getState(); - updateParams['claims'] = makeSelectClaimIdsForCollectionId(updateParams.claim_id)(state); - } else if (options.claims) { - updateParams['claims'] = options.claims; - } + } = { + bid: creditsToString(options.bid), + title: options.title, + thumbnail_url: options.thumbnail_url, + description: options.description, + tags: [], + languages: options.languages || [], + locations: [], + blocking: true, + claim_id: options.claim_id, + clear_claims: true, + }; if (options.tags) { updateParams['tags'] = options.tags.map(tag => tag.name); } + if (options.claims) { + updateParams['claims'] = options.claims; + } return new Promise(resolve => { dispatch({ type: ACTIONS.COLLECTION_PUBLISH_UPDATE_STARTED, diff --git a/src/redux/selectors/collections.js b/src/redux/selectors/collections.js index 6eb68c9..973228c 100644 --- a/src/redux/selectors/collections.js +++ b/src/redux/selectors/collections.js @@ -212,14 +212,18 @@ export const makeSelectClaimIdsForCollectionId = (id: string) => export const makeSelectIndexForUrlInCollection = (url: string, id: string) => createSelector( + state => state.content.shuffleList, makeSelectUrlsForCollectionId(id), makeSelectClaimForUri(url), - (urls, claim) => { - const index = urls && urls.findIndex(u => u === url); + (shuffleState, urls, claim) => { + const shuffleUrls = shuffleState && shuffleState.collectionId === id && shuffleState.newUrls; + const listUrls = shuffleUrls || urls; + + const index = listUrls && listUrls.findIndex(u => u === url); if (index > -1) { return index; } else if (claim) { - const index = urls && urls.findIndex(u => u === claim.permanent_url); + const index = listUrls && listUrls.findIndex(u => u === claim.permanent_url); if (index > -1) return index; return claim; } @@ -227,20 +231,49 @@ export const makeSelectIndexForUrlInCollection = (url: string, id: string) => } ); +export const makeSelectPreviousUrlForCollectionAndUrl = (id: string, url: string) => + createSelector( + state => state.content.shuffleList, + state => state.content.loopList, + makeSelectIndexForUrlInCollection(url, id), + makeSelectUrlsForCollectionId(id), + (shuffleState, loopState, index, urls) => { + const loopList = loopState && loopState.collectionId === id && loopState.loop; + const shuffleUrls = shuffleState && shuffleState.collectionId === id && shuffleState.newUrls; + + if (index > -1) { + const listUrls = shuffleUrls || urls; + let nextUrl; + if (index === 0 && loopList) { + nextUrl = listUrls[listUrls.length - 1]; + } else { + nextUrl = listUrls[index - 1]; + } + return nextUrl || null; + } else { + return null; + } + } + ); + export const makeSelectNextUrlForCollectionAndUrl = (id: string, url: string) => createSelector( + state => state.content.shuffleList, + state => state.content.loopList, makeSelectIndexForUrlInCollection(url, id), - selectClaimsByUri, makeSelectUrlsForCollectionId(id), - (index, claims, urls) => { + (shuffleState, loopState, index, urls) => { + const loopList = loopState && loopState.collectionId === id && loopState.loop; + const shuffleUrls = shuffleState && shuffleState.collectionId === id && shuffleState.newUrls; + if (index > -1) { + const listUrls = shuffleUrls || urls; // We'll get the next playble url - const remainingUrls = urls.slice(index + 1); - const nextUrl = remainingUrls.find( - u => - claims[u].value.stream_type && - (claims[u].value.stream_type === 'video' || claims[u].value.stream_type === 'audio') - ); + let remainingUrls = listUrls.slice(index + 1); + if (!remainingUrls.length && loopList) { + remainingUrls = listUrls.slice(0); + } + const nextUrl = remainingUrls && remainingUrls[0]; return nextUrl || null; } else { return null; @@ -264,7 +297,13 @@ export const makeSelectCountForCollectionId = (id: string) => if (collection.itemCount !== undefined) { return collection.itemCount; } - return collection.items.length; + let itemCount = 0; + collection.items.map(item => { + if (item) { + itemCount += 1; + } + }); + return itemCount; } return null; }