diff --git a/frontend/src/components/layout-editor/TypeLibrary.tsx b/frontend/src/components/layout-editor/TypeLibrary.tsx index 83dae86..b845a33 100644 --- a/frontend/src/components/layout-editor/TypeLibrary.tsx +++ b/frontend/src/components/layout-editor/TypeLibrary.tsx @@ -140,7 +140,7 @@ interface PlantTypeCardProps { function PlantTypeCard({ plantType, onDragStart }: PlantTypeCardProps) { const handleDragStart = (e: React.DragEvent) => { - e.dataTransfer.setData('application/json', JSON.stringify(plantType)); + e.dataTransfer.setData('application/json', JSON.stringify({ ...plantType, type: 'PLANT_TYPE' })); e.dataTransfer.effectAllowed = 'copy'; onDragStart(plantType); }; diff --git a/frontend/src/features/layout-designer/components/LayoutCanvas.tsx b/frontend/src/features/layout-designer/components/LayoutCanvas.tsx index 051c6ae..1e9c3b5 100644 --- a/frontend/src/features/layout-designer/components/LayoutCanvas.tsx +++ b/frontend/src/features/layout-designer/components/LayoutCanvas.tsx @@ -234,6 +234,23 @@ export function LayoutCanvas() { addToast(`Moved plant to ${result.newAddress}`, 'success'); } } + // Handle PLANT_TYPE placement (New Plants) + else if (parsed.type === 'PLANT_TYPE') { + const plantTypeId = parsed.id; + const plantTypeName = parsed.name || 'Plant'; + + if (col >= 1 && col <= targetSection.columns && row >= 1 && row <= targetSection.rows) { + const position = targetSection.positions?.find(p => p.row === row && p.column === col); + + if (position && (position.status === 'EMPTY' || position.status === 'RESERVED')) { + await layoutApi.occupyPosition(position.id, { plantTypeId }); + addToast(`Placed ${plantTypeName} at R${row}C${col}`, 'success'); + } else if (position?.status === 'PLANTED') { + addToast('Slot already occupied', 'warning'); + return; + } + } + } // Handle BATCH placement else if (parsed.type === 'BATCH') { const batchId = parsed.id;