Skip to content

Commit c095383

Browse files
tyler-daneCopilot
andauthored
feat(web): remove reminder from day and week views (#1402)
* refactor(web): enhance Header and MemoryRouter components for improved reminder handling - Updated `Header` component to conditionally render the `Reminder` based on the `showReminder` prop, allowing for more flexible UI rendering. - Refactored `useReminderHotkey` to accept an `enabled` parameter, enabling or disabling the hotkey functionality based on the reminder state. - Modified `MemoryRouter` utility to accept `initialEntries` for better routing control in tests. - Removed the `Edit Reminder` option from the command palette and related tests to streamline the user interface and focus on essential functionalities. * refactor(tests): remove redundant reminder tests from Calendar.form.test.tsx - Deleted tests related to reminder functionality in the Calendar form, including keyboard shortcuts and command palette interactions, to streamline the test suite and focus on essential features. - Removed unused import from DayCmdPalette.tsx to clean up the codebase. * refactor(Calendar): simplify SidebarDraftProvider props - Removed the `measurements` prop from `SidebarDraftProvider` in `CalendarView`, streamlining its usage. - Updated the `SidebarDraftProvider` component to reflect the removal of the `measurements` prop, enhancing clarity and reducing complexity. * refactor(tests): enhance custom render function in mock.render.tsx - Updated the `customRender` function to include a `CustomWrapper` option, allowing for more flexible component wrapping during tests. - Simplified the wrapper logic by creating a new `Wrapper` component that conditionally includes `CustomWrapper` or defaults to `BaseProviders`, improving test setup clarity. * refactor(tests): update mock event data and enhance test state structure - Removed local date utility from event mocks to standardize date handling. - Updated `EUROPE_TRIP` event dates to fixed values for consistency in tests. - Introduced a new `timer.baktest.ts` file with comprehensive tests for the Timer class, covering initialization, error handling, and event emissions. - Enhanced `state.weekEvents` mock to reflect accurate event counts and success states, improving test reliability. - Refactored `store.test.util.ts` to simplify state type definitions, ensuring better compatibility with mock data. * refactor(tests): streamline mock state and enhance type definitions - Removed unused event states from `state.weekEvents` mock to simplify the structure. - Updated `store.test.util.ts` to improve type definitions for test state, ensuring better compatibility with mock data. - Added `importGCal` state to `sync` in `preloadedState` for improved testing scenarios. - Enhanced type safety in `Sidebar.render.test.tsx` by specifying types for `dateCalcs` and `measurements` props. * Update packages/web/src/views/Day/view/DayViewContent.tsx Co-authored-by: Copilot <[email protected]> * refactor(tests): clean up DayCmdPalette test imports and mocks - Removed unused imports and streamlined mock setup in `DayCmdPalette.test.tsx` to enhance test clarity and maintainability. - Simplified the test structure by eliminating unnecessary dependencies, improving overall test performance. * refactor(Header): improve reminder focus handling with useCallback - Updated the `Header` component to utilize `useCallback` for the reminder focus handler, enhancing performance by memoizing the function. - Simplified the hotkey functionality to conditionally focus the reminder based on the `showReminder` prop, improving code clarity and maintainability. --------- Co-authored-by: Copilot <[email protected]>
1 parent 7419f4c commit c095383

File tree

21 files changed

+169
-192
lines changed

21 files changed

+169
-192
lines changed

packages/core/src/__mocks__/v1/events/events.misc.ts

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,6 @@ export const CLIMB: Schema_Event = {
3333
endDate: "2022-03-01T19:00:00-06:00",
3434
};
3535

36-
// Use local date to avoid timezone-dependent test failures
37-
const getLocalDateString = (): string => {
38-
const now = new Date();
39-
const year = now.getFullYear();
40-
const month = String(now.getMonth() + 1).padStart(2, "0");
41-
const day = String(now.getDate()).padStart(2, "0");
42-
return `${year}-${month}-${day}`;
43-
};
44-
45-
const today = getLocalDateString();
4636
export const EUROPE_TRIP: Schema_Event = {
4737
_id: new ObjectId().toString(),
4838
user: USER,
@@ -51,8 +41,8 @@ export const EUROPE_TRIP: Schema_Event = {
5141
description: "Italy, Germany",
5242
isSomeday: true,
5343
priority: Priorities.SELF,
54-
startDate: today,
55-
endDate: today,
44+
startDate: "2025-12-10T00:00:00-00:00",
45+
endDate: "2025-12-10T00:00:00-00:00",
5646
order: 2,
5747
};
5848
export const LEARN_CHINESE: Schema_Event = {

packages/web/src/__tests__/__mocks__/mock.render.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,16 +84,28 @@ const customRender = (
8484
reducer: reducers,
8585
preloadedState: state,
8686
}),
87+
wrapper: CustomWrapper,
8788
...renderOptions
88-
}: Omit<CustomRenderOptions, "wrapper"> = {},
89+
}: CustomRenderOptions = {},
8990
) => {
9091
sagaMiddleware.run(sagas);
9192

9293
const options: RenderOptions = { ...renderOptions };
94+
const BaseProviders = TestProviders({ store, router });
95+
96+
const Wrapper = ({ children }: PropsWithChildren) => {
97+
if (!CustomWrapper) return <BaseProviders>{children}</BaseProviders>;
98+
99+
return (
100+
<BaseProviders>
101+
<CustomWrapper>{children}</CustomWrapper>
102+
</BaseProviders>
103+
);
104+
};
93105

94106
// wraps test component with providers
95107
return render(ui, {
96-
wrapper: TestProviders({ store, router }),
108+
wrapper: Wrapper,
97109
...options,
98110
});
99111
};

packages/web/src/__tests__/__mocks__/state/state.weekEvents.ts

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,19 @@ import {
77
MULTI_WEEK,
88
TY_TIM,
99
} from "@core/__mocks__/v1/events/events.misc";
10-
import { InitialReduxState } from "@web/views/Calendar/calendar.render.test.utils";
10+
import { InitialReduxState } from "@web/__tests__/utils/state/store.test.util";
1111

1212
export const preloadedState: InitialReduxState = {
1313
events: {
1414
getSomedayEvents: {
1515
value: {
1616
data: [EUROPE_TRIP._id as string],
17-
count: 0,
18-
pageSize: 0,
17+
count: 1,
18+
pageSize: 10,
1919
},
2020
isProcessing: false,
21-
isSuccess: false,
22-
error: undefined,
21+
isSuccess: true,
22+
error: null,
2323
reason: null,
2424
},
2525
getWeekEvents: {
@@ -32,19 +32,19 @@ export const preloadedState: InitialReduxState = {
3232
MULTI_WEEK._id as string,
3333
TY_TIM._id as string,
3434
],
35-
count: 0,
36-
pageSize: 0,
35+
count: 6,
36+
pageSize: 10,
3737
},
3838
isProcessing: false,
39-
isSuccess: false,
40-
error: undefined,
39+
isSuccess: true,
40+
error: null,
4141
reason: null,
4242
},
4343
getDayEvents: {
4444
value: null,
4545
isProcessing: false,
46-
isSuccess: false,
47-
error: undefined,
46+
isSuccess: true,
47+
error: null,
4848
reason: null,
4949
},
5050
entities: {
@@ -58,20 +58,35 @@ export const preloadedState: InitialReduxState = {
5858
[TY_TIM._id as string]: TY_TIM,
5959
},
6060
},
61+
draft: {
62+
event: null,
63+
status: {
64+
activity: null,
65+
isDrafting: false,
66+
eventType: null,
67+
dateToResize: null,
68+
},
69+
},
70+
pendingEvents: {
71+
eventIds: [],
72+
},
6173
},
6274
settings: {
6375
isCmdPaletteOpen: false,
6476
},
6577
sync: {
78+
importGCal: {
79+
importing: false,
80+
},
6681
importLatest: {
6782
isFetchNeeded: false,
6883
reason: null,
6984
},
7085
},
7186
view: {
7287
dates: {
73-
start: "",
74-
end: "",
88+
start: "2025-12-07T00:00:00Z",
89+
end: "2025-12-13T23:59:59Z",
7590
},
7691
sidebar: {
7792
tab: "tasks",

packages/web/src/__tests__/utils/providers/MemoryRouter.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@ import { act } from "react";
22
import { MemoryRouter } from "react-router-dom";
33
import { render } from "@web/__tests__/__mocks__/mock.render";
44

5-
export const renderWithMemoryRouter = async (ui: React.ReactElement) => {
5+
export const renderWithMemoryRouter = async (
6+
ui: React.ReactElement,
7+
initialEntries?: string[],
8+
) => {
69
return await act(() =>
710
render(
811
<MemoryRouter
12+
initialEntries={initialEntries}
913
future={{
1014
v7_startTransition: true,
1115
v7_relativeSplatPath: true,

packages/web/src/__tests__/utils/state/store.test.util.ts

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ type TestState = {
2121
error: unknown;
2222
reason: string | null;
2323
};
24+
2425
getWeekEvents?: {
2526
value: {
2627
data: string[];
@@ -45,6 +46,7 @@ type TestState = {
4546
entities?: {
4647
value: Record<string, unknown>;
4748
};
49+
[key: string]: unknown;
4850
};
4951
};
5052
// Type for the initial state that can be passed to PreloadedState
@@ -82,34 +84,6 @@ export const createInitialState = (
8284
isSuccess: false,
8385
reason: null,
8486
},
85-
getCurrentMonthEvents: {
86-
value: null,
87-
isProcessing: false,
88-
error: null,
89-
isSuccess: false,
90-
reason: null,
91-
},
92-
createEvent: {
93-
isProcessing: false,
94-
error: null,
95-
value: null,
96-
isSuccess: false,
97-
reason: null,
98-
},
99-
editEvent: {
100-
isProcessing: false,
101-
error: null,
102-
value: null,
103-
isSuccess: false,
104-
reason: null,
105-
},
106-
deleteEvent: {
107-
isProcessing: false,
108-
error: null,
109-
value: null,
110-
isSuccess: false,
111-
reason: null,
112-
},
11387
draft: {
11488
event: null,
11589
status: {
@@ -140,6 +114,9 @@ export const createInitialState = (
140114
isCmdPaletteOpen: false,
141115
},
142116
sync: {
117+
importGCal: {
118+
importing: false,
119+
},
143120
importLatest: {
144121
isFetchNeeded: false,
145122
reason: null,

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

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -142,51 +142,4 @@ describe("Event Form", () => {
142142
);
143143
});
144144
});
145-
146-
describe("Reminder", () => {
147-
it("it should be focused when the 'r' keyboard shortcut is used", async () => {
148-
const { container } = await act(() =>
149-
render(<></>, { router, state: preloadedState }),
150-
);
151-
152-
const reminderPlaceholder = screen.getByText(
153-
"Click to add your reminder",
154-
);
155-
156-
expect(reminderPlaceholder).toBeInTheDocument();
157-
158-
await act(async () => userEvent.keyboard("r"));
159-
160-
const reminderInput = container.querySelector('[id="reminderInput"]');
161-
162-
expect(reminderInput).toHaveFocus();
163-
});
164-
165-
it("it should be focused when the 'edit reminder' btn is clicked in the command palette", async () => {
166-
const user = userEvent.setup();
167-
168-
await act(() => render(<></>, { router, state: preloadedState }));
169-
170-
expect(
171-
screen.getByText("Click to add your reminder"),
172-
).toBeInTheDocument();
173-
174-
await act(async () => {
175-
await user.keyboard(`{${getModifierKey()}>}k{/${getModifierKey()}}`);
176-
});
177-
178-
const cmdPaletteEditBtn = await screen.findByRole("button", {
179-
name: /edit reminder/i,
180-
});
181-
await act(async () => {
182-
await user.click(cmdPaletteEditBtn);
183-
});
184-
185-
await waitFor(() => {
186-
const input = document.querySelector("#reminderInput");
187-
expect(input).toBeInTheDocument();
188-
expect(input).toHaveFocus();
189-
});
190-
}, 10000);
191-
});
192145
});

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,7 @@ export const CalendarView = () => {
6565
weekProps={weekProps}
6666
isSidebarOpen={isSidebarOpen}
6767
>
68-
<SidebarDraftProvider
69-
dateCalcs={dateCalcs}
70-
measurements={measurements}
71-
weekProps={weekProps}
72-
>
68+
<SidebarDraftProvider dateCalcs={dateCalcs} weekProps={weekProps}>
7369
<Shortcuts shortcutsProps={shortcutProps}>
7470
<ContextMenuWrapper id="sidebar-context-menu">
7571
<Draft measurements={measurements} weekProps={weekProps} />

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import React, { ReactNode } from "react";
1+
import { ReactNode } from "react";
22
import { DateCalcs } from "@web/views/Calendar/hooks/grid/useDateCalcs";
3-
import { Measurements_Grid } from "@web/views/Calendar/hooks/grid/useGridLayout";
43
import { WeekProps } from "@web/views/Calendar/hooks/useWeek";
54
import { useSidebarActions } from "../hooks/useSidebarActions";
65
import { useSidebarEffects } from "../hooks/useSidebarEffects";
@@ -10,16 +9,14 @@ import { SidebarDraftContext } from "./SidebarDraftContext";
109
interface Props {
1110
children: ReactNode;
1211
dateCalcs: DateCalcs;
13-
measurements: Measurements_Grid;
1412
weekProps: WeekProps;
1513
}
1614
export const SidebarDraftProvider = ({
1715
children,
1816
dateCalcs,
19-
measurements,
2017
weekProps,
2118
}: Props) => {
22-
const { setters, state } = useSidebarState(measurements);
19+
const { setters, state } = useSidebarState();
2320
const actions = useSidebarActions(dateCalcs, state, setters, weekProps);
2421
useSidebarEffects(state, actions);
2522

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

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { FC, useRef } from "react";
1+
import { FC } from "react";
22
import dayjs, { Dayjs } from "@core/util/date/dayjs";
33
import { theme } from "@web/common/styles/theme";
44
import { getCalendarHeadingLabel } from "@web/common/utils/datetime/web.date.util";
@@ -12,11 +12,9 @@ import { viewSlice } from "@web/ducks/events/slices/view.slice";
1212
import { useAppDispatch, useAppSelector } from "@web/store/store.hooks";
1313
import { RootProps } from "../../calendarView.types";
1414
import { Util_Scroll } from "../../hooks/grid/useScroll";
15-
import { useReminderHotkey } from "../../hooks/shortcuts/useFocusHotkey";
1615
import { WeekProps } from "../../hooks/useWeek";
1716
import { TodayButton } from "../TodayButton/TodayButton";
1817
import { DayLabels } from "./DayLabels";
19-
import { Reminder } from "./Reminder/Reminder";
2018
import {
2119
ArrowNavigationButton,
2220
StyledHeaderLabel,
@@ -51,10 +49,6 @@ export const Header: FC<Props> = ({ scrollUtil, today, weekProps }) => {
5149
scrollToNow();
5250
};
5351

54-
const reminderRef = useRef<HTMLDivElement>(null);
55-
56-
useReminderHotkey(() => reminderRef.current?.focus(), [reminderRef]);
57-
5852
return (
5953
<>
6054
<StyledHeaderRow alignItems={AlignItems.BASELINE}>
@@ -76,7 +70,6 @@ export const Header: FC<Props> = ({ scrollUtil, today, weekProps }) => {
7670
<Text size="xl">{headerLabel}</Text>
7771
</StyledHeaderLabel>
7872
</StyledLeftGroup>
79-
<Reminder ref={reminderRef} />
8073
<StyledRightGroup>
8174
<SelectView />
8275
<div>

0 commit comments

Comments
 (0)