From f7acec12b692f63428d42b215dd515c51c3de7fc Mon Sep 17 00:00:00 2001 From: Razzmatazz Date: Fri, 11 Aug 2023 15:48:44 -0500 Subject: [PATCH 1/2] fix crash --- src/components/barters-table/index.js | 3 +++ src/features/barters/index.js | 32 +++++++++++++-------------- src/pages/item/index.js | 6 ++--- 3 files changed, 22 insertions(+), 19 deletions(-) diff --git a/src/components/barters-table/index.js b/src/components/barters-table/index.js index f4c3882aa..5e4b5783f 100644 --- a/src/components/barters-table/index.js +++ b/src/components/barters-table/index.js @@ -148,6 +148,9 @@ function BartersTable({ selectedTrader, nameFilter, itemFilter, showAll, useBart } if (!rewardItem.item.containsItems) continue; for (const contained of rewardItem.item.containsItems) { + if (!contained) { + continue; + } if (contained.item.id === itemFilter) { return true; } diff --git a/src/features/barters/index.js b/src/features/barters/index.js index 49958a330..67f91e537 100644 --- a/src/features/barters/index.js +++ b/src/features/barters/index.js @@ -121,26 +121,26 @@ export const selectAllBarters = createSelector([selectBarters, selectQuests, sel } return { ...barter, - requiredItems: barter.requiredItems.map(req => { + requiredItems: barter.requiredItems.reduce((requirements, req) => { let matchedItem = items.find(it => it.id === req.item.id); - if (!matchedItem) { - return false; + if (matchedItem) { + requirements.push({ + ...req, + item: matchedItem, + }); } - return { - ...req, - item: matchedItem, - }; - }).filter(Boolean), - rewardItems: barter.rewardItems.map(req => { + return requirements; + }, []), + rewardItems: barter.rewardItems.reduce((requirements, req) => { const matchedItem = items.find(it => it.id === req.item.id); - if (!matchedItem) { - return false; + if (matchedItem) { + requirements.push({ + ...req, + item: matchedItem, + }); } - return { - ...req, - item: matchedItem, - }; - }).filter(Boolean), + return requirements; + }, []), taskUnlock: taskUnlock, }; }).filter(barter => barter.rewardItems.length > 0 && barter.requiredItems.length > 0); diff --git a/src/pages/item/index.js b/src/pages/item/index.js index 07f338a28..c1cf9261e 100644 --- a/src/pages/item/index.js +++ b/src/pages/item/index.js @@ -214,9 +214,9 @@ function Item() { const containsItems = currentItemData?.containsItems?.length > 0; const hasBarters = barters.some(barter => { - let requiredItems = barter.requiredItems.some(contained => contained.item.id === currentItemData.id); - let rewardItems = barter.rewardItems.some(contained => contained.item.id === currentItemData.id || - contained.item.containsItems.some(ci => ci.item.id === currentItemData.id)); + let requiredItems = barter.requiredItems.some(contained => contained?.item.id === currentItemData.id); + let rewardItems = barter.rewardItems.some(contained => contained?.item.id === currentItemData.id || + contained?.item.containsItems.some(ci => ci?.item.id === currentItemData.id)); return requiredItems || rewardItems; }); From ce0bd9956e3e03aa65c1b4408cd40087cf8e2e26 Mon Sep 17 00:00:00 2001 From: Razzmatazz Date: Fri, 11 Aug 2023 16:14:07 -0500 Subject: [PATCH 2/2] another fix --- src/components/small-item-table/index.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/components/small-item-table/index.js b/src/components/small-item-table/index.js index 6b45db268..93818b482 100644 --- a/src/components/small-item-table/index.js +++ b/src/components/small-item-table/index.js @@ -323,6 +323,9 @@ function SmallItemTable(props) { return {}; const filterItems = {}; containedInFilter.forEach(ci => { + if (!ci) { + return; + } filterItems[ci.item.id] = ci.count; }); return filterItems;