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
});
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) {

View file

@ -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';

View file

@ -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<Claim>, claimList) => {
const newResults: Array<Claim> = [];
const sortResults = (items: Array<Claim>, claimList) => {
const newItems: Array<Claim> = [];
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
) => {