From 5388ddff2315be1fb28175128ccf05c246356b77 Mon Sep 17 00:00:00 2001 From: BackDEV Date: Mon, 30 Nov 2026 17:04:09 +0700 Subject: [PATCH 1/2] feat: add month and year picker to calendar --- .../calendar/components/CalendarPage.tsx | 50 ++++++++- .../calendar/components/MiniMonth.tsx | 106 +++++++++++++++++- web/features/calendar/components/calendar.css | 72 ++++++++++++ web/tests/calendar.spec.tsx | 48 ++++++++ 4 files changed, 267 insertions(+), 9 deletions(-) diff --git a/web/features/calendar/components/CalendarPage.tsx b/web/features/calendar/components/CalendarPage.tsx index b87ddd2a0..c0e896990 100644 --- a/web/features/calendar/components/CalendarPage.tsx +++ b/web/features/calendar/components/CalendarPage.tsx @@ -2,7 +2,7 @@ import { browserStorage } from '@/shared/storage' import { useEffect, useMemo, useRef, useState } from 'react' -import { CalendarDays, ChevronLeft, ChevronRight, Plus, Search, PanelLeft, X } from 'lucide-react' +import { CalendarDays, ChevronDown, ChevronLeft, ChevronRight, Plus, Search, PanelLeft, X } from 'lucide-react' import { useTranslation } from 'react-i18next' import { PageHeader } from '@/components/layout/FeaturePage' import HeaderActionButton from '@/features/chat/components/HeaderActionButton' @@ -50,6 +50,7 @@ import { } from '../model/items' import { AnchoredPopover, anchorOf, type Anchor } from './AnchoredPopover' import { CalendarRail } from './CalendarRail' +import { MonthYearPicker } from './MiniMonth' import { TimeGrid, type GridDraft } from './TimeGrid' import { MonthView } from './MonthView' import { AgendaView, SearchResults } from './AgendaView' @@ -71,6 +72,7 @@ type Panel = { anchor: Anchor } & ( | { kind: 'delete'; item: EventItem } | { kind: 'calendar-delete'; calendar: api.CalendarEntry } | { kind: 'move'; item: EventItem; start: Date; end: Date } + | { kind: 'jump' } ) const center: Anchor = { top: 110, bottom: 140, left: 280, right: 280 } @@ -367,7 +369,24 @@ export default function CalendarPage() { navigate(-1)} /> navigate(1)} /> -

{heading}

+

