Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

feat(calendar): add period and view navigation hotkeys (#5528)

dev-rb3e5bf92e0ad9
diff --git a/apps/web/src/features/calendar/CalendarPeriodSelector.tsx b/apps/web/src/features/calendar/CalendarPeriodSelector.tsx
index dd88dc5d49..42ee8d0173 100644
--- a/apps/web/src/features/calendar/CalendarPeriodSelector.tsx
+++ b/apps/web/src/features/calendar/CalendarPeriodSelector.tsx
@@ -1,10 +1,11 @@
import { MobileDrawer } from '@components/app/mobile/MobileDrawer';
import { useSidePanel } from '@components/app/side-panel/SidePanel';
+import { type HotkeyToken, TOKENS } from '@core/hotkey/tokens';
import CalendarIcon from '@phosphor/calendar-blank.svg';
import CaretDownIcon from '@phosphor/caret-down.svg';
import CaretRightIcon from '@phosphor/caret-right.svg';
import CheckIcon from '@phosphor/check.svg';
-import { Dropdown, Calendar as MiniCalendar } from '@ui';
+import { Dropdown, Hotkey, Calendar as MiniCalendar } from '@ui';
import { createMemo, For, Show } from 'solid-js';
import { createStore } from 'solid-js/store';
import { useCalendarPager } from './CalendarPagerContext';
@@ -12,10 +13,26 @@ import { useCalendarView } from './CalendarViewContext';
import type { CalendarPeriodView } from './events/types';
const CALENDAR_VIEWS = [
- { value: 'dayGridMonth', label: 'Month' },
- { value: 'timeGridWeek', label: 'Week' },
- { value: 'timeGridDay', label: 'Day' },
-] satisfies Array<{ value: CalendarPeriodView; label: string }>;
+ {
+ value: 'dayGridMonth',
+ label: 'Month',
+ hotkeyToken: TOKENS.calendar.view.month,
+ },
+ {
+ value: 'timeGridWeek',
+ label: 'Week',
+ hotkeyToken: TOKENS.calendar.view.week,
+ },
+ {
+ value: 'timeGridDay',
+ label: 'Day',
+ hotkeyToken: TOKENS.calendar.view.day,
+ },
+] satisfies Array<{
+ value: CalendarPeriodView;
+ label: string;
+ hotkeyToken: HotkeyToken;
+}>;
const DRAWER_ROW_CLASS =
"relative flex w-full items-center gap-3 bg-surface px-4 py-3 text-left text-sm text-ink not-last:after:absolute not-last:after:inset-x-2 not-last:after:bottom-0 not-last:after:h-px not-last:after:bg-edge-muted not-last:after:content-['']";
@@ -155,6 +172,8 @@ export function CalendarPeriodSelector() {
<Dropdown.ItemIndicator>
<CheckIcon class="size-3.5 text-accent" />
</Dropdown.ItemIndicator>
+
+ <Hotkey token={view.hotkeyToken} theme="subtle" />
</Dropdown.RadioItem>
)}
</For>
diff --git a/apps/web/src/features/calendar/calendar-view.tsx b/apps/web/src/features/calendar/calendar-view.tsx
index 08fa44acc4..32445e795b 100644
--- a/apps/web/src/features/calendar/calendar-view.tsx
+++ b/apps/web/src/features/calendar/calendar-view.tsx
@@ -5,6 +5,7 @@ import {
SplitHeaderRight,
} from '@components/app/split-layout/components/SplitHeader';
import { useSplitPanelOrThrow } from '@components/app/split-layout/layoutUtils';
+import { TOKENS } from '@core/hotkey/tokens';
import { isMobile } from '@core/mobile/isMobile';
import CalendarBlankIcon from '@phosphor/calendar-blank.svg';
import CaretLeftIcon from '@phosphor/caret-left.svg';
@@ -41,7 +42,7 @@ import {
} from './CalendarViewContext';
import { SelectedEventDetails } from './events/EventDetailsPopover';
import { EventEditorDialog } from './events/EventEditorDialog';
-import './calendar.css';
+import { useCalendarHotkeys } from './use-calendar-hotkeys';
const CALENDAR_SWIPE_EDGE_INSET = 40;
@@ -177,6 +178,14 @@ function CalendarWorkspace() {
const today = createLocalToday();
const [createEventOpen, setCreateEventOpen] = createSignal(false);
+ useCalendarHotkeys({
+ scopeId: panel.splitHotkeyScope,
+ changeView: calendarPager.changeView,
+ previousPeriod: pager.previous,
+ nextPeriod: pager.next,
+ navigateToToday: calendarPager.navigateToToday,
+ });
+
const currentDate = createMemo(
() => calendarPager.activeDateInfo()?.view.calendar.getDate() ?? initialDate
);
@@ -225,6 +234,7 @@ function CalendarWorkspace() {
class="rounded-lg px-3"
depth={2}
label="Go to today"
+ hotkey={TOKENS.calendar.period.today}
onClick={calendarPager.navigateToToday}
>
Today
@@ -237,6 +247,7 @@ function CalendarWorkspace() {
size="icon-sm"
class="rounded-full"
label="Go to today"
+ hotkey={TOKENS.calendar.period.today}
onClick={calendarPager.navigateToToday}
>
<CalendarBlankIcon aria-hidden="true" />
@@ -266,6 +277,7 @@ function CalendarWorkspace() {
size="icon-sm"
class="rounded-lg"
label="Previous period"
+ hotkey={TOKENS.calendar.period.previous}
onClick={() => void pager.previous()}
>
<CaretLeftIcon class="size-4" />
@@ -275,6 +287,7 @@ function CalendarWorkspace() {
size="icon-sm"
class="rounded-lg"
label="Next period"
+ hotkey={TOKENS.calendar.period.next}
onClick={() => void pager.next()}
>
<CaretRightIcon class="size-4" />
diff --git a/apps/web/src/features/calendar/use-calendar-hotkeys.ts b/apps/web/src/features/calendar/use-calendar-hotkeys.ts
new file mode 100644
index 0000000000..d9aebb8ac3
--- /dev/null
+++ b/apps/web/src/features/calendar/use-calendar-hotkeys.ts
@@ -0,0 +1,99 @@
+import { createHotkeyGroup, registerHotkey } from '@core/hotkey/hotkeys';
+import { TOKENS } from '@core/hotkey/tokens';
+import { onCleanup } from 'solid-js';
+import type { CalendarPeriodView } from './events/types';
+
+interface CalendarHotkeyHandlers {
+ scopeId: string;
+ changeView: (view: CalendarPeriodView) => void;
+ previousPeriod: () => unknown;
+ nextPeriod: () => unknown;
+ navigateToToday: () => void;
+}
+
+const VIEW_HOTKEYS = [
+ {
+ hotkey: 'd',
+ token: TOKENS.calendar.view.day,
+ description: 'Day view',
+ view: 'timeGridDay',
+ },
+ {
+ hotkey: 'w',
+ token: TOKENS.calendar.view.week,
+ description: 'Week view',
+ view: 'timeGridWeek',
+ },
+ {
+ hotkey: 'm',
+ token: TOKENS.calendar.view.month,
+ description: 'Month view',
+ view: 'dayGridMonth',
+ },
+] as const satisfies ReadonlyArray<{
+ hotkey: 'd' | 'w' | 'm';
+ token: (typeof TOKENS.calendar.view)[keyof typeof TOKENS.calendar.view];
+ description: string;
+ view: CalendarPeriodView;
+}>;
+
+/** Registers keyboard navigation for the current calendar component. */
+export function useCalendarHotkeys(handlers: CalendarHotkeyHandlers) {
+ const group = createHotkeyGroup();
+
+ for (const command of VIEW_HOTKEYS) {
+ group.add(
+ registerHotkey({
+ scopeId: handlers.scopeId,
+ hotkey: command.hotkey,
+ hotkeyToken: command.token,
+ description: command.description,
+ keyDownHandler: () => {
+ handlers.changeView(command.view);
+ return true;
+ },
+ })
+ );
+ }
+
+ group.add(
+ registerHotkey({
+ scopeId: handlers.scopeId,
+ hotkey: 'p',
+ hotkeyToken: TOKENS.calendar.period.previous,
+ description: 'Previous period',
+ keyDownHandler: () => {
+ void handlers.previousPeriod();
+ return true;
+ },
+ })
+ );
+
+ group.add(
+ registerHotkey({
+ scopeId: handlers.scopeId,
+ hotkey: 'n',
+ hotkeyToken: TOKENS.calendar.period.next,
+ description: 'Next period',
+ keyDownHandler: () => {
+ void handlers.nextPeriod();
+ return true;
+ },
+ })
+ );
+
+ group.add(
+ registerHotkey({
+ scopeId: handlers.scopeId,
+ hotkey: 't',
+ hotkeyToken: TOKENS.calendar.period.today,
+ description: 'Go to today',
+ keyDownHandler: () => {
+ handlers.navigateToToday();
+ return true;
+ },
+ })
+ );
+
+ onCleanup(() => group.dispose());
+}
diff --git a/apps/web/src/lib/core/hotkey/tokens.ts b/apps/web/src/lib/core/hotkey/tokens.ts
index 9192bad5ee..a5bc97387c 100644
--- a/apps/web/src/lib/core/hotkey/tokens.ts
+++ b/apps/web/src/lib/core/hotkey/tokens.ts
@@ -77,6 +77,20 @@ export const TOKENS = {
escape: 'code.escape',
},
+ // calendar
+ calendar: {
+ view: {
+ day: 'calendar.view.day',
+ week: 'calendar.view.week',
+ month: 'calendar.view.month',
+ },
+ period: {
+ previous: 'calendar.period.previous',
+ next: 'calendar.period.next',
+ today: 'calendar.period.today',
+ },
+ },
+
// global
global: {
createCommand: 'global.createCommand',