1
1
import { MutableRefObject , useEffect , useRef , useState } from "react" ;
2
2
import { ID_GRID_ALLDAY_ROW } from "@web/common/constants/web.constants" ;
3
3
import { getElemById } from "@web/common/utils/grid.util" ;
4
+ import { selectIsDNDing } from "@web/ducks/events/selectors/draft.selectors" ;
5
+ import { useAppSelector } from "@web/store/store.hooks" ;
4
6
import { useDraftContext } from "@web/views/Calendar/components/Draft/context/useDraftContext" ;
7
+ import { SidebarDraftContextValue } from "@web/views/Calendar/components/Draft/sidebar/context/SidebarDraftContext" ;
8
+ import { useSidebarContext } from "@web/views/Calendar/components/Draft/sidebar/context/useSidebarContext" ;
5
9
import { WeekProps } from "../useWeek" ;
6
10
7
11
const EDGE_THRESHOLD = 50 ; // pixels from edge to trigger navigation
@@ -11,14 +15,26 @@ export const useDragEdgeNavigation = (
11
15
mainGridRef : MutableRefObject < HTMLDivElement | null > ,
12
16
weekProps : WeekProps ,
13
17
) => {
14
- const { state } = useDraftContext ( ) ;
18
+ const { state : draftState } = useDraftContext ( ) ;
19
+ const isDNDing = useAppSelector ( selectIsDNDing ) ;
20
+ const { state : sidebarState } =
21
+ useSidebarContext ( ) as SidebarDraftContextValue ;
15
22
const [ mousePosition , setMousePosition ] = useState ( { x : 0 , y : 0 } ) ;
16
23
const navigationTimeoutRef = useRef < NodeJS . Timeout | null > ( null ) ;
17
24
const lastEdgeRef = useRef < "left" | "right" | null > ( null ) ;
18
25
26
+ const isGridEventDragging = draftState . isDragging ;
27
+ const isSomedayEventDragging = isDNDing ;
28
+
29
+ const gridEventDraft = draftState . draft ;
30
+ const somedayEventDraft = sidebarState . draft ;
31
+
32
+ const isDragging = isGridEventDragging || isSomedayEventDragging ;
33
+ const currentDraft = gridEventDraft || somedayEventDraft ;
34
+
19
35
// Track mouse position during dragging
20
36
useEffect ( ( ) => {
21
- if ( ! state . isDragging ) {
37
+ if ( ! isDragging ) {
22
38
// Clear any pending navigation when dragging stops
23
39
if ( navigationTimeoutRef . current ) {
24
40
clearTimeout ( navigationTimeoutRef . current ) ;
@@ -29,9 +45,6 @@ export const useDragEdgeNavigation = (
29
45
return ;
30
46
}
31
47
32
- // Handle both timed and all-day events
33
- if ( ! state . draft ) return ;
34
-
35
48
const updateMousePosition = ( event : MouseEvent ) => {
36
49
setMousePosition ( { x : event . clientX , y : event . clientY } ) ;
37
50
} ;
@@ -41,16 +54,16 @@ export const useDragEdgeNavigation = (
41
54
return ( ) => {
42
55
window . removeEventListener ( "mousemove" , updateMousePosition ) ;
43
56
} ;
44
- } , [ state . isDragging , state . draft ] ) ;
57
+ } , [ isDragging ] ) ;
45
58
46
59
// Check for edge proximity and trigger navigation
47
60
useEffect ( ( ) => {
48
- if ( ! state . isDragging || ! state . draft ) {
61
+ if ( ! isDragging || ! currentDraft ) {
49
62
return ;
50
63
}
51
64
52
65
// Use appropriate container based on event type
53
- const isAllDay = state . draft . isAllDay ;
66
+ const isAllDay = currentDraft . isAllDay ;
54
67
const container = isAllDay
55
68
? getElemById ( ID_GRID_ALLDAY_ROW )
56
69
: mainGridRef . current ;
@@ -98,7 +111,8 @@ export const useDragEdgeNavigation = (
98
111
navigationTimeoutRef . current = null ;
99
112
}
100
113
} ;
101
- } , [ state . isDragging , mousePosition . x , weekProps . util , state . draft ] ) ;
114
+ // eslint-disable-next-line react-hooks/exhaustive-deps
115
+ } , [ isDragging , mousePosition . x , weekProps . util , currentDraft ] ) ;
102
116
103
117
// Cleanup on unmount
104
118
useEffect ( ( ) => {
0 commit comments