fix(frontend): implement drag handler for PLANT_TYPE from library
This commit is contained in:
parent
2acef3c63c
commit
dcbb75180d
2 changed files with 18 additions and 1 deletions
|
|
@ -140,7 +140,7 @@ interface PlantTypeCardProps {
|
||||||
|
|
||||||
function PlantTypeCard({ plantType, onDragStart }: PlantTypeCardProps) {
|
function PlantTypeCard({ plantType, onDragStart }: PlantTypeCardProps) {
|
||||||
const handleDragStart = (e: React.DragEvent) => {
|
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';
|
e.dataTransfer.effectAllowed = 'copy';
|
||||||
onDragStart(plantType);
|
onDragStart(plantType);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -234,6 +234,23 @@ export function LayoutCanvas() {
|
||||||
addToast(`Moved plant to ${result.newAddress}`, 'success');
|
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
|
// Handle BATCH placement
|
||||||
else if (parsed.type === 'BATCH') {
|
else if (parsed.type === 'BATCH') {
|
||||||
const batchId = parsed.id;
|
const batchId = parsed.id;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue