61 lines
1.6 KiB
TypeScript
61 lines
1.6 KiB
TypeScript
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,
|
|
};
|
|
}
|