mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-13 15:51:00 +00:00
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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user