Skip to content

Commit 1b44d67

Browse files
committed
♻️ Refator: use isSomedayFormOpen instead of draft.isOpen
1 parent efc6fdb commit 1b44d67

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

packages/web/src/views/Calendar/components/Draft/hooks/sidebar/useSidebar.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export const useSidebar = (
1515
state,
1616
state.setDraft,
1717
state.setIsDrafting,
18+
state.setIsSomedayFormOpen,
1819
);
1920
useSidebarEffects(util);
2021

packages/web/src/views/Calendar/components/Draft/hooks/sidebar/useSidebarState.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useState, useEffect } from "react";
2-
import { Schema_GridEvent } from "@web/common/types/web.event.types";
2+
import { Schema_Event } from "@core/types/event.types";
33
import { COLUMN_MONTH, COLUMN_WEEK } from "@web/common/constants/web.constants";
44
import { Measurements_Grid } from "@web/views/Calendar/hooks/grid/useGridLayout";
55
import { useAppSelector } from "@web/store/store.hooks";
@@ -18,13 +18,14 @@ export const useSidebarState = (measurements: Measurements_Grid) => {
1818

1919
const { eventType: draftType } = useAppSelector(selectDraftStatus);
2020

21-
const [draft, setDraft] = useState<Schema_GridEvent | null>(null);
21+
const [draft, setDraft] = useState<Schema_Event | null>(null);
2222
const [isDrafting, setIsDrafting] = useState(false);
2323
const [isDraftingExisting, setIsDraftingExisting] = useState(false);
24+
const [isSomedayFormOpen, setIsSomedayFormOpen] = useState(false);
2425

2526
const isDragging = isDrafting && draft !== null;
2627
const { isOverAllDayRow, isOverGrid, isOverMainGrid, mouseCoords } =
27-
useMousePosition(isDragging, draft?.isOpen, measurements);
28+
useMousePosition(isDragging, isSomedayFormOpen, measurements);
2829

2930
const somedayWeekIds = somedayEvents.columns[COLUMN_WEEK]
3031
.eventIds as string[];
@@ -35,7 +36,8 @@ export const useSidebarState = (measurements: Measurements_Grid) => {
3536
const isDraftingNew =
3637
isDrafting && !isDraftingExisting && !somedayIds.includes(draft?._id);
3738

38-
const shouldPreviewOnGrid = draft !== null && isOverGrid && !draft?.isOpen;
39+
const shouldPreviewOnGrid =
40+
draft !== null && isOverGrid && !isSomedayFormOpen;
3941

4042
return {
4143
draft,
@@ -56,6 +58,7 @@ export const useSidebarState = (measurements: Measurements_Grid) => {
5658
setDraft,
5759
setIsDrafting,
5860
setIsDraftingExisting,
61+
setIsSomedayFormOpen,
5962
setSomedayEvents,
6063
};
6164
};

packages/web/src/views/Calendar/components/Draft/hooks/sidebar/useSidebarUtil.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,9 @@ import { State_Sidebar } from "./useSidebarState";
4747
export const useSidebarUtil = (
4848
dateCalcs: DateCalcs,
4949
state: State_Sidebar,
50-
setDraft: React.Dispatch<React.SetStateAction<Schema_GridEvent | null>>,
50+
setDraft: React.Dispatch<React.SetStateAction<Schema_Event | null>>,
5151
setIsDrafting: React.Dispatch<React.SetStateAction<boolean>>,
52+
setIsSomedayFormOpen: React.Dispatch<React.SetStateAction<boolean>>,
5253
) => {
5354
const dispatch = useAppDispatch();
5455

@@ -154,7 +155,8 @@ export const useSidebarUtil = (
154155
Categories_Event.SOMEDAY_WEEK,
155156
);
156157

157-
setDraft({ ...somedayDefault, isOpen: true });
158+
setDraft(somedayDefault);
159+
setIsSomedayFormOpen(true);
158160
setIsDrafting(true);
159161
}, [setDraft]);
160162

@@ -184,10 +186,7 @@ export const useSidebarUtil = (
184186

185187
const onDraft = (event: Schema_Event, category: Categories_Event) => {
186188
state.setIsDrafting(true);
187-
state.setDraft({
188-
...event,
189-
isOpen: true,
190-
});
189+
state.setDraft(event);
191190

192191
dispatch(
193192
draftSlice.actions.start({

0 commit comments

Comments
 (0)