diff --git a/src/ui/NavButton.jsx b/src/ui/NavButton.jsx index b0bbe36b..93d4762e 100644 --- a/src/ui/NavButton.jsx +++ b/src/ui/NavButton.jsx @@ -2,8 +2,6 @@ import React from "react"; import styled from "styled-components"; import { useNavigate } from "react-router-dom"; -import { useEventListener } from "@react-hookz/web/esm/useEventListener"; -import { insideElement } from "../utils"; import FixedButton from "./FixedButton"; const StyledNavButton = styled(FixedButton)` diff --git a/src/utils/index.js b/src/utils/index.js index 61464b45..eb5c61dc 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -31,16 +31,6 @@ export const insideClass = (element, className) => { return insideClass(element.parentNode, className); }; -export const insideElement = (wrapperElement, element) => { - if (element === wrapperElement) { - return true; - } - if (!element.parentNode) { - return false; - } - return insideClass(wrapperElement, element.parentNode); -}; - /** * Shuffles array in place. * @param {Array} a An array containing the items. diff --git a/src/utils/item.js b/src/utils/item.js index c6e162b2..246aaea6 100644 --- a/src/utils/item.js +++ b/src/utils/item.js @@ -113,6 +113,7 @@ export const getHeldItems = ({ itemIds, shouldHoldItems, }) => { + const safeCurrentLinkedItems = currentLinkedItemIds || []; if (shouldHoldItems) { let before = true; const afterItemIds = itemList @@ -125,20 +126,20 @@ export const getHeldItems = ({ }) .map(({ id }) => id); const newHeldItems = Object.entries( - areItemsInside(element, afterItemIds, currentLinkedItemIds || [], true) + areItemsInside(element, afterItemIds, safeCurrentLinkedItems, true) ) .filter(([, { inside }]) => inside) .map(([itemId]) => itemId); if ( - currentLinkedItemIds.length !== newHeldItems.length || - !currentLinkedItemIds.every((itemId) => newHeldItems.includes(itemId)) + safeCurrentLinkedItems.length !== newHeldItems.length || + !safeCurrentLinkedItems.every((itemId) => newHeldItems.includes(itemId)) ) { return newHeldItems; } } else { if ( - !Array.isArray(currentLinkedItemIds) || - currentLinkedItemIds.length !== 0 + !Array.isArray(safeCurrentLinkedItems) || + safeCurrentLinkedItems.length !== 0 ) { return []; }