Skip to content

Commit b1c49bc

Browse files
Merge pull request #338 from SwitchbackTech/bug_fix_events_lose_position_when_week_change
🐛 Fix: grid events losing position when changing to next/prev week
2 parents d3324c5 + 92341b1 commit b1c49bc

File tree

4 files changed

+59
-44
lines changed

4 files changed

+59
-44
lines changed

packages/web/src/common/store/helpers/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ export const createAsyncSlice = <
4444

4545
const reducers = {
4646
request: (state, _action: PayloadAction<Draft<RequestPayload>>) => {
47+
// When running tests, we use mock data, so we don't need to fetch the week events from the API
48+
// See comments in https://github.com/SwitchbackTech/compass/pull/338 for dev notes
49+
if (process.env.NODE_ENV === "test") {
50+
return;
51+
}
52+
4753
state.isProcessing = true;
4854
state.isSuccess = false;
4955
state.error = null;

packages/web/src/ducks/events/selectors/util.selectors.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ export const selectIsProcessing = (state: RootState) =>
1010
isProcessing(state.events.createEvent) ||
1111
isProcessing(state.events.getWeekEvents);
1212

13+
export const selectIsGetWeekEventsProcessing = (state: RootState) =>
14+
isProcessing(state.events.getWeekEvents);
15+
1316
export const selectEventIdsBySectionType = (
1417
state: RootState,
1518
type: SectionType,

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

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { Schema_GridEvent } from "@web/common/types/web.event.types";
55
import { isLeftClick } from "@web/common/utils/mouse/mouse.util";
66
import { selectDraftId } from "@web/ducks/events/selectors/draft.selectors";
77
import { selectAllDayEvents } from "@web/ducks/events/selectors/event.selectors";
8+
import { selectIsGetWeekEventsProcessing } from "@web/ducks/events/selectors/util.selectors";
89
import { draftSlice } from "@web/ducks/events/slices/draft.slice";
910
import { useAppDispatch, useAppSelector } from "@web/store/store.hooks";
1011
import { useGridEventMouseDown } from "@web/views/Calendar/hooks/grid/useGridEventMouseDown";
@@ -24,6 +25,7 @@ export const AllDayEvents = ({
2425
endOfView,
2526
}: Props) => {
2627
const allDayEvents = useAppSelector(selectAllDayEvents);
28+
const isProcessing = useAppSelector(selectIsGetWeekEventsProcessing);
2729
const draftId = useAppSelector(selectDraftId);
2830
const dispatch = useAppDispatch();
2931

@@ -54,24 +56,25 @@ export const AllDayEvents = ({
5456

5557
return (
5658
<StyledEvents id={ID_GRID_EVENTS_ALLDAY}>
57-
{allDayEvents.map((event: Schema_GridEvent, i) => {
58-
return (
59-
<AllDayEventMemo
60-
key={`${event.title}-${i}`}
61-
isPlaceholder={event._id === draftId}
62-
event={event}
63-
startOfView={startOfView}
64-
endOfView={endOfView}
65-
measurements={measurements}
66-
onMouseDown={(e, event) => {
67-
if (!isLeftClick(e)) {
68-
return;
69-
}
70-
onMouseDown(e, event);
71-
}}
72-
/>
73-
);
74-
})}
59+
{!isProcessing &&
60+
allDayEvents.map((event: Schema_GridEvent, i) => {
61+
return (
62+
<AllDayEventMemo
63+
key={`${event.title}-${i}`}
64+
isPlaceholder={event._id === draftId}
65+
event={event}
66+
startOfView={startOfView}
67+
endOfView={endOfView}
68+
measurements={measurements}
69+
onMouseDown={(e, event) => {
70+
if (!isLeftClick(e)) {
71+
return;
72+
}
73+
onMouseDown(e, event);
74+
}}
75+
/>
76+
);
77+
})}
7578
</StyledEvents>
7679
);
7780
};

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

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { Schema_GridEvent } from "@web/common/types/web.event.types";
55
import { adjustOverlappingEvents } from "@web/common/utils/overlap/overlap";
66
import { selectDraftId } from "@web/ducks/events/selectors/draft.selectors";
77
import { selectGridEvents } from "@web/ducks/events/selectors/event.selectors";
8+
import { selectIsGetWeekEventsProcessing } from "@web/ducks/events/selectors/util.selectors";
89
import { draftSlice } from "@web/ducks/events/slices/draft.slice";
910
import { useAppDispatch, useAppSelector } from "@web/store/store.hooks";
1011
import { useGridEventMouseDown } from "@web/views/Calendar/hooks/grid/useGridEventMouseDown";
@@ -21,6 +22,7 @@ export const MainGridEvents = ({ measurements, weekProps }: Props) => {
2122
const dispatch = useAppDispatch();
2223

2324
const timedEvents = useAppSelector(selectGridEvents);
25+
const isProcessing = useAppSelector(selectIsGetWeekEventsProcessing);
2426
const draftId = useAppSelector(selectDraftId);
2527

2628
const adjustedEvents = adjustOverlappingEvents(timedEvents);
@@ -66,32 +68,33 @@ export const MainGridEvents = ({ measurements, weekProps }: Props) => {
6668

6769
return (
6870
<div id={ID_GRID_EVENTS_TIMED}>
69-
{adjustedEvents.map((event: Schema_GridEvent) => {
70-
return (
71-
<GridEventMemo
72-
event={event}
73-
isDragging={false}
74-
isDraft={false}
75-
isPlaceholder={event._id === draftId}
76-
isResizing={false}
77-
key={`initial-${event._id}`}
78-
measurements={measurements}
79-
onEventMouseDown={(event, e) => {
80-
onMouseDown(e, event);
81-
}}
82-
onScalerMouseDown={(
83-
event,
84-
e,
85-
dateToChange: "startDate" | "endDate",
86-
) => {
87-
e.stopPropagation();
88-
e.preventDefault();
89-
resizeTimedEvent(event, dateToChange);
90-
}}
91-
weekProps={weekProps}
92-
/>
93-
);
94-
})}
71+
{!isProcessing &&
72+
adjustedEvents.map((event: Schema_GridEvent) => {
73+
return (
74+
<GridEventMemo
75+
event={event}
76+
isDragging={false}
77+
isDraft={false}
78+
isPlaceholder={event._id === draftId}
79+
isResizing={false}
80+
key={`initial-${event._id}`}
81+
measurements={measurements}
82+
onEventMouseDown={(event, e) => {
83+
onMouseDown(e, event);
84+
}}
85+
onScalerMouseDown={(
86+
event,
87+
e,
88+
dateToChange: "startDate" | "endDate",
89+
) => {
90+
e.stopPropagation();
91+
e.preventDefault();
92+
resizeTimedEvent(event, dateToChange);
93+
}}
94+
weekProps={weekProps}
95+
/>
96+
);
97+
})}
9598
</div>
9699
);
97100
};

0 commit comments

Comments
 (0)