fix crash on abandoned collection claim

This commit is contained in:
zeppi 2021-06-04 09:22:54 -04:00 committed by jessopb
parent e20baa0683
commit 40fc75320d
3 changed files with 28 additions and 18 deletions

21
dist/bundle.es.js vendored
View file

@ -1040,8 +1040,8 @@ var shared_preferences = /*#__PURE__*/Object.freeze({
CLIENT_SYNC_KEYS: CLIENT_SYNC_KEYS CLIENT_SYNC_KEYS: CLIENT_SYNC_KEYS
}); });
const COLLECTION_ID = 'colid'; const COLLECTION_ID = 'lid';
const COLLECTION_INDEX = 'colindex'; const COLLECTION_INDEX = 'linx';
const COL_TYPE_PLAYLIST = 'playlist'; const COL_TYPE_PLAYLIST = 'playlist';
const COL_TYPE_CHANNELS = 'channelList'; const COL_TYPE_CHANNELS = 'channelList';
@ -4662,16 +4662,21 @@ const doFetchItemsInCollections = (resolveItemsOptions, resolveStartedCallback)
const claimId = claim.claim_id; const claimId = claim.claim_id;
const itemOrder = claim.value.claims; const itemOrder = claim.value.claims;
const sortResults = function (results, claimList) { const sortResults = function (items, claimList) {
const newResults = []; const newItems = [];
claimList.forEach(function (id) { claimList.forEach(function (id) {
const index = results.findIndex(function (i) { const index = items.findIndex(function (i) {
return i.claim_id === id; return i.claim_id === id;
}); });
const item = results.splice(index, 1); if (index >= 0) {
if (item) newResults.push(item[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) { const mergeBatches = function (arrayOfResults, claimList) {

View file

@ -1,5 +1,5 @@
export const COLLECTION_ID = 'colid'; export const COLLECTION_ID = 'lid';
export const COLLECTION_INDEX = 'colindex'; export const COLLECTION_INDEX = 'linx';
export const COL_TYPE_PLAYLIST = 'playlist'; export const COL_TYPE_PLAYLIST = 'playlist';
export const COL_TYPE_CHANNELS = 'channelList'; export const COL_TYPE_CHANNELS = 'channelList';

View file

@ -93,7 +93,7 @@ export const doFetchItemsInCollections = (
pageSize?: number, pageSize?: number,
}, },
resolveStartedCallback?: () => void 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. 1) make sure all the collection claims are loaded into claims reducer, search/resolve if necessary.
2) get the item claims for each 2) get the item claims for each
@ -124,14 +124,19 @@ export const doFetchItemsInCollections = (
const claimId = claim.claim_id; const claimId = claim.claim_id;
const itemOrder = claim.value.claims; const itemOrder = claim.value.claims;
const sortResults = (results: Array<Claim>, claimList) => { const sortResults = (items: Array<Claim>, claimList) => {
const newResults: Array<Claim> = []; const newItems: Array<Claim> = [];
claimList.forEach(id => { claimList.forEach(id => {
const index = results.findIndex(i => i.claim_id === id); const index = items.findIndex(i => i.claim_id === id);
const item = results.splice(index, 1); if (index >= 0) {
if (item) newResults.push(item[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 = ( const mergeBatches = (
@ -313,7 +318,7 @@ export const doFetchItemsInCollection = (
return doFetchItemsInCollections(newOptions, cb); return doFetchItemsInCollections(newOptions, cb);
}; };
export const doCollectionEdit = (collectionId: string, params: CollectionEditParams) => async( export const doCollectionEdit = (collectionId: string, params: CollectionEditParams) => async (
dispatch: Dispatch, dispatch: Dispatch,
getState: GetState getState: GetState
) => { ) => {