refactor(web): extract project drag finalize

This commit is contained in:
2026-04-01 11:49:14 +02:00
parent 463caedcfd
commit 1e2bd3d4eb
5 changed files with 218 additions and 30 deletions
+18 -27
View File
@@ -24,7 +24,8 @@ import { finalizeAllocationReleaseEffects } from "./timelineAllocationReleaseEff
import { cleanupTimelineDragState } from "./timelineDragCleanup.js";
import { resolveAllocationDragPosition, resolveProjectDragPosition } from "./timelineDragPosition.js";
import { attachDocumentMouseDrag } from "./timelineDocumentDrag.js";
import { buildProjectShiftMutationInput, createProjectDragState } from "./timelineProjectDrag.js";
import { finalizeProjectDrag } from "./timelineProjectDragFinalize.js";
import { createProjectDragState } from "./timelineProjectDrag.js";
import { beginProjectDragSession } from "./timelineProjectDragSession.js";
import {
forwardCanvasTouchEnd,
@@ -408,28 +409,18 @@ export function useTimelineDrag({
mutateAsync: (...args: unknown[]) => Promise<unknown>;
};
const finalizeProjectDrag = useCallback(
(clientX: number, mode: "mutate" | "mutateAsync" = "mutate") => {
updateProjectDragPosition(clientX);
const finalDrag = dragStateRef.current;
if (!finalDrag.isDragging) return null;
const mutationInput = buildProjectShiftMutationInput(finalDrag);
if (finalDrag.daysDelta !== 0) {
preserveLivePreview(projectPreviewRef.current);
}
clearProjectDragSession();
if (!mutationInput) return null;
if (mode === "mutateAsync") {
return applyShiftMutation.mutateAsync(mutationInput);
}
applyShiftMutation.mutate(mutationInput);
return null;
},
const finalizeActiveProjectDrag = useCallback(
(clientX: number, mode: "mutate" | "mutateAsync" = "mutate") =>
finalizeProjectDrag({
clientX,
mode,
dragRef: dragStateRef,
previewRef: projectPreviewRef,
updatePosition: updateProjectDragPosition,
clearSession: clearProjectDragSession,
mutate: applyShiftMutation.mutate,
mutateAsync: applyShiftMutation.mutateAsync,
}),
[applyShiftMutation, clearProjectDragSession, updateProjectDragPosition],
);
@@ -516,11 +507,11 @@ export function useTimelineDrag({
attachDrag: attachDocumentMouseDrag,
updatePosition: updateProjectDragPosition,
finalize: (clientX) => {
void finalizeProjectDrag(clientX);
void finalizeActiveProjectDrag(clientX);
},
});
},
[finalizeProjectDrag, setProjectPreviewTargets, updateProjectDragPosition],
[finalizeActiveProjectDrag, setProjectPreviewTargets, updateProjectDragPosition],
);
// Legacy — kept for backward compat (triggers project shift from allocation block)
@@ -717,7 +708,7 @@ export function useTimelineDrag({
const drag = dragStateRef.current;
if (drag.isDragging) {
try {
await finalizeProjectDrag(e.clientX, "mutateAsync");
await finalizeActiveProjectDrag(e.clientX, "mutateAsync");
} catch {
// Validation error — revert visually
}
@@ -734,7 +725,7 @@ export function useTimelineDrag({
setRangeState(INITIAL_RANGE_STATE);
}
},
[finalizeProjectDrag, onRangeSelected],
[finalizeActiveProjectDrag, onRangeSelected],
);
const onCanvasMouseLeave = useCallback(() => {