Skip to content

Commit e31f44a

Browse files
feat(web): implement transition week on hold event to calendar edge for (#806)
someday events
1 parent 0a0ac69 commit e31f44a

File tree

4 files changed

+49
-29
lines changed

4 files changed

+49
-29
lines changed

packages/web/src/views/Calendar/Calendar.tsx

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -80,26 +80,26 @@ export const CalendarView = () => {
8080
/>
8181
)}
8282
</ContextMenuWrapper>
83-
</SidebarDraftProvider>
84-
<StyledCalendar direction={FlexDirections.COLUMN} id={ID_MAIN}>
85-
<Header
86-
rootProps={rootProps}
87-
scrollUtil={scrollUtil}
88-
today={today}
89-
weekProps={weekProps}
90-
/>
91-
92-
<ContextMenuWrapper id="grid-context-menu">
93-
<Grid
94-
dateCalcs={dateCalcs}
95-
isSidebarOpen={isSidebarOpen}
96-
gridRefs={gridRefs}
97-
measurements={measurements}
83+
<StyledCalendar direction={FlexDirections.COLUMN} id={ID_MAIN}>
84+
<Header
85+
rootProps={rootProps}
86+
scrollUtil={scrollUtil}
9887
today={today}
9988
weekProps={weekProps}
10089
/>
101-
</ContextMenuWrapper>
102-
</StyledCalendar>
90+
91+
<ContextMenuWrapper id="grid-context-menu">
92+
<Grid
93+
dateCalcs={dateCalcs}
94+
isSidebarOpen={isSidebarOpen}
95+
gridRefs={gridRefs}
96+
measurements={measurements}
97+
today={today}
98+
weekProps={weekProps}
99+
/>
100+
</ContextMenuWrapper>
101+
</StyledCalendar>
102+
</SidebarDraftProvider>
103103
</DraftProvider>
104104
</Styled>
105105
);

packages/web/src/views/Calendar/components/Draft/sidebar/context/SidebarDraftContext.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { createContext } from "react";
22
import { Actions_Sidebar } from "../hooks/useSidebarActions";
33
import { Setters_Sidebar, State_Sidebar } from "../hooks/useSidebarState";
44

5-
interface SidebarDraftContextValue {
5+
export interface SidebarDraftContextValue {
66
state: State_Sidebar;
77
setters: Setters_Sidebar;
88
actions: Actions_Sidebar;

packages/web/src/views/Calendar/components/Draft/sidebar/hooks/useSidebarActions.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,10 +251,16 @@ export const useSidebarActions = (
251251
const onDragEnd = (result: DropResult) => {
252252
const { destination, draggableId, source } = result;
253253

254+
const handleDiscard = () => {
255+
dispatch(draftSlice.actions.discard());
256+
close();
257+
};
258+
254259
const droppedOnSidebar = destination !== null;
255260
if (droppedOnSidebar) {
256261
const reorderedDraft = draggableId === ID_SOMEDAY_DRAFT;
257262
if (reorderedDraft && !state.isDraftingNew) {
263+
handleDiscard();
258264
return;
259265
}
260266

@@ -263,7 +269,7 @@ export const useSidebarActions = (
263269
destination.index === source.index;
264270

265271
if (noChange) {
266-
close();
272+
handleDiscard();
267273
return;
268274
}
269275

@@ -280,7 +286,7 @@ export const useSidebarActions = (
280286
}
281287
}
282288

283-
close();
289+
handleDiscard();
284290
};
285291

286292
const onDragStart = async (props: { draggableId: string }) => {

packages/web/src/views/Calendar/hooks/grid/useDragEdgeNavigation.ts

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import { MutableRefObject, useEffect, useRef, useState } from "react";
22
import { ID_GRID_ALLDAY_ROW } from "@web/common/constants/web.constants";
33
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";
46
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";
59
import { WeekProps } from "../useWeek";
610

711
const EDGE_THRESHOLD = 50; // pixels from edge to trigger navigation
@@ -11,14 +15,26 @@ export const useDragEdgeNavigation = (
1115
mainGridRef: MutableRefObject<HTMLDivElement | null>,
1216
weekProps: WeekProps,
1317
) => {
14-
const { state } = useDraftContext();
18+
const { state: draftState } = useDraftContext();
19+
const isDNDing = useAppSelector(selectIsDNDing);
20+
const { state: sidebarState } =
21+
useSidebarContext() as SidebarDraftContextValue;
1522
const [mousePosition, setMousePosition] = useState({ x: 0, y: 0 });
1623
const navigationTimeoutRef = useRef<NodeJS.Timeout | null>(null);
1724
const lastEdgeRef = useRef<"left" | "right" | null>(null);
1825

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+
1935
// Track mouse position during dragging
2036
useEffect(() => {
21-
if (!state.isDragging) {
37+
if (!isDragging) {
2238
// Clear any pending navigation when dragging stops
2339
if (navigationTimeoutRef.current) {
2440
clearTimeout(navigationTimeoutRef.current);
@@ -29,9 +45,6 @@ export const useDragEdgeNavigation = (
2945
return;
3046
}
3147

32-
// Handle both timed and all-day events
33-
if (!state.draft) return;
34-
3548
const updateMousePosition = (event: MouseEvent) => {
3649
setMousePosition({ x: event.clientX, y: event.clientY });
3750
};
@@ -41,16 +54,16 @@ export const useDragEdgeNavigation = (
4154
return () => {
4255
window.removeEventListener("mousemove", updateMousePosition);
4356
};
44-
}, [state.isDragging, state.draft]);
57+
}, [isDragging]);
4558

4659
// Check for edge proximity and trigger navigation
4760
useEffect(() => {
48-
if (!state.isDragging || !state.draft) {
61+
if (!isDragging || !currentDraft) {
4962
return;
5063
}
5164

5265
// Use appropriate container based on event type
53-
const isAllDay = state.draft.isAllDay;
66+
const isAllDay = currentDraft.isAllDay;
5467
const container = isAllDay
5568
? getElemById(ID_GRID_ALLDAY_ROW)
5669
: mainGridRef.current;
@@ -98,7 +111,8 @@ export const useDragEdgeNavigation = (
98111
navigationTimeoutRef.current = null;
99112
}
100113
};
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]);
102116

103117
// Cleanup on unmount
104118
useEffect(() => {

0 commit comments

Comments
 (0)