Skip to content

Commit c97db87

Browse files
fix(web): infinite week changes when dragging someday event to edge of calendar (#902)
1 parent ac8aed5 commit c97db87

5 files changed

Lines changed: 27 additions & 16 deletions

File tree

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Dayjs } from "dayjs";
22
import React, { FC } from "react";
33
import { AllDayRow } from "@web/views/Calendar/components/Grid/AllDayRow";
44
import { MainGrid } from "@web/views/Calendar/components/Grid/MainGrid";
5+
import { EdgeNavigationIndicators } from "@web/views/Calendar/components/Grid/MainGrid/EdgeNavigationIndicators";
56
import { DateCalcs } from "@web/views/Calendar/hooks/grid/useDateCalcs";
67
import { useDragEdgeNavigation } from "@web/views/Calendar/hooks/grid/useDragEdgeNavigation";
78
import { Refs_Grid } from "@web/views/Calendar/hooks/grid/useGridLayout";
@@ -31,7 +32,7 @@ export const Grid: FC<Props> = ({
3132
const dragEdgeState = useDragEdgeNavigation(mainGridRef, weekProps);
3233

3334
return (
34-
<>
35+
<div style={{ height: "100%", width: "100%", position: "relative" }}>
3536
<AllDayRow
3637
allDayRef={allDayRef}
3738
dateCalcs={dateCalcs}
@@ -49,6 +50,7 @@ export const Grid: FC<Props> = ({
4950
weekProps={weekProps}
5051
dragEdgeState={dragEdgeState}
5152
/>
52-
</>
53+
<EdgeNavigationIndicators dragEdgeState={dragEdgeState} />
54+
</div>
5355
);
5456
};

packages/web/src/views/Calendar/components/Grid/MainGrid/MainGrid.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import { Measurements_Grid } from "@web/views/Calendar/hooks/grid/useGridLayout"
1616
import { WeekProps } from "@web/views/Calendar/hooks/useWeek";
1717
import { DRAFT_DURATION_MIN } from "@web/views/Calendar/layout.constants";
1818
import { MainGridColumns } from "../Columns/MainGridColumns";
19-
import { EdgeNavigationIndicators } from "./EdgeNavigationIndicators";
2019
import { MainGridEvents } from "./MainGridEvents";
2120
import {
2221
StyledGridRow,
@@ -99,8 +98,6 @@ export const MainGrid: FC<Props> = ({
9998
</StyledGridWithTimeLabels>
10099

101100
<MainGridEvents measurements={measurements} weekProps={weekProps} />
102-
103-
<EdgeNavigationIndicators dragEdgeState={dragEdgeState} />
104101
</StyledMainGrid>
105102
);
106103
};

packages/web/src/views/Calendar/components/Grid/MainGrid/styled.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export const StyledGridWithTimeLabels = styled.div`
3030
export const StyledMainGrid = styled.div`
3131
flex: 1;
3232
margin-bottom: ${GRID_PADDING_BOTTOM}px;
33+
height: 100%;
3334
width: 100%;
3435
position: relative;
3536
overflow-y: auto;

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

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
import { MutableRefObject, useEffect, useRef, useState } from "react";
2-
import { ID_GRID_ALLDAY_ROW } from "@web/common/constants/web.constants";
3-
import { getElemById } from "@web/common/utils/grid.util";
42
import { selectIsDNDing } from "@web/ducks/events/selectors/draft.selectors";
53
import { useAppSelector } from "@web/store/store.hooks";
64
import { useDraftContext } from "@web/views/Calendar/components/Draft/context/useDraftContext";
@@ -78,18 +76,27 @@ export const useDragEdgeNavigation = (
7876
return;
7977
}
8078

81-
// Use appropriate container based on event type
82-
const isAllDay = currentDraft.isAllDay;
83-
const container = isAllDay
84-
? getElemById(ID_GRID_ALLDAY_ROW)
85-
: mainGridRef.current;
79+
// Check if mouse is over the main calendar grid
80+
if (!mainGridRef.current) {
81+
return;
82+
}
83+
84+
const calendarBounds = mainGridRef.current.getBoundingClientRect();
85+
const { x, y } = mousePosition;
86+
87+
const isMouseOverCalendar =
88+
x >= calendarBounds.left &&
89+
x <= calendarBounds.right &&
90+
y >= calendarBounds.top &&
91+
y <= calendarBounds.bottom;
8692

87-
if (!container) {
93+
// Only proceed with edge detection if mouse is over calendar
94+
if (!isMouseOverCalendar) {
8895
return;
8996
}
9097

91-
const { left, right } = container.getBoundingClientRect();
92-
const { x } = mousePosition;
98+
// Use main calendar bounds for edge detection
99+
const { left, right } = calendarBounds;
93100

94101
let currentEdge: "left" | "right" | null = null;
95102

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,11 @@ export const useDragEventSmartScroll = (
3535
if (!container) return;
3636
if (state.draft?.isAllDay !== false) return;
3737

38-
const { top, bottom } = container.getBoundingClientRect();
38+
const containerRect = container.getBoundingClientRect();
39+
const { top, bottom } = {
40+
top: containerRect.top,
41+
bottom: containerRect.bottom - 100,
42+
};
3943
const { y } = mousePosition;
4044

4145
let scrollAmount = 0;

0 commit comments

Comments
 (0)