fix(frontend): implement drag handler for PLANT_TYPE from library
Some checks are pending
Test / backend-test (push) Waiting to run
Test / frontend-test (push) Waiting to run

This commit is contained in:
fullsizemalt 2026-01-01 17:03:20 -08:00
parent 2acef3c63c
commit dcbb75180d
2 changed files with 18 additions and 1 deletions

View file

@ -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);
};

View file

@ -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;