refactor(web): extract optimistic timeline reconciliation
This commit is contained in:
@@ -17,6 +17,7 @@ import {
|
||||
finalizeMultiSelectDraft,
|
||||
updateMultiSelectDraft,
|
||||
} from "./timelineMultiSelect.js";
|
||||
import { reconcileOptimisticEntries } from "./timelineOptimisticAllocations.js";
|
||||
import { finalizeRangeSelection, updateRangeSelectionDraft } from "./timelineRangeSelection.js";
|
||||
import { getTouchPoint, resolveTouchDragDecision } from "./timelineTouch.js";
|
||||
|
||||
@@ -510,27 +511,9 @@ export function useTimelineDrag({
|
||||
|
||||
const reconcileOptimisticAllocations = useCallback((entries: readonly OptimisticTimelineEntry[]) => {
|
||||
setOptimisticAllocations((prev) => {
|
||||
if (prev.size === 0) return prev;
|
||||
|
||||
const next = new Map(prev);
|
||||
for (const entry of entries) {
|
||||
const override = next.get(entry.id);
|
||||
if (!override) continue;
|
||||
|
||||
const startTime = new Date(entry.startDate).getTime();
|
||||
const endTime = new Date(entry.endDate).getTime();
|
||||
if (
|
||||
startTime === override.startDate.getTime() &&
|
||||
endTime === override.endDate.getTime()
|
||||
) {
|
||||
next.delete(entry.id);
|
||||
if (pendingOptimisticAllocationIdRef.current === entry.id) {
|
||||
pendingOptimisticAllocationIdRef.current = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return next.size === prev.size ? prev : next;
|
||||
const result = reconcileOptimisticEntries(prev, entries, pendingOptimisticAllocationIdRef.current);
|
||||
pendingOptimisticAllocationIdRef.current = result.pendingOptimisticAllocationId;
|
||||
return result.changed ? result.optimisticAllocations : prev;
|
||||
});
|
||||
}, []);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user