Skip to content

Commit

Permalink
Minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jrmi committed Feb 18, 2024
1 parent 6e03f3f commit bcb0b13
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 17 deletions.
2 changes: 0 additions & 2 deletions src/ui/NavButton.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)`
Expand Down
10 changes: 0 additions & 10 deletions src/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
11 changes: 6 additions & 5 deletions src/utils/item.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ export const getHeldItems = ({
itemIds,
shouldHoldItems,
}) => {
const safeCurrentLinkedItems = currentLinkedItemIds || [];
if (shouldHoldItems) {
let before = true;
const afterItemIds = itemList
Expand All @@ -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 [];
}
Expand Down

1 comment on commit bcb0b13

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.