Skip to content

Commit

Permalink
refactor(web/slot): easier to read drop function
Browse files Browse the repository at this point in the history
  • Loading branch information
LukeWasTakenn committed Sep 29, 2023
1 parent f17e5a3 commit 4878cb4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 24 deletions.
34 changes: 13 additions & 21 deletions web/src/components/inventory/InventorySlot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,27 +58,19 @@ const InventorySlot: React.FC<SlotProps> = ({ inventory, item }) => {
collect: (monitor) => ({
isOver: monitor.isOver(),
}),
drop: (source) =>
source.inventory === InventoryType.SHOP
? onBuy(source, {
inventory: inventory.type,
item: {
slot: item.slot,
},
})
: source.inventory === InventoryType.CRAFTING
? onCraft(source, {
inventory: inventory.type,
item: {
slot: item.slot,
},
})
: onDrop(source, {
inventory: inventory.type,
item: {
slot: item.slot,
},
}),
drop: (source) => {
switch (source.inventory) {
case InventoryType.SHOP:
onBuy(source, { inventory: inventory.type, item: { slot: item.slot } });
break;
case InventoryType.CRAFTING:
onCraft(source, { inventory: inventory.type, item: { slot: item.slot } });
break;
default:
onDrop(source, { inventory: inventory.type, item: { slot: item.slot } });
break;
}
},
canDrop: (source) =>
!isBusy &&
(source.item.slot !== item.slot || source.inventory !== inventory.type) &&
Expand Down
5 changes: 2 additions & 3 deletions web/src/components/utils/Tooltip.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React from 'react';
import { flip, FloatingPortal, shift, useFloating, autoUpdate, offset, useTransitionStyles } from '@floating-ui/react';
import { useAppDispatch, useAppSelector } from '../../store';
import { setHoverData } from '../../store/inventory';
import { flip, FloatingPortal, shift, useFloating, offset, useTransitionStyles } from '@floating-ui/react';
import { useAppSelector } from '../../store';
import SlotTooltip from '../inventory/SlotTooltip';

const Tooltip: React.FC = () => {
Expand Down

0 comments on commit 4878cb4

Please sign in to comment.