refactor(web): extract project drag helpers

This commit is contained in:
2026-04-01 10:06:32 +02:00
parent c32f56ba89
commit 892a9c5ccf
5 changed files with 200 additions and 32 deletions
+60
View File
@@ -0,0 +1,60 @@
type ProjectDragStateLike = {
isDragging: boolean;
projectId: string | null;
projectName: string | null;
allocationId: string | null;
originalStartDate: Date | null;
originalEndDate: Date | null;
currentStartDate: Date | null;
currentEndDate: Date | null;
startMouseX: number;
pointerDeltaX: number;
originalLeft: number;
blockWidth: number;
daysDelta: number;
};
type CreateProjectDragStateInput = {
projectId: string;
projectName: string;
allocationId?: string | null;
startDate: Date;
endDate: Date;
startMouseX: number;
originalLeft?: number;
blockWidth?: number;
};
export function createProjectDragState<TState extends ProjectDragStateLike>(
input: CreateProjectDragStateInput,
): TState {
return {
isDragging: true,
projectId: input.projectId,
projectName: input.projectName,
allocationId: input.allocationId ?? null,
originalStartDate: input.startDate,
originalEndDate: input.endDate,
currentStartDate: input.startDate,
currentEndDate: input.endDate,
startMouseX: input.startMouseX,
pointerDeltaX: 0,
originalLeft: input.originalLeft ?? 0,
blockWidth: input.blockWidth ?? 0,
daysDelta: 0,
} as TState;
}
export function buildProjectShiftMutationInput(
drag: Pick<ProjectDragStateLike, "daysDelta" | "projectId" | "currentStartDate" | "currentEndDate">,
): { projectId: string; newStartDate: Date; newEndDate: Date } | null {
if (drag.daysDelta === 0 || !drag.projectId || !drag.currentStartDate || !drag.currentEndDate) {
return null;
}
return {
projectId: drag.projectId,
newStartDate: drag.currentStartDate,
newEndDate: drag.currentEndDate,
};
}