Skip to content

Commit e09f39b

Browse files
committed
✨ Feat: Refactor event handling to use Schema_GridEvent and improve type safety
1 parent 5a1700a commit e09f39b

File tree

6 files changed

+21
-15
lines changed

6 files changed

+21
-15
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ export const getCategory = (event: Schema_Event) => {
8888
export const assembleGridEvent = (
8989
event: Partial<Schema_GridEvent>
9090
): Schema_GridEvent => {
91-
// TODO: Maybe move to a constants file?
9291
const DEFAULT_POSITION = {
9392
isOverlapping: false,
9493
widthMultiplier: 1,

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,12 @@ export const assignEventToRow = (
4343
return { fits, rowNum };
4444
};
4545

46-
export const assignEventsToRow = (allDayEvents: Schema_Event[]) => {
46+
export const assignEventsToRow = (
47+
allDayEvents: Schema_Event[]
48+
): {
49+
rowsCount: number;
50+
allDayEvents: Schema_GridEvent[];
51+
} => {
4752
const rows: number[][] = [];
4853
// makes copy of all event objects to allow for adding a 'row' field
4954
// can likely be optimized using immer's `produce` and `draft`
@@ -442,7 +447,8 @@ export const getAbsoluteLeftPosition = (
442447
}
443448

444449
if (
445-
event.position?.isOverlapping &&
450+
!event.isAllDay &&
451+
event.position.isOverlapping &&
446452
event.position.horizontalOrder > 1
447453
) {
448454
positionStart += eventWidth * (event.position.horizontalOrder - 1);

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,18 @@ import { assignEventsToRow } from "@web/common/utils/grid.util";
55
import { Schema_GridEvent } from "@web/common/types/web.event.types";
66
import { assembleGridEvent } from "@web/common/utils/event.util";
77

8+
type Schema_GridEvent_NoPosition = Omit<Schema_GridEvent, "position">;
9+
810
export const selectAllDayEvents = createSelector(
911
(state: RootState) => state.events.entities.value || {},
1012
(state: RootState) => state.events.getWeekEvents.value || [],
1113
(entities, weekIds) => {
1214
if (!("data" in weekIds) || weekIds.data.length === 0) return [];
1315

14-
const weekEvents: Schema_Event[] = weekIds.data.map(
16+
const weekEvents: Schema_GridEvent_NoPosition[] = weekIds.data.map(
1517
(_id: string) => entities[_id]
1618
);
17-
const _allDayEvents: Schema_Event[] = weekEvents.filter(
19+
const _allDayEvents: Schema_GridEvent_NoPosition[] = weekEvents.filter(
1820
(e: Schema_Event) => e !== undefined && e.isAllDay
1921
);
2022
const { allDayEvents } = assignEventsToRow(_allDayEvents);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ import React, {
66
useMemo,
77
} from "react";
88
import dayjs from "dayjs";
9+
import { Priorities } from "@core/constants/core.constants";
910
import { Schema_GridEvent } from "@web/common/types/web.event.types";
11+
import { isOptimisticEvent } from "@web/common/utils/event.util";
1012
import { Measurements_Grid } from "@web/views/Calendar/hooks/grid/useGridLayout";
1113
import { WeekProps } from "@web/views/Calendar/hooks/useWeek";
1214
import { Flex } from "@web/components/Flex";
@@ -22,8 +24,6 @@ import { ZIndex } from "@web/common/constants/web.constants";
2224
import { Text } from "@web/components/Text";
2325

2426
import { StyledEvent, StyledEventScaler, StyledEventTitle } from "../../styled";
25-
import { Priorities } from "@core/constants/core.constants";
26-
import { isOptimisticEvent } from "@web/common/utils/event.util";
2727

2828
interface Props {
2929
event: Schema_GridEvent;

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import dayjs from "dayjs";
22
import React, { memo, MouseEvent } from "react";
3-
import { Schema_Event } from "@core/types/event.types";
3+
import { Priorities } from "@core/constants/core.constants";
44
import { Flex } from "@web/components/Flex";
5+
import { Schema_GridEvent } from "@web/common/types/web.event.types";
6+
import { isOptimisticEvent } from "@web/common/utils/event.util";
57
import { AlignItems, FlexDirections } from "@web/components/Flex/styled";
68
import { SpaceCharacter } from "@web/components/SpaceCharacter";
79
import { getPosition } from "@web/views/Calendar/hooks/event/getPosition";
@@ -10,17 +12,14 @@ import { WeekProps } from "@web/views/Calendar/hooks/useWeek";
1012
import { Text } from "@web/components/Text";
1113

1214
import { StyledEvent } from "../../Event/styled";
13-
import { Schema_GridEvent } from "@web/common/types/web.event.types";
14-
import { Priorities } from "@core/constants/core.constants";
15-
import { isOptimisticEvent } from "@web/common/utils/event.util";
1615

1716
interface Props {
1817
event: Schema_GridEvent;
1918
isPlaceholder: boolean;
2019
measurements: Measurements_Grid;
2120
startOfView: WeekProps["component"]["startOfView"];
2221
endOfView: WeekProps["component"]["endOfView"];
23-
onMouseDown: (e: MouseEvent, event: Schema_Event) => void;
22+
onMouseDown: (e: MouseEvent, event: Schema_GridEvent) => void;
2423
}
2524

2625
const AllDayEvent = ({

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { MouseEvent } from "react";
2-
import { Schema_Event } from "@core/types/event.types";
32
import { ID_GRID_EVENTS_ALLDAY } from "@web/common/constants/web.constants";
3+
import { Schema_GridEvent } from "@web/common/types/web.event.types";
44
import { Measurements_Grid } from "@web/views/Calendar/hooks/grid/useGridLayout";
55
import { WeekProps } from "@web/views/Calendar/hooks/useWeek";
66
import { useAppDispatch, useAppSelector } from "@web/store/store.hooks";
@@ -26,7 +26,7 @@ export const AllDayEvents = ({
2626
const draftId = useAppSelector(selectDraftId);
2727
const dispatch = useAppDispatch();
2828

29-
const onMouseDown = (e: MouseEvent, event: Schema_Event) => {
29+
const onMouseDown = (e: MouseEvent, event: Schema_GridEvent) => {
3030
e.stopPropagation();
3131

3232
if (isSomedayEventFormOpen()) {
@@ -38,7 +38,7 @@ export const AllDayEvents = ({
3838

3939
return (
4040
<StyledEvents id={ID_GRID_EVENTS_ALLDAY}>
41-
{allDayEvents.map((event: Schema_Event, i) => {
41+
{allDayEvents.map((event: Schema_GridEvent, i) => {
4242
return (
4343
<AllDayEventMemo
4444
key={`${event.title}-${i}`}

0 commit comments

Comments
 (0)