refactor(web): extract allocation release classification

This commit is contained in:
2026-04-01 10:48:47 +02:00
parent 0ab1374853
commit ca947befde
5 changed files with 220 additions and 34 deletions
+14 -30
View File
@@ -11,18 +11,14 @@ import {
scheduleLivePreview,
type LivePreviewSession,
} from "./timelineLivePreview.js";
import {
buildAllocationMovedSnapshot,
hasAllocationDateChange,
shouldTreatAllocationDragAsClick,
} from "./timelineAllocationFinalize.js";
import { buildAllocationBlockClickInfo, buildAllocationMutationPlan } from "./timelineAllocationActions.js";
import { buildAllocationMovedSnapshot } from "./timelineAllocationFinalize.js";
import {
finalizeAllocationMultiDrag,
isAllocationMultiSelected,
startAllocationMultiDrag,
updateAllocationMultiDrag,
} from "./timelineAllocationMultiDrag.js";
import { resolveAllocationRelease } from "./timelineAllocationRelease.js";
import { createAllocationDragState } from "./timelineAllocationDragState.js";
import { attachDocumentMouseDrag } from "./timelineDocumentDrag.js";
import { buildProjectShiftMutationInput, createProjectDragState } from "./timelineProjectDrag.js";
@@ -703,36 +699,24 @@ export function useTimelineDrag({
allocDragCleanupRef.current = null;
updateAllocationDragPosition(ev.clientX);
const alloc = allocDragRef.current;
if (!alloc.isActive) return;
const hasDateChange = hasAllocationDateChange(alloc);
const release = resolveAllocationRelease(alloc, {
clickThresholdPx: DRAG_CLICK_THRESHOLD_PX,
wasShift,
});
if (release.kind === "ignore") return;
if (hasDateChange) {
if (release.preservePreview) {
preserveLivePreview(allocPreviewRef.current);
}
clearLivePreview(allocPreviewRef.current);
allocPreviewRef.current = null;
const shouldTreatAsClick = shouldTreatAllocationDragAsClick(alloc, DRAG_CLICK_THRESHOLD_PX);
if (shouldTreatAsClick && alloc.allocationId) {
// No movement → treat as click
if (wasShift) {
// Shift+Click → toggle multi-selection for this allocation
onShiftClickAllocRef.current?.(alloc.allocationId);
} else {
// Normal click → open alloc popover
const clickInfo = buildAllocationBlockClickInfo(alloc);
if (clickInfo) {
onBlockClickRef.current?.(clickInfo);
}
}
} else if (hasDateChange && alloc.allocationId && alloc.currentStartDate && alloc.currentEndDate) {
const mutationPlan = buildAllocationMutationPlan(alloc);
if (!mutationPlan) {
allocDragRef.current = INITIAL_ALLOC_DRAG;
setAllocDragState(INITIAL_ALLOC_DRAG);
return;
}
if (release.kind === "shift-click") {
onShiftClickAllocRef.current?.(release.allocationId);
} else if (release.kind === "click") {
onBlockClickRef.current?.(release.clickInfo);
} else if (release.kind === "mutation") {
const { mutationPlan } = release;
const {
activeAllocationId,
currentStartDate,