Skip to content

Commit 30244dd

Browse files
committed
🧹 Chore: cleanup sidebar draft effects and actions
1 parent f01159d commit 30244dd

File tree

4 files changed

+39
-44
lines changed

4 files changed

+39
-44
lines changed

packages/web/src/views/Calendar/components/Draft/sidebar/context/SidebarDraftProvider.tsx

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
import React, { ReactNode } 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";
52
import { DateCalcs } from "@web/views/Calendar/hooks/grid/useDateCalcs";
63
import { Measurements_Grid } from "@web/views/Calendar/hooks/grid/useGridLayout";
7-
import { useDraftForm } from "../../hooks/state/useDraftForm";
84
import { useSidebarActions } from "../hooks/useSidebarActions";
5+
import { useSidebarEffects } from "../hooks/useSidebarEffects";
96
import { useSidebarState } from "../hooks/useSidebarState";
107
import { SidebarDraftContext } from "./SidebarDraftContext";
118

@@ -19,23 +16,9 @@ export const SidebarDraftProvider = ({
1916
dateCalcs,
2017
measurements,
2118
}: Props) => {
22-
const { setters, state: _state } = useSidebarState(measurements);
23-
const actions = useSidebarActions(dateCalcs, _state, setters);
24-
25-
const _category = useAppSelector(selectDraftCategory);
26-
const category = _category || Categories_Event.TIMED;
27-
const formProps = useDraftForm(
28-
category,
29-
_state.isSomedayFormOpen,
30-
actions.discard,
31-
actions.reset,
32-
setters.setIsSomedayFormOpen,
33-
);
34-
35-
const state = {
36-
..._state,
37-
formProps,
38-
};
19+
const { setters, state } = useSidebarState(measurements);
20+
const actions = useSidebarActions(dateCalcs, state, setters);
21+
useSidebarEffects(state, actions);
3922

4023
return (
4124
<SidebarDraftContext.Provider value={{ state, setters, actions }}>

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ export const useSidebarActions = (
8888
}
8989
};
9090

91+
const closeForm = () => {
92+
setIsSomedayFormOpen(false);
93+
};
94+
9195
// call this when enabling DND for drafts
9296
const convertSomedayDraftToTimed = (
9397
dropItem: DropResult_ReactDND,
@@ -417,6 +421,7 @@ export const useSidebarActions = (
417421

418422
return {
419423
close,
424+
closeForm,
420425
createDefaultSomeday,
421426
discard,
422427
onDraft,
Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,37 @@
11
import { useEffect } from "react";
2-
import {
3-
selectIsDrafting,
4-
selectIsDraftingExisting,
5-
selectIsDraftingSomeday,
6-
} from "@web/ducks/events/selectors/draft.selectors";
2+
import { selectIsDNDing } from "@web/ducks/events/selectors/draft.selectors";
73
import { useAppSelector } from "@web/store/store.hooks";
84
import { Actions_Sidebar } from "./useSidebarActions";
5+
import { State_Sidebar } from "./useSidebarState";
96

10-
export const useSidebarEffects = (util: Actions_Sidebar) => {
11-
const { resetLocalDraftStateIfNeeded, createDefaultSomeday } = util;
12-
13-
const isDrafting = useAppSelector(selectIsDrafting);
14-
const isDraftingExisting = useAppSelector(selectIsDraftingExisting);
15-
const isDraftingSomeday = useAppSelector(selectIsDraftingSomeday);
16-
17-
useEffect(() => {
18-
const isSidebarStatePotentiallyStale = !isDraftingSomeday;
19-
if (isSidebarStatePotentiallyStale) {
20-
resetLocalDraftStateIfNeeded();
21-
}
22-
}, [isDraftingSomeday, resetLocalDraftStateIfNeeded]);
7+
export const useSidebarEffects = (
8+
state: State_Sidebar,
9+
actions: Actions_Sidebar,
10+
) => {
11+
const isDNDing = useAppSelector(selectIsDNDing);
2312

2413
useEffect(() => {
25-
const shouldStartNew = isDrafting && !isDraftingExisting;
26-
if (shouldStartNew) {
27-
createDefaultSomeday();
14+
if (isDNDing && state.isSomedayFormOpen) {
15+
actions.closeForm();
2816
}
29-
}, [isDraftingExisting, isDrafting, createDefaultSomeday]);
17+
}, [isDNDing, state.isSomedayFormOpen, actions]);
3018
};
19+
//++ TODO delete
20+
// const { resetLocalDraftStateIfNeeded, createDefaultSomeday } = actions;
21+
22+
// const isDrafting = useAppSelector(selectIsDrafting);
23+
// const isDraftingExisting = useAppSelector(selectIsDraftingExisting);
24+
// const isDraftingSomeday = useAppSelector(selectIsDraftingSomeday);
25+
// useEffect(() => {
26+
// const isSidebarStatePotentiallyStale = !isDraftingSomeday;
27+
// if (isSidebarStatePotentiallyStale) {
28+
// resetLocalDraftStateIfNeeded();
29+
// }
30+
// }, [isDraftingSomeday, resetLocalDraftStateIfNeeded]);
31+
32+
// useEffect(() => {
33+
// const shouldStartNew = isDrafting && !isDraftingExisting;
34+
// if (shouldStartNew) {
35+
// createDefaultSomeday();
36+
// }
37+
// }, [isDraftingExisting, isDrafting, createDefaultSomeday]);

packages/web/src/views/Calendar/components/Sidebar/SomedayTab/WeekSection/SomedayEvents/SomedayEventContainer/SomedayEventContainer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export const SomedayEventContainer = ({
8181
<SomedayEventForm
8282
event={event}
8383
onClose={() => {
84-
setters.setIsSomedayFormOpen(false);
84+
actions.closeForm();
8585
actions.close();
8686
}}
8787
onSubmit={onSubmit}

0 commit comments

Comments
 (0)