Skip to content

Commit c80757d

Browse files
committed
bug(web): handle edge case with dragging an event to very bottom of the page, causing event to overflow past container. Refactor code
this occurs when we drag an event to the very bottom until the event's end time is past midnight, instead of preventing me from dragging the event past midnight, the event overflows past its container.
1 parent b0e1929 commit c80757d

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

packages/web/src/views/Calendar/components/Draft/hooks/actions/useDraftActions.ts

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -161,29 +161,33 @@ export const useDraftActions = (
161161
const updateTimesDuringDrag = (e: MouseEvent) => {
162162
setDraft((_draft) => {
163163
const x = getX(e, isSidebarOpen);
164-
const _initialStart = dateCalcs.getDateByXY(
164+
const startEndDurationMin = dragStatus?.durationMin || 0;
165+
166+
let eventStart = dateCalcs.getDateByXY(
165167
x,
166168
e.clientY,
167169
weekProps.component.startOfView,
168170
);
169171

170-
const startDate = _draft?.isAllDay
171-
? _initialStart.format(YEAR_MONTH_DAY_FORMAT)
172-
: _initialStart.format();
173-
174-
const _end = _initialStart.add(
175-
dragStatus?.durationMin || 0,
176-
"minutes",
177-
);
172+
let eventEnd = eventStart.add(startEndDurationMin, "minutes");
178173

179-
const endDate = _draft.isAllDay
180-
? _end.format(YEAR_MONTH_DAY_FORMAT)
181-
: _end.format();
174+
if (!_draft.isAllDay) {
175+
// Edge case: timed events' end times can overflow past midnight at the bottom of the grid.
176+
// Below logic prevents that from occurring.
177+
if (eventEnd.date() !== eventStart.date()) {
178+
eventEnd = eventEnd.hour(0).minute(0);
179+
eventStart = eventEnd.subtract(startEndDurationMin, "minutes");
180+
}
181+
}
182182

183183
return {
184184
..._draft,
185-
startDate,
186-
endDate,
185+
startDate: _draft.isAllDay
186+
? eventStart.format(YEAR_MONTH_DAY_FORMAT)
187+
: eventStart.format(),
188+
endDate: _draft.isAllDay
189+
? eventEnd.format(YEAR_MONTH_DAY_FORMAT)
190+
: eventEnd.format(),
187191
priority: _draft?.priority || Priorities.UNASSIGNED,
188192
};
189193
});

0 commit comments

Comments
 (0)