refactor(web): extract timeline range selection helpers
This commit is contained in:
@@ -17,6 +17,7 @@ import {
|
||||
finalizeMultiSelectDraft,
|
||||
updateMultiSelectDraft,
|
||||
} from "./timelineMultiSelect.js";
|
||||
import { finalizeRangeSelection, updateRangeSelectionDraft } from "./timelineRangeSelection.js";
|
||||
import { getTouchPoint, resolveTouchDragDecision } from "./timelineTouch.js";
|
||||
|
||||
const DRAG_CLICK_THRESHOLD_PX = 5;
|
||||
@@ -893,18 +894,8 @@ export function useTimelineDrag({
|
||||
|
||||
// Range select
|
||||
const range = rangeStateRef.current;
|
||||
if (range.isSelecting && range.startDate) {
|
||||
const deltaX = e.clientX - range.startClientX;
|
||||
const daysDelta = pixelsToDays(deltaX, cellWidthRef.current);
|
||||
const currentDate = new Date(range.startDate);
|
||||
currentDate.setDate(currentDate.getDate() + daysDelta);
|
||||
|
||||
const prevDelta = range.currentDate
|
||||
? Math.round((range.currentDate.getTime() - range.startDate.getTime()) / 86400000)
|
||||
: 0;
|
||||
if (daysDelta === prevDelta) return;
|
||||
|
||||
const updated: RangeState = { ...range, currentDate };
|
||||
const updated = updateRangeSelectionDraft(range, e.clientX, cellWidthRef.current);
|
||||
if (updated) {
|
||||
rangeStateRef.current = updated;
|
||||
setRangeState(updated);
|
||||
}
|
||||
@@ -927,19 +918,9 @@ export function useTimelineDrag({
|
||||
|
||||
// Range select
|
||||
const range = rangeStateRef.current;
|
||||
if (range.isSelecting && range.resourceId && range.startDate) {
|
||||
const endDate = range.currentDate ?? range.startDate;
|
||||
const [startDate, finalEnd] =
|
||||
range.startDate <= endDate ? [range.startDate, endDate] : [endDate, range.startDate];
|
||||
|
||||
onRangeSelected?.({
|
||||
resourceId: range.resourceId,
|
||||
startDate,
|
||||
endDate: finalEnd,
|
||||
suggestedProjectId: range.suggestedProjectId,
|
||||
anchorX: e.clientX,
|
||||
anchorY: e.clientY,
|
||||
});
|
||||
const selection = finalizeRangeSelection(range, e.clientX, e.clientY);
|
||||
if (selection) {
|
||||
onRangeSelected?.(selection);
|
||||
|
||||
rangeStateRef.current = INITIAL_RANGE_STATE;
|
||||
setRangeState(INITIAL_RANGE_STATE);
|
||||
|
||||
Reference in New Issue
Block a user