+ +

) const tools = ( @@ -557,10 +576,31 @@ export default function CalendarPage() { - {panel.kind === 'edit' ? ( + {panel.kind === 'jump' ? ( +
+ { + const lastDay = new Date(year, month + 1, 0).getDate() + setCursor(new Date(year, month, Math.min(cursor.getDate(), lastDay))) + setQuery('') + setPanel(null) + }} + /> +
+ ) : panel.kind === 'edit' ? ( i) + +/** Compact year stepper/dropdown + 12-month grid used by both the toolbar and mini calendar. */ +export function MonthYearPicker({ + activeYear, + activeMonth, + today, + locale, + onSelect, +}: { + activeYear: number + activeMonth: number + today: Date + locale: string + onSelect: (year: number, month: number) => void +}) { + const { t } = useTranslation() + const [year, setYear] = useState(activeYear) + const [followedYear, setFollowedYear] = useState(activeYear) + if (activeYear !== followedYear) { + setFollowedYear(activeYear) + setYear(activeYear) + } + const years = Array.from({ length: 21 }, (_, i) => year - 10 + i) + const todayYear = today.getFullYear() + const todayMonth = today.getMonth() + return ( +
+
+ + + +
+
+ {MONTHS.map(m => ( + + ))} +
+
+ ) +} + /** A small month to jump around in; the shown range is shaded. */ export function MiniMonth({ cursor, @@ -34,6 +110,7 @@ export function MiniMonth({ const locale = i18n.language const [shown, setShown] = useState(() => startOfMonth(cursor)) const [followed, setFollowed] = useState(dateKey(startOfMonth(cursor))) + const [pickingMonth, setPickingMonth] = useState(false) // Follow the main view when it leaves the month on display. const cursorMonth = dateKey(startOfMonth(cursor)) if (cursorMonth !== followed) { @@ -45,7 +122,15 @@ export function MiniMonth({ return (
- {formatMonthTitle(shown, locale)} +
-
+ {pickingMonth ? ( + { + setShown(new Date(year, month, 1)) + setPickingMonth(false) + }} + /> + ) : ( +
{weeks[0].map(day => ( @@ -103,7 +200,8 @@ export function MiniMonth({ })}
))} -
+
+ )}
) } diff --git a/web/features/calendar/components/calendar.css b/web/features/calendar/components/calendar.css index 546e6be48..1d041ffe3 100644 --- a/web/features/calendar/components/calendar.css +++ b/web/features/calendar/components/calendar.css @@ -51,6 +51,20 @@ margin: 0 10px 0 6px; font-variant-numeric: tabular-nums; } +.dt-cal-heading-button { + display: inline-flex; + align-items: center; + gap: 5px; + padding: 3px 8px; + margin: -3px -8px; + border-radius: 7px; + font: inherit; + letter-spacing: inherit; +} +.dt-cal-heading-button:hover, +.dt-cal-heading-button[aria-expanded='true'] { + background: var(--secondary); +} .dt-cal-today { height: 30px; margin-left: 4px; @@ -251,6 +265,64 @@ button.dt-cal-rail-link { } .dt-cal-mini-title { flex: 1; + display: inline-flex; + align-items: center; + gap: 4px; + padding: 2px 6px; + margin-left: -6px; + border-radius: 6px; + font-weight: 600; + text-align: left; +} +.dt-cal-mini-title:hover, +.dt-cal-mini-title[aria-expanded='true'] { + background: var(--secondary); +} +.dt-cal-ym-popover { + padding: 12px; +} +.dt-cal-ym-head { + display: flex; + align-items: center; + justify-content: space-between; + gap: 6px; + margin-bottom: 10px; +} +.dt-cal-ym-select { + flex: 1; + height: 28px; + padding: 0 8px; + border-radius: 6px; + border: 1px solid var(--border); + background: var(--background); + color: var(--foreground); + font-size: 13px; + font-weight: 600; + font-variant-numeric: tabular-nums; + text-align: center; + cursor: pointer; +} +.dt-cal-ym-grid { + display: grid; + grid-template-columns: repeat(3, 1fr); + gap: 4px; +} +.dt-cal-ym-month { + height: 30px; + border-radius: 6px; + font-size: 12px; + color: var(--foreground); + transition: background-color 120ms, color 120ms; +} +.dt-cal-ym-month:hover { + background: var(--accent, var(--secondary)); +} +.dt-cal-ym-month[aria-current='date'] { + box-shadow: inset 0 0 0 1px var(--primary); +} +.dt-cal-ym-month[aria-pressed='true'] { + background: var(--primary); + color: var(--primary-foreground); font-weight: 600; } .dt-cal-icon-button { diff --git a/web/tests/calendar.spec.tsx b/web/tests/calendar.spec.tsx index daaf439b9..df08d855c 100644 --- a/web/tests/calendar.spec.tsx +++ b/web/tests/calendar.spec.tsx @@ -185,6 +185,54 @@ it('does not trigger calendar shortcuts while typing in the editor', async () => expect(screen.getByRole('tab', { name: 'Week' })).toHaveAttribute('aria-selected', 'true') }) +it('jumps to a chosen month and year from the toolbar heading and toggles closed', async () => { + mount() + await waitFor(() => expect(screen.getByRole('button', { name: 'New event' })).toBeEnabled()) + const heading = screen.getByRole('heading', { level: 2 }) + const toggle = within(heading).getByRole('button') + fireEvent.click(toggle) + expect(screen.getByRole('dialog', { name: 'Calendar' })).toBeInTheDocument() + // Let AnchoredPopover attach its document pointerdown listener before toggling closed. + await act(async () => { + await new Promise(resolve => setTimeout(resolve, 0)) + }) + fireEvent.pointerDown(toggle) + fireEvent.click(toggle) + expect(screen.queryByRole('dialog', { name: 'Calendar' })).not.toBeInTheDocument() + + fireEvent.click(toggle) + const dialog = within(screen.getByRole('dialog', { name: 'Calendar' })) + const targetYear = new Date().getFullYear() + 2 + fireEvent.change(dialog.getByRole('combobox', { name: 'Years' }), { + target: { value: String(targetYear) }, + }) + fireEvent.click(dialog.getByRole('button', { name: 'Feb' })) + expect(screen.queryByRole('dialog', { name: 'Calendar' })).not.toBeInTheDocument() + expect(heading).toHaveTextContent(`February ${targetYear}`) + await waitFor(() => + expect( + vi.mocked(fetch).mock.calls.some(([url]) => String(url).includes(`${targetYear}-`)) + ).toBe(true) + ) +}) + +it('picks a month and year from the mini calendar and keeps year synced when stepping', async () => { + mount() + await waitFor(() => expect(screen.getByRole('button', { name: 'New event' })).toBeEnabled()) + const rail = within(screen.getByRole('complementary', { name: 'Calendar sidebar' })) + const currentYear = new Date().getFullYear() + const prevYear = currentYear - 1 + + fireEvent.click(rail.getByRole('button', { name: new RegExp(String(currentYear)) })) + fireEvent.click(rail.getByRole('button', { name: 'Previous year' })) + fireEvent.click(rail.getByRole('button', { name: 'Jan' })) + expect(rail.getByRole('grid', { name: `January ${prevYear}` })).toBeInTheDocument() + + fireEvent.click(rail.getByRole('button', { name: `January ${prevYear}` })) + fireEvent.click(rail.getByRole('button', { name: 'Previous month' })) + expect(rail.getByRole('combobox', { name: 'Years' })).toHaveValue(String(prevYear - 1)) +}) + describe('calendar models', () => { it('clamps month navigation and covers the leap day once', () => { expect(dateKey(addMonths(new Date(2024, 0, 31), 1))).toBe('2024-02-29') From f36fffec68157068167c671f02ed399ca07eafb0 Mon Sep 17 00:00:00 2001 From: BackDEV Date: Mon, 30 Nov 2026 17:11:00 +0700 Subject: [PATCH 2/2] feat: replace year select with 12-year drill-down grid --- .../calendar/components/MiniMonth.tsx | 90 ++++++++++++------- web/features/calendar/components/calendar.css | 16 ++-- web/tests/calendar.spec.tsx | 11 +-- 3 files changed, 75 insertions(+), 42 deletions(-) diff --git a/web/features/calendar/components/MiniMonth.tsx b/web/features/calendar/components/MiniMonth.tsx index 09a956923..eb1c20af1 100644 --- a/web/features/calendar/components/MiniMonth.tsx +++ b/web/features/calendar/components/MiniMonth.tsx @@ -17,7 +17,7 @@ import { const MONTHS = Array.from({ length: 12 }, (_, i) => i) -/** Compact year stepper/dropdown + 12-month grid used by both the toolbar and mini calendar. */ +/** Compact month & 12-year drill-down picker used by both the toolbar and mini calendar. */ export function MonthYearPicker({ activeYear, activeMonth, @@ -34,59 +34,85 @@ export function MonthYearPicker({ const { t } = useTranslation() const [year, setYear] = useState(activeYear) const [followedYear, setFollowedYear] = useState(activeYear) + const [pickingYear, setPickingYear] = useState(false) + const [yearStart, setYearStart] = useState(activeYear - 4) if (activeYear !== followedYear) { setFollowedYear(activeYear) setYear(activeYear) + setYearStart(activeYear - 4) } - const years = Array.from({ length: 21 }, (_, i) => year - 10 + i) const todayYear = today.getFullYear() const todayMonth = today.getMonth() + const yearRange = `${yearStart} – ${yearStart + 11}` return (
- +
-
- {MONTHS.map(m => ( - - ))} -
+ {pickingYear ? ( +
+ {MONTHS.map(offset => { + const y = yearStart + offset + return ( + + ) + })} +
+ ) : ( +
+ {MONTHS.map(m => ( + + ))} +
+ )}
) } diff --git a/web/features/calendar/components/calendar.css b/web/features/calendar/components/calendar.css index 1d041ffe3..53b689b46 100644 --- a/web/features/calendar/components/calendar.css +++ b/web/features/calendar/components/calendar.css @@ -288,19 +288,24 @@ button.dt-cal-rail-link { gap: 6px; margin-bottom: 10px; } -.dt-cal-ym-select { +.dt-cal-ym-year { flex: 1; height: 28px; + display: inline-flex; + align-items: center; + justify-content: center; + gap: 4px; padding: 0 8px; border-radius: 6px; - border: 1px solid var(--border); - background: var(--background); color: var(--foreground); font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; - text-align: center; - cursor: pointer; + transition: background-color 120ms; +} +.dt-cal-ym-year:hover, +.dt-cal-ym-year[aria-expanded='true'] { + background: var(--secondary); } .dt-cal-ym-grid { display: grid; @@ -311,6 +316,7 @@ button.dt-cal-rail-link { height: 30px; border-radius: 6px; font-size: 12px; + font-variant-numeric: tabular-nums; color: var(--foreground); transition: background-color 120ms, color 120ms; } diff --git a/web/tests/calendar.spec.tsx b/web/tests/calendar.spec.tsx index df08d855c..4eb185c90 100644 --- a/web/tests/calendar.spec.tsx +++ b/web/tests/calendar.spec.tsx @@ -202,10 +202,11 @@ it('jumps to a chosen month and year from the toolbar heading and toggles closed fireEvent.click(toggle) const dialog = within(screen.getByRole('dialog', { name: 'Calendar' })) - const targetYear = new Date().getFullYear() + 2 - fireEvent.change(dialog.getByRole('combobox', { name: 'Years' }), { - target: { value: String(targetYear) }, - }) + const currentYear = new Date().getFullYear() + const targetYear = currentYear + 14 + fireEvent.click(dialog.getByRole('button', { name: String(currentYear) })) + fireEvent.click(dialog.getByRole('button', { name: 'Next' })) + fireEvent.click(dialog.getByRole('button', { name: String(targetYear) })) fireEvent.click(dialog.getByRole('button', { name: 'Feb' })) expect(screen.queryByRole('dialog', { name: 'Calendar' })).not.toBeInTheDocument() expect(heading).toHaveTextContent(`February ${targetYear}`) @@ -230,7 +231,7 @@ it('picks a month and year from the mini calendar and keeps year synced when ste fireEvent.click(rail.getByRole('button', { name: `January ${prevYear}` })) fireEvent.click(rail.getByRole('button', { name: 'Previous month' })) - expect(rail.getByRole('combobox', { name: 'Years' })).toHaveValue(String(prevYear - 1)) + expect(rail.getByRole('button', { name: String(prevYear - 1) })).toBeInTheDocument() }) describe('calendar models', () => {