refactor(web): extract allocation multi-drag helpers

This commit is contained in:
2026-04-01 10:03:16 +02:00
parent e23b502dd9
commit c32f56ba89
5 changed files with 158 additions and 13 deletions
+18 -13
View File
@@ -17,6 +17,12 @@ import {
requiresAllocationFragmentExtraction,
shouldTreatAllocationDragAsClick,
} from "./timelineAllocationFinalize.js";
import {
finalizeAllocationMultiDrag,
isAllocationMultiSelected,
startAllocationMultiDrag,
updateAllocationMultiDrag,
} from "./timelineAllocationMultiDrag.js";
import {
createMultiSelectState,
finalizeMultiSelectDraft,
@@ -648,28 +654,26 @@ export function useTimelineDrag({
// Check if this allocation is part of a multi-selection → multi-drag mode
const ms = multiSelectRef.current;
const isMultiSelected =
ms.selectedAllocationIds.length > 1 &&
ms.selectedAllocationIds.includes(opts.allocationId);
const isMultiSelected = isAllocationMultiSelected(ms, opts.allocationId);
if (isMultiSelected) {
// ── Multi-drag: move/resize all selected allocations together ──
const startMouseX = e.clientX;
let currentDaysDelta = 0;
const dragMode = opts.mode;
const initialMultiDragState = startAllocationMultiDrag(ms, dragMode);
setMultiSelectState((prev) => ({ ...prev, isMultiDragging: true, multiDragDaysDelta: 0, multiDragMode: dragMode }));
multiSelectRef.current = { ...ms, isMultiDragging: true, multiDragDaysDelta: 0, multiDragMode: dragMode };
setMultiSelectState(initialMultiDragState);
multiSelectRef.current = initialMultiDragState;
multiSelectCleanupRef.current?.();
function handleMultiMove(ev: MouseEvent) {
const deltaX = ev.clientX - startMouseX;
const daysDelta = pixelsToDays(deltaX, cellWidthRef.current);
if (daysDelta === currentDaysDelta) return;
currentDaysDelta = daysDelta;
const updated = updateAllocationMultiDrag(multiSelectRef.current, daysDelta);
if (!updated) return;
setMultiSelectState((prev) => ({ ...prev, multiDragDaysDelta: daysDelta }));
multiSelectRef.current = { ...multiSelectRef.current, multiDragDaysDelta: daysDelta };
setMultiSelectState(updated);
multiSelectRef.current = updated;
}
function handleMultiUp(ev: MouseEvent) {
@@ -677,13 +681,14 @@ export function useTimelineDrag({
multiSelectCleanupRef.current = null;
const finalDelta = pixelsToDays(ev.clientX - startMouseX, cellWidthRef.current);
const finalized = finalizeAllocationMultiDrag(multiSelectRef.current);
setMultiSelectState((prev) => ({ ...prev, isMultiDragging: false, multiDragDaysDelta: 0 }));
multiSelectRef.current = { ...multiSelectRef.current, isMultiDragging: false, multiDragDaysDelta: 0 };
setMultiSelectState(finalized);
multiSelectRef.current = finalized;
if (finalDelta !== 0) {
// Pass IDs from ref to avoid stale closure in the callback
const ids = multiSelectRef.current.selectedAllocationIds;
const ids = finalized.selectedAllocationIds;
onMultiDragCompleteRef.current?.(finalDelta, dragMode, ids);
}
}