From d88fe04b56aeeeb67e62c194f743e37c0b8db81b Mon Sep 17 00:00:00 2001 From: Z8MB1E Date: Tue, 28 Jul 2026 14:51:56 -0400 Subject: [PATCH] fix(grid): prevent split collision by including source in overlap check Server action: remove 'other.id === entryId' exclusion from the split overlap scan so the source item's own footprint is treated as occupied, forcing the split to find a different position. UI: disable the split button via findEmptySpot check when no room exists for the split stack, preventing a failed action. --- src/app/(frontend)/logistics/structures/actions.ts | 2 +- src/components/frontend/storage/GridToolbar.tsx | 6 +++++- src/components/frontend/storage/StructureCard.tsx | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/app/(frontend)/logistics/structures/actions.ts b/src/app/(frontend)/logistics/structures/actions.ts index 53dbd82..5e35a94 100644 --- a/src/app/(frontend)/logistics/structures/actions.ts +++ b/src/app/(frontend)/logistics/structures/actions.ts @@ -737,7 +737,7 @@ export async function splitGridStack( let overlaps = false; for (const other of existing) { - if (other.id === entryId || other.id == null) continue; + if (other.id == null) continue; const otherRes = other.resource as Resource; if (!otherRes || typeof otherRes === "number") continue; const otherRotated = other.rotated ?? false; diff --git a/src/components/frontend/storage/GridToolbar.tsx b/src/components/frontend/storage/GridToolbar.tsx index 3a875c2..4e9f576 100644 --- a/src/components/frontend/storage/GridToolbar.tsx +++ b/src/components/frontend/storage/GridToolbar.tsx @@ -9,7 +9,7 @@ import { LayoutGridIcon, ListIcon, } from "lucide-react"; -import { GridItem, getItemFootprint, getGridOccupancy } from "@/lib/logistics"; +import { GridItem, getItemFootprint, getGridOccupancy, findEmptySpot } from "@/lib/logistics"; import { Resource } from "@/payload-types"; import { cn, pluralize } from "@/lib/utils"; @@ -41,6 +41,9 @@ export function GridToolbar({ const occupancy = getGridOccupancy(storedResources, gridWidth, gridHeight); const res = selectedItem ? (selectedItem.resource as Resource) : null; const fp = res ? getItemFootprint(res, selectedItem!.rotated) : null; + const canSplit = selectedItem && res && fp + ? findEmptySpot(storedResources, fp.width, fp.height, gridWidth, gridHeight) !== null + : false; return (
@@ -94,6 +97,7 @@ export function GridToolbar({