Skip to content

Commit 5034a3f

Browse files
committed
fix(web): implement hotfix to address backend not returning some events when filtering
See #440
1 parent aa04679 commit 5034a3f

File tree

2 files changed

+33
-5
lines changed

2 files changed

+33
-5
lines changed

packages/web/src/common/utils/web.date.util.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,11 @@ export const toUTCOffset = (date: string | Dayjs | Date) => {
253253
} else return date.format(); // then already a DayJs object
254254
};
255255

256+
// Given an ISO string, return a string in the format of YEAR_MONTH_DAY_FORMAT
257+
export const fromUTCOffset = (date: string) => {
258+
return dayjs(date).format(YEAR_MONTH_DAY_FORMAT);
259+
};
260+
256261
const _addTimesToDates = (dt: Schema_SelectedDates) => {
257262
const start = getDayjsByTimeValue(dt.startTime.value);
258263
const startDate = dayjs(dt.startDate)

packages/web/src/ducks/events/sagas/event.sagas.ts

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
handleError,
1212
replaceIdWithOptimisticId,
1313
} from "@web/common/utils/event.util";
14+
import { fromUTCOffset } from "@web/common/utils/web.date.util";
1415
import { EventApi } from "@web/ducks/events/event.api";
1516
import { selectEventById } from "@web/ducks/events/selectors/event.selectors";
1617
import { selectPaginatedEventsBySectionType } from "@web/ducks/events/selectors/util.selectors";
@@ -161,12 +162,34 @@ function* getEvents(
161162
yield put(eventsEntitiesSlice.actions.insert(payload.data));
162163
return { data: payload.data };
163164
}
164-
const res: Response_GetEventsSuccess = (yield call(
165-
EventApi.get,
166-
payload,
167-
)) as Response_GetEventsSuccess;
168165

169-
const normalizedEvents = normalize<Schema_Event>(res.data, [
166+
// Hotfix to address issue where timed events and all-day events fetch
167+
// result does not return the correct events due to inconsistencies.
168+
// in the DB model in terms of how dates are saved.
169+
//
170+
// This hotfix works by sending 2 requests, one to handle timed events (filter is ISO-8601 date string)
171+
// and one to handle all-day events (filter is YYYY-MM-DD date string).
172+
//
173+
// The drawback is that we now send 2 requests instead of 1.
174+
//
175+
// See https://github.com/SwitchbackTech/compass/pull/440 for more details.
176+
const res: Response_GetEventsSuccess = (yield call(EventApi.get, {
177+
startDate: payload.startDate,
178+
endDate: payload.endDate,
179+
})) as Response_GetEventsSuccess;
180+
const alldayRes: Response_GetEventsSuccess = (yield call(EventApi.get, {
181+
startDate: fromUTCOffset(payload.startDate as string),
182+
endDate: fromUTCOffset(payload.endDate as string),
183+
})) as Response_GetEventsSuccess;
184+
185+
// Separating timed and all-day events removes duplicates
186+
const timedEvents = res.data.filter((event) => event.isAllDay === false);
187+
const alldayEvents = alldayRes.data.filter(
188+
(event) => event.isAllDay === true,
189+
);
190+
const events = [...timedEvents, ...alldayEvents];
191+
192+
const normalizedEvents = normalize<Schema_Event>(events, [
170193
normalizedEventsSchema(),
171194
]);
172195

0 commit comments

Comments
 (0)