Skip to content

Commit e3210c7

Browse files
authored
♻️ Refactor: Reorganize someday hooks (#265)
* 🔧 Fix: Update import path for DateCalcs hook * 🔧 Fix: Allow null draft event in sidebar utility hook * 🧹 Chore: alphabetize useSidebarUtil * 🔧 Fix: Update import paths for sidebar hooks in SomedayEvents * 🐛 Fix: update how onPlaceholderClick creates a new draft * 🧹 Chore: Remove unused imports and clean up web event types * 🧹 Chore: Remove TODO comments * ♻️ Refactor: Restore closeForm() in draft actions * ♻️ Refator: use isSomedayFormOpen instead of draft.isOpen * 🔧 Fix: Add optional chaining to draft status selectors * ✨ Feat: Add drag and drop (DnD) state management for sidebar events * ♻️ Refactor: Update GridEventPreview and SomedayEvents imports and types * ♻️ Refactor: Update DraggableSomedayEvents types * chore: remove onClick handlers in Header and Sidebar * ✨ Feat: Improve draft category selection in Draft component * ✨ Feat: Add sidebar ID constant and update draft container selection * refactor(checkpoint): move sidebar state into Context * fix: simplify state in DraggableSomedayEvent * 🔧 Fix: imports from merge * 🧹 Chore: improve type-safety by adding category to resizing and drag * 🧹 Chore: remove Someday conditional from Draft.tsx Going to do this in the sidebar for now for simplicity * ♻️ refactor(checkpoint): use isSomedayFormOpen state for sidebar currently opening the correct form when clicking an existing draft need to update for new drafts (and shortcuts) * ♻️ refactor(checkpoint): close someday form on ESC need to update for new drafts (and shortcuts) * 🔧 fix: prompt for confirmation before deleting someday event from shortcut * 🔧 fix(checkpoint): update form props based on draft category the placement value is currently correct, but the form is still visually appearing in the wrong location. this is likely due to how the refs are handled * 🧹 Chore: enable DND by fixing id check in DraggableSomedayEvent * 🧹 chore(checkpoint): recompute form position within each SomedayEventContainer * 🧹 Chore: fix type issues in sidebar hooks * 🧹 Chore: cleanup sidebar draft effects and actions * 🧹 Chore: delete old effects in useSidebarEffects * 🐛: Fix ESLint configuration for Prettier plugin Replaced direct plugin usage in eslint config with plugin object. The flat config system expects each item in the array to be a valid configuration object Plugins need to be explicitly registered in the plugins field * ✨ Feat: Create sidebar drafts upon 'W' and 'M' shortcuts * 🧹 Chore: Remove unused imports and commented-out code in Draft component * 🔧Chore: remove ID_SIDEBAR as a valid response for draft container the sidebar isn't being used as a container now, so this makes the code easier to understand * 🧹Chore: rearrange someday files
1 parent 882b9c2 commit e3210c7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+727
-662
lines changed

packages/web/src/common/constants/web.constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export const ID_GRID_EVENTS_TIMED = "timedEvents";
1313
export const ID_GRID_MAIN = "mainGrid";
1414
export const ID_MAIN = "mainSection";
1515
export const ID_DATEPICKER_SIDEBAR = "sidebarDatePicker";
16+
export const ID_SIDEBAR = "sidebar";
1617
export const ID_SOMEDAY_DRAFT = "somedayDraft";
1718
export const ID_SOMEDAY_EVENTS = "ID_SOMEDAY_EVENTS";
1819
export const ID_SOMEDAY_EVENT_FORM = "Someday Event Form";

packages/web/src/common/types/web.event.types.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
import { z } from "zod";
2-
import {
3-
Categories_Event,
4-
CoreEventSchema,
5-
Schema_Event,
6-
} from "@core/types/event.types";
2+
import { CoreEventSchema, Schema_Event } from "@core/types/event.types";
73
import { SelectOption } from "@web/common/types/component.types";
8-
import { Activity_DraftEvent } from "@web/ducks/events/slices/draft.slice.types";
94

105
export enum Recurrence_Selection {
116
NONE = "none",
@@ -22,7 +17,7 @@ export const GridEventSchema = CoreEventSchema.extend({
2217
export interface Schema_GridEvent extends Schema_Event {
2318
hasFlipped?: boolean;
2419
isOpen?: boolean;
25-
row?: number; //TODO: delete if not used
20+
row?: number;
2621
position: {
2722
isOverlapping: boolean;
2823
widthMultiplier: number; // EG: 0.5 for half width

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { Categories_Event } from "@core/types/event.types";
44
import {
55
ID_GRID_EVENTS_ALLDAY,
66
ID_GRID_EVENTS_TIMED,
7+
ID_SIDEBAR,
78
} from "@web/common/constants/web.constants";
89
import { Schema_GridEvent } from "@web/common/types/web.event.types";
910
import { roundToNext } from "@web/common/utils";
@@ -67,10 +68,11 @@ export const getDraftTimes = (isCurrentWeek: boolean, startOfWeek: Dayjs) => {
6768
return { startDate, endDate };
6869
};
6970

70-
export const getDraftContainer = (isAllDay: boolean) => {
71-
if (isAllDay) {
72-
return getElemById(ID_GRID_EVENTS_ALLDAY);
71+
export const getDraftContainer = (category: Categories_Event) => {
72+
switch (category) {
73+
case Categories_Event.ALLDAY:
74+
return getElemById(ID_GRID_EVENTS_ALLDAY);
75+
case Categories_Event.TIMED:
76+
return getElemById(ID_GRID_EVENTS_TIMED);
7377
}
74-
75-
return getElemById(ID_GRID_EVENTS_TIMED);
7678
};

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ export const prepEvtAfterDraftDrop = (
241241
};
242242

243243
export const prepEvtBeforeSubmit = (
244-
draft: Schema_GridEvent,
244+
draft: Schema_Event | Schema_GridEvent,
245245
userId: string,
246246
) => {
247247
const _event = {

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

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,27 @@ import { RootState } from "@web/store";
33

44
export const selectDraft = (state: RootState) => state.events.draft.event;
55

6+
export const selectDraftActivity = (state: RootState) =>
7+
state.events.draft.status?.activity;
8+
9+
export const selectDraftCategory = (state: RootState) =>
10+
state.events.draft.status?.eventType;
11+
12+
export const selectDraftId = (state: RootState) =>
13+
state.events.draft.event?._id;
14+
615
export const selectDraftStatus = (state: RootState) =>
716
state.events.draft.status;
817

18+
export const selectIsDNDing = (state: RootState) =>
19+
state.events.draft.status?.activity === "dnd";
20+
921
export const selectIsDrafting = (state: RootState) =>
10-
state.events.draft.status.isDrafting;
22+
state.events.draft.status?.isDrafting;
1123

1224
export const selectIsDraftingExisting = (state: RootState) =>
1325
state.events.draft.event?._id !== undefined;
1426

1527
export const selectIsDraftingSomeday = (state: RootState) =>
16-
state.events.draft.status.eventType === Categories_Event.SOMEDAY_WEEK ||
17-
state.events.draft.status.eventType === Categories_Event.SOMEDAY_MONTH;
18-
19-
export const selectDraftId = (state: RootState) =>
20-
state.events.draft.event?._id;
28+
state.events.draft.status?.eventType === Categories_Event.SOMEDAY_WEEK ||
29+
state.events.draft.status?.eventType === Categories_Event.SOMEDAY_MONTH;

packages/web/src/ducks/events/slices/draft.slice.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,24 +34,34 @@ export const draftSlice = createSlice({
3434
},
3535

3636
startResizing: (state, action: Action_Draft_Resize) => {
37-
const { event, dateToChange } = action.payload;
37+
const { category, event, dateToChange } = action.payload;
3838
return {
3939
event,
4040
status: {
4141
...state.status,
4242
activity: "resizing",
4343
dateToResize: dateToChange,
44+
eventType: category,
4445
isDrafting: true,
4546
},
4647
};
4748
},
4849

50+
startDnd: (state) => {
51+
state.status = {
52+
...state.status,
53+
activity: "dnd",
54+
isDrafting: true,
55+
};
56+
},
57+
4958
startDragging: (state, action) => {
50-
const { event } = action.payload;
59+
const { category, event } = action.payload;
5160
state.event = event;
5261
state.status = {
5362
...state.status,
5463
activity: "dragging",
64+
eventType: category,
5565
isDrafting: true,
5666
};
5767
},

packages/web/src/ducks/events/slices/draft.slice.types.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ export interface Action_DraftEvent extends Action {
77
}
88
export type Activity_DraftEvent =
99
| "createShortcut"
10-
| "eventRightClick"
10+
| "dnd"
1111
| "dragging"
12+
| "eventRightClick"
1213
| "gridClick"
1314
| "resizing"
1415
| "sidebarClick";
@@ -35,6 +36,7 @@ interface Payload_DraftEvent {
3536
}
3637

3738
interface Payload_Draft_Resize {
39+
category: Categories_Event;
3840
event: Schema_Event;
3941
dateToChange: "startDate" | "endDate";
4042
}

packages/web/src/views/Calendar/Calendar.tsx

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ import { RootProps } from "./calendarView.types";
99
import { Dedication } from "./components/Dedication";
1010
import { Draft } from "./components/Draft/Draft";
1111
import { DraftProvider } from "./components/Draft/context/DraftProvider";
12+
import { SidebarDraftProvider } from "./components/Draft/sidebar/context/SidebarDraftProvider";
1213
import { Grid } from "./components/Grid/";
1314
import { Header } from "./components/Header";
14-
import { Sidebar } from "./components/Sidebar";
15+
import { Sidebar } from "./components/Sidebar/Sidebar";
1516
import { useDateCalcs } from "./hooks/grid/useDateCalcs";
1617
import { useGridLayout } from "./hooks/grid/useGridLayout";
1718
import { useScroll } from "./hooks/grid/useScroll";
@@ -67,15 +68,17 @@ export const CalendarView = () => {
6768
weekProps={weekProps}
6869
isSidebarOpen={isSidebarOpen}
6970
>
70-
<Draft measurements={measurements} weekProps={weekProps} />
71-
{isSidebarOpen && (
72-
<Sidebar
73-
dateCalcs={dateCalcs}
74-
measurements={measurements}
75-
weekProps={weekProps}
76-
gridRefs={gridRefs}
77-
/>
78-
)}
71+
<SidebarDraftProvider dateCalcs={dateCalcs} measurements={measurements}>
72+
<Draft measurements={measurements} weekProps={weekProps} />
73+
{isSidebarOpen && (
74+
<Sidebar
75+
dateCalcs={dateCalcs}
76+
measurements={measurements}
77+
weekProps={weekProps}
78+
gridRefs={gridRefs}
79+
/>
80+
)}
81+
</SidebarDraftProvider>
7982
<StyledCalendar direction={FlexDirections.COLUMN} id={ID_MAIN}>
8083
<Header
8184
rootProps={rootProps}

packages/web/src/views/Calendar/components/Draft/Draft.tsx

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,43 @@
1-
import React, { FC, useEffect, useState } from "react";
1+
import React, { FC } from "react";
22
import { createPortal } from "react-dom";
33
import { Categories_Event } from "@core/types/event.types";
44
import { getDraftContainer } from "@web/common/utils/draft/draft.util";
5-
import { getCategory } from "@web/common/utils/event.util";
6-
import { selectIsDrafting } from "@web/ducks/events/selectors/draft.selectors";
5+
import { selectDraftCategory } from "@web/ducks/events/selectors/draft.selectors";
76
import { useAppSelector } from "@web/store/store.hooks";
87
import { Measurements_Grid } from "@web/views/Calendar/hooks/grid/useGridLayout";
98
import { WeekProps } from "@web/views/Calendar/hooks/useWeek";
10-
import { GridDraft } from "./GridDraft";
119
import { useDraftContext } from "./context/useDraftContext";
12-
import { useGridClick } from "./hooks/grid/useGridClick";
13-
import { useGridMouseMove } from "./hooks/grid/useGridMouseMove";
10+
import { GridDraft } from "./grid/GridDraft";
11+
import { useGridClick } from "./grid/hooks/useGridClick";
12+
import { useGridMouseMove } from "./grid/hooks/useGridMouseMove";
1413

1514
interface Props {
1615
measurements: Measurements_Grid;
1716
weekProps: WeekProps;
1817
}
1918

2019
export const Draft: FC<Props> = ({ measurements, weekProps }) => {
21-
const [isLoadingDOM, setIsLoadingDOM] = useState(true);
22-
23-
useEffect(() => {
24-
setIsLoadingDOM(false);
25-
}, []);
26-
2720
useGridClick();
2821
useGridMouseMove();
2922

23+
const category = useAppSelector(selectDraftCategory);
3024
const { state } = useDraftContext();
3125
const { draft, isDragging, isResizing } = state;
32-
const isDrafting = useAppSelector(selectIsDrafting);
33-
34-
if (isLoadingDOM || !draft || !isDrafting) return null;
3526

3627
if (draft?.isAllDay === undefined) {
37-
console.error("draft.isAllDay is undefined", draft);
3828
return null;
3929
}
40-
const container = getDraftContainer(draft.isAllDay);
41-
const category = getCategory(draft);
42-
const isGridEvent =
30+
if (!category) return null;
31+
32+
const container = getDraftContainer(category);
33+
if (!container) return null;
34+
35+
const isGridDraft =
4336
category === Categories_Event.ALLDAY || category === Categories_Event.TIMED;
4437

4538
return createPortal(
4639
<>
47-
{isGridEvent && (
40+
{isGridDraft && (
4841
<GridDraft
4942
draft={draft}
5043
isDragging={isDragging}

packages/web/src/views/Calendar/components/Draft/context/DraftProvider.tsx

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import React from "react";
2+
import { Categories_Event } from "@core/types/event.types";
3+
import { selectDraftCategory } from "@web/ducks/events/selectors/draft.selectors";
4+
import { useAppSelector } from "@web/store/store.hooks";
25
import { DateCalcs } from "@web/views/Calendar/hooks/grid/useDateCalcs";
36
import { WeekProps } from "@web/views/Calendar/hooks/useWeek";
47
import { useDraftActions } from "../hooks/actions/useDraftActions";
58
import { useDraftForm } from "../hooks/state/useDraftForm";
69
import { useDraftState } from "../hooks/state/useDraftState";
7-
import { DraftContext, State_Draft_Combined } from "./DraftContext";
10+
import { DraftContext, State_Draft } from "./DraftContext";
811

912
interface DraftProviderProps {
1013
children: React.ReactNode;
@@ -29,9 +32,18 @@ export const DraftProvider = ({
2932
const { discard, reset } = actions;
3033
const { isFormOpen } = originalState;
3134
const { setIsFormOpen } = setters;
32-
const formProps = useDraftForm(isFormOpen, discard, reset, setIsFormOpen);
3335

34-
const state: State_Draft_Combined = {
36+
const _category = useAppSelector(selectDraftCategory);
37+
const category = _category || Categories_Event.TIMED;
38+
const formProps = useDraftForm(
39+
category,
40+
isFormOpen,
41+
discard,
42+
reset,
43+
setIsFormOpen,
44+
);
45+
46+
const state: State_Draft = {
3547
...originalState,
3648
formProps,
3749
};

0 commit comments

Comments
 (0)