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.

fix(calendar): improve mobile header and today navigation (#9292)

gbirman7d9c4968f4db
diff --git a/apps/web/src/components/ui/components/Button.tsx b/apps/web/src/components/ui/components/Button.tsx
index 951dc14bfa..eae83aaefc 100644
--- a/apps/web/src/components/ui/components/Button.tsx
+++ b/apps/web/src/components/ui/components/Button.tsx
@@ -75,7 +75,7 @@ const buttonStyles = createVariants(
),
ghost: cn(
buttonFrames.ghost,
- 'not-data-disabled:hover:bg-button-tertiary-hover not-data-disabled:hover:text-ink not-data-disabled:active:bg-button-tertiary-pressed not-data-disabled:active:text-ink aria-pressed:bg-button-tertiary-pressed aria-pressed:text-ink aria-pressed:not-data-disabled:hover:bg-button-tertiary-pressed popup-open:bg-button-tertiary-pressed popup-open:text-ink popup-open:not-data-disabled:hover:bg-button-tertiary-pressed',
+ 'not-touch:not-data-disabled:hover:bg-button-tertiary-hover not-touch:not-data-disabled:hover:text-ink not-data-disabled:active:bg-button-tertiary-pressed not-data-disabled:active:text-ink aria-pressed:bg-button-tertiary-pressed aria-pressed:text-ink not-touch:aria-pressed:not-data-disabled:hover:bg-button-tertiary-pressed popup-open:bg-button-tertiary-pressed popup-open:text-ink not-touch:popup-open:not-data-disabled:hover:bg-button-tertiary-pressed',
buttonPressedStyles
),
danger: cn(
diff --git a/apps/web/src/features/calendar-view/components/Header.tsx b/apps/web/src/features/calendar-view/components/Header.tsx
index 8b7ffce4b4..9b06e76ac9 100644
--- a/apps/web/src/features/calendar-view/components/Header.tsx
+++ b/apps/web/src/features/calendar-view/components/Header.tsx
@@ -232,7 +232,7 @@ export function Header(props: {
const Control = compact ? ButtonGroup.Button : Button;
const size = () => {
if (compact) return mobile ? 'icon-sm' : 'sm';
- return mobile ? 'icon-lg' : 'lg';
+ return mobile ? 'icon-md' : 'lg';
};
return (
<Control
diff --git a/apps/web/src/features/calendar/components/CalendarPagerContext.test.tsx b/apps/web/src/features/calendar/components/CalendarPagerContext.test.tsx
new file mode 100644
index 0000000000..48c069b0b1
--- /dev/null
+++ b/apps/web/src/features/calendar/components/CalendarPagerContext.test.tsx
@@ -0,0 +1,146 @@
+import { Calendar, type DatesSetArg } from '@fullcalendar/core';
+import dayGridPlugin from '@fullcalendar/daygrid';
+import timeGridPlugin from '@fullcalendar/timegrid';
+import { cleanup, fireEvent, render, screen } from '@solidjs/testing-library';
+import { createSignal, onCleanup, onMount } from 'solid-js';
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
+import type { CalendarPeriodView } from '../types';
+import {
+ CalendarPagerContextProvider,
+ useCalendarPager,
+} from './CalendarPagerContext';
+
+function mountCalendar(view: CalendarPeriodView = 'timeGridDay') {
+ const element = document.createElement('div');
+ let calendar: Calendar;
+ const scrollToTime = vi.fn();
+
+ function Controls() {
+ const pager = useCalendarPager();
+ const [dateInfo, setDateInfo] = createSignal<DatesSetArg>();
+ onMount(() => {
+ calendar = new Calendar(element, {
+ plugins: [timeGridPlugin, dayGridPlugin],
+ initialView: view,
+ initialDate: new Date(2026, 10, 1),
+ datesSet: setDateInfo,
+ });
+ calendar.render();
+ vi.spyOn(calendar, 'scrollToTime').mockImplementation(scrollToTime);
+ const unregister = pager.registerPage({
+ id: 'current',
+ api: () => calendar,
+ dateInfo,
+ element: () => element,
+ data: {
+ range: () => undefined,
+ events: () => [],
+ visibleEvents: () => [],
+ eventsById: () => new Map(),
+ isLoading: () => false,
+ isSyncing: () => false,
+ get occurrencesQuery(): never {
+ throw new Error('Date navigation must not read occurrences');
+ },
+ },
+ });
+ onCleanup(() => {
+ unregister();
+ calendar.destroy();
+ });
+ });
+ return (
+ <>
+ <button onClick={pager.navigateToToday}>Today</button>
+ <button onClick={() => pager.navigateToDate(new Date(2026, 10, 5))}>
+ Another date
+ </button>
+ <button onClick={pager.nextPeriod}>Next period</button>
+ {element}
+ </>
+ );
+ }
+
+ render(() => (
+ <CalendarPagerContextProvider
+ initialView={view}
+ showWeekends={() => true}
+ weekStartsOn={() => 0}
+ onNavigate={() => {}}
+ onViewChange={() => {}}
+ >
+ <Controls />
+ </CalendarPagerContextProvider>
+ ));
+ return { calendar: () => calendar, scrollToTime };
+}
+
+beforeEach(() => {
+ vi.stubGlobal(
+ 'ResizeObserver',
+ class {
+ observe() {}
+ unobserve() {}
+ disconnect() {}
+ }
+ );
+ vi.useFakeTimers();
+ vi.setSystemTime(new Date(2026, 10, 1, 13, 45));
+});
+afterEach(() => {
+ cleanup();
+ vi.useRealTimers();
+ vi.restoreAllMocks();
+ vi.unstubAllGlobals();
+});
+
+describe('calendar Today navigation', () => {
+ it.each(['timeGridDay', 'timeGridWeek'] as const)(
+ 'scrolls to the current time even when already on today in %s',
+ async (view) => {
+ const { calendar, scrollToTime } = mountCalendar(view);
+ fireEvent.click(screen.getByRole('button', { name: 'Today' }));
+ expect(scrollToTime).not.toHaveBeenCalled();
+ await vi.advanceTimersByTimeAsync(100);
+ expect(calendar().getDate().getDate()).toBe(1);
+ expect(scrollToTime).toHaveBeenCalledWith({ minutes: 765 });
+ }
+ );
+
+ it('returns from another date before scrolling to the current time', async () => {
+ const { calendar, scrollToTime } = mountCalendar();
+ fireEvent.click(screen.getByRole('button', { name: 'Another date' }));
+ await vi.advanceTimersByTimeAsync(100);
+ expect(calendar().getDate().getDate()).toBe(5);
+ fireEvent.click(screen.getByRole('button', { name: 'Today' }));
+ await vi.advanceTimersByTimeAsync(100);
+ expect(calendar().getDate().getDate()).toBe(1);
+ expect(scrollToTime).toHaveBeenCalledWith({ minutes: 765 });
+ });
+
+ it('clamps the context above the current time to midnight', async () => {
+ vi.setSystemTime(new Date(2026, 10, 1, 0, 15));
+ const { scrollToTime } = mountCalendar();
+ fireEvent.click(screen.getByRole('button', { name: 'Today' }));
+ await vi.advanceTimersByTimeAsync(100);
+ expect(scrollToTime).toHaveBeenCalledWith({ minutes: 0 });
+ });
+
+ it('cancels a pending Today scroll when another date is selected', async () => {
+ const { calendar, scrollToTime } = mountCalendar();
+ fireEvent.click(screen.getByRole('button', { name: 'Today' }));
+ fireEvent.click(screen.getByRole('button', { name: 'Another date' }));
+ await vi.advanceTimersByTimeAsync(100);
+ expect(calendar().getDate().getDate()).toBe(5);
+ expect(scrollToTime).not.toHaveBeenCalled();
+ });
+
+ it('cancels a pending Today scroll when paging forward', async () => {
+ const { calendar, scrollToTime } = mountCalendar();
+ fireEvent.click(screen.getByRole('button', { name: 'Today' }));
+ fireEvent.click(screen.getByRole('button', { name: 'Next period' }));
+ await vi.advanceTimersByTimeAsync(100);
+ expect(calendar().getDate().getDate()).toBe(2);
+ expect(scrollToTime).not.toHaveBeenCalled();
+ });
+});
diff --git a/apps/web/src/features/calendar/components/CalendarPagerContext.tsx b/apps/web/src/features/calendar/components/CalendarPagerContext.tsx
index dbce4b579c..af37243071 100644
--- a/apps/web/src/features/calendar/components/CalendarPagerContext.tsx
+++ b/apps/web/src/features/calendar/components/CalendarPagerContext.tsx
@@ -267,6 +267,22 @@ function createCalendarPagerContext(props: CalendarPagerContextProps) {
scheduleActiveUpdate();
};
+ const navigateToToday = () => {
+ const now = new Date();
+ gotoDate(now);
+ // Scroll after the active grid renders. A newer navigation clears this job
+ // together with the date update, so it cannot scroll an unrelated period.
+ renderQueue.enqueue('scroll-to-now', () => {
+ activePage()
+ ?.api()
+ ?.scrollToTime({
+ // Keep the current-time marker below the scroller's top fade.
+ minutes: Math.max(0, now.getHours() * 60 + now.getMinutes() - 60),
+ });
+ copyActiveScrollPosition();
+ });
+ };
+
const finishDateNavigation = async (
transition: Promise<boolean>,
date: Date,
@@ -393,7 +409,7 @@ function createCalendarPagerContext(props: CalendarPagerContextProps) {
updateSize,
gotoDate,
navigateToDate,
- navigateToToday: () => navigateToDate(new Date()),
+ navigateToToday,
previousPeriod: () => navigatePeriod('previous'),
nextPeriod: () => navigatePeriod('next'),
changeView,
diff --git a/apps/web/src/features/calendar/components/MonthDrawer.tsx b/apps/web/src/features/calendar/components/MonthDrawer.tsx
index 4ce393f157..ad2fd1cd69 100644
--- a/apps/web/src/features/calendar/components/MonthDrawer.tsx
+++ b/apps/web/src/features/calendar/components/MonthDrawer.tsx
@@ -1,4 +1,5 @@
import { MobileDrawer } from '@components/app/mobile/MobileDrawer';
+import { isMobile } from '@core/mobile/isMobile';
import { isTouchDevice } from '@core/mobile/isTouchDevice';
import CaretDownIcon from '@icon/system/regular/caret-down.svg';
import { Button, CalendarMonthMenu, Dropdown, formatCalendarMonth } from '@ui';
@@ -9,6 +10,9 @@ type MonthDrawerProps = {
month: Date;
};
+const FORMAT_MONTH = new Intl.DateTimeFormat(undefined, { month: 'long' })
+ .format;
+
/** Month selector that uses a dropdown on desktop and a drawer on touch. */
export function MonthDrawer(props: MonthDrawerProps) {
const calendarPager = useCalendarPager();
@@ -26,7 +30,11 @@ export function MonthDrawer(props: MonthDrawerProps) {
const triggerContent = () => (
<>
- <span class="min-w-0 truncate">{formatCalendarMonth(props.month)}</span>
+ <span class="min-w-0 truncate">
+ {isMobile()
+ ? FORMAT_MONTH(props.month)
+ : formatCalendarMonth(props.month)}
+ </span>
<CaretDownIcon class="size-3 shrink-0 text-ink-muted" />
</>
);