fix(planner): the drag state setters are stable, so the sidebar's dragend listener lists them and is still set up once

This commit is contained in:
Maurice
2026-11-12 08:42:15 +01:00
parent c515f95d17
commit 860ffc1dee
2 changed files with 7 additions and 6 deletions
@@ -373,7 +373,7 @@ function useDayPlanSidebar(props: DayPlanSidebarProps) {
}
document.addEventListener('dragend', cleanup)
return () => document.removeEventListener('dragend', cleanup)
}, [])
}, [setDraggingId, setDropTargetKey, setDragOverDayId])
// Initialize missing transport positions outside of render to avoid setState-during-render
// eslint-disable-next-line react-hooks/exhaustive-deps
@@ -1,4 +1,4 @@
import { useEffect, useRef, useState, type MutableRefObject } from 'react';
import { useCallback, useEffect, useRef, useState, type MutableRefObject } from 'react';
/** A stop's or a day's id, as the day plan's drag handlers pass them around. */
type DragKey = string | number | null;
@@ -27,14 +27,15 @@ export function useDayPlanDragState(dragDataRef: MutableRefObject<unknown>) {
const dropTargetRef = useRef<string | null>(null);
const [dragOverDayId, setDragOverDayId] = useState<DragKey>(null);
const setDraggingId = (id: DragKey) => {
// Stable, so the sidebar's listeners that call them are set up once.
const setDraggingId = useCallback((id: DragKey) => {
if (id != null) setHasDragged(true);
setDraggingIdState(id);
};
const setDropTargetKey = (key: string | null) => {
}, []);
const setDropTargetKey = useCallback((key: string | null) => {
dropTargetRef.current = key;
setDropTargetKeyState(key);
};
}, []);
useEffect(() => {
if (!draggingId && !dropTargetKey && !dragOverDayId) return;