From e4fc01fc72dd2f437661b00cd84b2f8ac224cdab Mon Sep 17 00:00:00 2001 From: zeppi Date: Fri, 4 Jun 2021 09:22:54 -0400 Subject: [PATCH] fix crash on abandoned collection claim --- dist/bundle.es.js | 21 +++++++++++++-------- src/constants/collections.js | 4 ++-- src/redux/actions/collections.js | 21 +++++++++++++-------- 3 files changed, 28 insertions(+), 18 deletions(-) diff --git a/dist/bundle.es.js b/dist/bundle.es.js index 7839fd2..991c050 100644 --- a/dist/bundle.es.js +++ b/dist/bundle.es.js @@ -1040,8 +1040,8 @@ var shared_preferences = /*#__PURE__*/Object.freeze({ CLIENT_SYNC_KEYS: CLIENT_SYNC_KEYS }); -const COLLECTION_ID = 'colid'; -const COLLECTION_INDEX = 'colindex'; +const COLLECTION_ID = 'lid'; +const COLLECTION_INDEX = 'linx'; const COL_TYPE_PLAYLIST = 'playlist'; const COL_TYPE_CHANNELS = 'channelList'; @@ -4662,16 +4662,21 @@ const doFetchItemsInCollections = (resolveItemsOptions, resolveStartedCallback) const claimId = claim.claim_id; const itemOrder = claim.value.claims; - const sortResults = function (results, claimList) { - const newResults = []; + const sortResults = function (items, claimList) { + const newItems = []; claimList.forEach(function (id) { - const index = results.findIndex(function (i) { + const index = items.findIndex(function (i) { return i.claim_id === id; }); - const item = results.splice(index, 1); - if (item) newResults.push(item[0]); + if (index >= 0) { + newItems.push(items[index]); + } }); - return newResults; + /* + This will return newItems[] of length less than total_items below + if one or more of the claims has been abandoned. That's ok for now. + */ + return newItems; }; const mergeBatches = function (arrayOfResults, claimList) { diff --git a/src/constants/collections.js b/src/constants/collections.js index 0d53c94..6c002e6 100644 --- a/src/constants/collections.js +++ b/src/constants/collections.js @@ -1,5 +1,5 @@ -export const COLLECTION_ID = 'colid'; -export const COLLECTION_INDEX = 'colindex'; +export const COLLECTION_ID = 'lid'; +export const COLLECTION_INDEX = 'linx'; export const COL_TYPE_PLAYLIST = 'playlist'; export const COL_TYPE_CHANNELS = 'channelList'; diff --git a/src/redux/actions/collections.js b/src/redux/actions/collections.js index a8b7066..43176e3 100644 --- a/src/redux/actions/collections.js +++ b/src/redux/actions/collections.js @@ -93,7 +93,7 @@ export const doFetchItemsInCollections = ( pageSize?: number, }, resolveStartedCallback?: () => void -) => async(dispatch: Dispatch, getState: GetState) => { +) => async (dispatch: Dispatch, getState: GetState) => { /* 1) make sure all the collection claims are loaded into claims reducer, search/resolve if necessary. 2) get the item claims for each @@ -124,14 +124,19 @@ export const doFetchItemsInCollections = ( const claimId = claim.claim_id; const itemOrder = claim.value.claims; - const sortResults = (results: Array, claimList) => { - const newResults: Array = []; + const sortResults = (items: Array, claimList) => { + const newItems: Array = []; claimList.forEach(id => { - const index = results.findIndex(i => i.claim_id === id); - const item = results.splice(index, 1); - if (item) newResults.push(item[0]); + const index = items.findIndex(i => i.claim_id === id); + if (index >= 0) { + newItems.push(items[index]); + } }); - return newResults; + /* + This will return newItems[] of length less than total_items below + if one or more of the claims has been abandoned. That's ok for now. + */ + return newItems; }; const mergeBatches = ( @@ -313,7 +318,7 @@ export const doFetchItemsInCollection = ( return doFetchItemsInCollections(newOptions, cb); }; -export const doCollectionEdit = (collectionId: string, params: CollectionEditParams) => async( +export const doCollectionEdit = (collectionId: string, params: CollectionEditParams) => async ( dispatch: Dispatch, getState: GetState ) => {