diff --git a/app/globals.css b/app/globals.css index 4e41210eb..ecabb03ab 100644 --- a/app/globals.css +++ b/app/globals.css @@ -313,6 +313,18 @@ optgroup { background-color: var(--color-muted-foreground); } +/* The folded folder column (components/layout/sidebar.tsx) leaves its 48px + to the icons: a 4px scrollbar, in a gutter kept on both sides. */ +:root:not([data-native-scrollbars="on"]) [data-folder-rail]::-webkit-scrollbar { + width: 4px; +} + +@supports not selector(::-webkit-scrollbar) { + :root:not([data-native-scrollbars="on"]) [data-folder-rail] { + scrollbar-width: thin; + } +} + /* Enhanced Email Content Styling */ .email-content-wrapper { @@ -617,8 +629,9 @@ optgroup { --titlebar-right-inset: calc(100vw - env(titlebar-area-x, 0px) - env(titlebar-area-width, 100vw)); --titlebar-left-inset: env(titlebar-area-x, 0px); --titlebar-row-height: env(titlebar-area-height, 0px); - /* Where a drawer from the window's edge starts (the folder drawer): under - the top bar, and under the window's controls when they are over the page. */ + /* Where a drawer from the window's edge starts (Mail's folders, the + Calendar, Contacts and Files sidebars): under the top bar, and under the + window's controls when they are over the page. */ --drawer-top: max(var(--app-top-inset), var(--titlebar-row-height)); } @@ -627,6 +640,17 @@ html[data-window-controls] [data-window-row-right] { padding-right: calc(var(--titlebar-right-inset) + 0.5rem) !important; } +/* + * The composer's header runs over its plugin panels. The head above the panel at the + * window's right takes that room inside itself, so it stays as wide as the panel and + * its Hide button stays at the panel's edge, with its window buttons left of the controls. + */ +html[data-window-controls]:not([dir="rtl"]) [data-window-row-right] > [data-composer-panel-head="right"], +html[data-window-controls][dir="rtl"] [data-window-row-right] > [data-composer-panel-head="left"] { + margin-right: calc(-1 * (var(--titlebar-right-inset) + 0.5rem)); + padding-right: calc(var(--titlebar-right-inset) + 0.5rem); +} + /* Something floating at the top end of a page with no row: next to the controls, lined up. */ html[data-window-controls]:not([dir="rtl"]) [data-window-beside-controls] { right: calc(var(--titlebar-right-inset) + 0.5rem); diff --git a/components/calendar/__tests__/calendar-app.test.tsx b/components/calendar/__tests__/calendar-app.test.tsx index f02537e85..2b48c34bd 100644 --- a/components/calendar/__tests__/calendar-app.test.tsx +++ b/components/calendar/__tests__/calendar-app.test.tsx @@ -866,3 +866,56 @@ describe('CalendarApp company calendars on a phone', () => { } }); }); + +// Below the full desktop the sidebar is the same drawer as Mail's folders +// (usability test 2026-11-04): from the window's edge, the page dimmed, +// Escape closes it, and the focus goes in and back to the menu button. +describe('CalendarApp sidebar drawer', () => { + beforeEach(() => { + media.desktop = false; + }); + + const drawer = () => screen.getByTestId('calendar-sidebar-drawer'); + const menu = () => screen.getByRole('button', { name: 'nav_open_menu' }); + + it("opens from the window's edge, over the app rail and under the top bar", () => { + renderApp(); + const classes = drawer().className.split(/\s+/); + expect(classes).toEqual(expect.arrayContaining(['fixed', 'start-0', 'top-[var(--drawer-top)]', 'bottom-0'])); + expect(classes).not.toContain('absolute'); + }); + + it("is out of reach while closed, so Tab doesn't walk into the hidden calendars", () => { + renderApp(); + expect(drawer()).toHaveAttribute('inert'); + fireEvent.click(menu()); + expect(drawer()).not.toHaveAttribute('inert'); + }); + + it('takes the focus in, keeps Tab there and gives it back to the menu button on Escape', () => { + renderApp(); + menu().focus(); + fireEvent.click(menu()); + expect(drawer().contains(document.activeElement)).toBe(true); + const stops = Array.from(drawer().querySelectorAll('button:not(:disabled)')); + stops.at(-1)!.focus(); + fireEvent.keyDown(stops.at(-1)!, { key: 'Tab' }); + expect(document.activeElement).toBe(stops[0]); + + fireEvent.keyDown(document.activeElement!, { key: 'Escape' }); + expect(drawer()).toHaveAttribute('inert'); + expect(document.activeElement).toBe(menu()); + }); + + it('closes on a click on the dimmed window and gives the focus back to the menu button', () => { + renderApp(); + menu().focus(); + fireEvent.click(menu()); + const scrim = screen.getByTestId('drawer-scrim'); + expect(scrim.className.split(/\s+/)).toEqual(expect.arrayContaining(['fixed', 'inset-0'])); + (document.activeElement as HTMLElement).blur(); + fireEvent.click(scrim); + expect(drawer()).toHaveAttribute('inert'); + expect(document.activeElement).toBe(menu()); + }); +}); diff --git a/components/calendar/calendar-app.tsx b/components/calendar/calendar-app.tsx index 9bda4c125..81ced90b4 100644 --- a/components/calendar/calendar-app.tsx +++ b/components/calendar/calendar-app.tsx @@ -60,6 +60,7 @@ import { useIsFocusedProTab, useIsPaneScoped } from "@/hooks/use-pane-context"; import { useProMultiAccountCalendars } from "@/hooks/use-pro-multi-account-calendars"; import { useEventUserEmails } from "@/hooks/use-event-user-emails"; import { ResizeHandle } from "@/components/layout/resize-handle"; +import { EdgeDrawer } from "@/components/layout/edge-drawer"; import { descriptionWithNote } from "@/lib/calendar-description"; import { filterTasksByCalendars } from "@/lib/calendar-tasks"; import { baseEventStoreId, isServerRecurrenceInstance } from "@/lib/recurrence-instances"; @@ -183,6 +184,7 @@ export function CalendarApp({ linkSegments: routeSegments }: CalendarAppProps = // collapses into a burger-toggled overlay instead of taking inline space. const isNarrow = !isFullDesktop; const [narrowSidebarOpen, setNarrowSidebarOpen] = useState(false); + const closeNarrowSidebar = useCallback(() => setNarrowSidebarOpen(false), []); useEffect(() => { if (!isNarrow) setNarrowSidebarOpen(false); }, [isNarrow]); const { showAppsModal, inlineApp, loadedApps, handleManageApps, handleInlineApp, closeInlineApp, closeAppsModal } = useSidebarApps(); const { client, isAuthenticated, logout, checkAuth, switchAccount, activeAccountId, isLoading: authLoading } = useAuthStore(); @@ -2218,6 +2220,97 @@ export function CalendarApp({ linkSegments: routeSegments }: CalendarAppProps = /> ); + // The sidebar's content: beside the views on the full desktop, a drawer below it. + const calendarSidebar = ( + <> + { setNarrowSidebarOpen(false); openCreateForView(); }} + createLabel={createLabel} + tourTarget={!isNarrow} + /> +
+
+ +
+ { + if (calendarId === BIRTHDAY_CALENDAR_ID) { + updateSetting('birthdayCalendarColor', color); + return; + } + // Shared calendars: recolor locally only (the viewer usually + // can't write the owner's calendar, and it'd recolor it for + // everyone). Personal calendars write through to the server. + const cal = allCalendars.find((c) => c.id === calendarId); + if (cal?.isShared) { + setSharedCalendarColor(sharedCalendarColorKey(cal), color); + return; + } + updateCalendar(client, calendarId, { color }); + } : undefined} + onResetColor={(cal) => { + // Drop the local override. A calendar with a server color goes + // back to it; one without gets a fresh unused color from the + // auto-assign effect (so it never reverts to a collision). + removeSharedCalendarColor(sharedCalendarColorKey(cal)); + }} + onShareCalendar={client ? (cal) => setSharingCalendarId(cal.id) : undefined} + onCreateEvent={(cal: Calendar) => { + setDefaultCalendarIdForCreate(cal.id); + openCreateModal(); + }} + onClearCalendar={client ? async (cal: Calendar) => { + const ok = await confirmAction({ + title: tMgmt("clear_events"), + message: tMgmt("confirm_clear", { name: shownName.calendar(cal) }), + variant: "destructive", + confirmText: tMgmt("clear_events"), + }); + if (!ok) return; + try { + const count = await clearCalendarEvents(client, cal.id); + toast.success(tMgmt("events_cleared", { count })); + } catch (err) { + // The store rethrows the server's reason (#434). + toast.error(err instanceof Error && err.message ? err.message : tMgmt("error_clear")); + } + } : undefined} + onDeleteCalendar={client ? async (cal: Calendar) => { + const ok = await confirmAction({ + title: tMgmt("delete"), + message: tMgmt("confirm_delete", { name: shownName.calendar(cal) }), + variant: "destructive", + confirmText: tMgmt("delete"), + }); + if (!ok) return; + try { + await removeCalendar(client, cal.id); + toast.success(tMgmt("calendar_deleted")); + } catch { + toast.error(tMgmt("error_delete")); + } + } : undefined} + onCreateCalendar={client ? () => setShowCreateCalendar(true) : undefined} + onSubscribe={canSubscribe ? () => setShowSubscriptionModal(true) : undefined} + onEditSubscription={(subId) => setEditingSubscription(subId)} + client={client} + multiAccountMode={multiAccountEnabled && accountClients.length > 1} + /> +
+ + ); + return (
{!isEmbedded && {tShell("skip_to_content")}} @@ -2253,138 +2346,49 @@ export function CalendarApp({ linkSegments: routeSegments }: CalendarAppProps = )} - {/* Narrow-pane backdrop: dim and close overlay sidebar */} - {isNarrow && narrowSidebarOpen && !inlineApp && ( -
setNarrowSidebarOpen(false)} - /> - )} - {!inlineApp && (
- {/* Sidebar - in-flow when desktop pane, overlay when narrow */} - {(isNarrow || !sidebarCollapsed) && ( + {/* The sidebar: in flow on the full desktop; below it a drawer from + the window's edge, over the app rail, as Mail's folders. */} + {isNarrow && ( + + {calendarSidebar} + + )} + {!isNarrow && !sidebarCollapsed && ( <>
- { setNarrowSidebarOpen(false); openCreateForView(); }} - createLabel={createLabel} - tourTarget={!isNarrow} - /> -
-
- -
- { - if (calendarId === BIRTHDAY_CALENDAR_ID) { - updateSetting('birthdayCalendarColor', color); - return; - } - // Shared calendars: recolor locally only (the viewer usually - // can't write the owner's calendar, and it'd recolor it for - // everyone). Personal calendars write through to the server. - const cal = allCalendars.find((c) => c.id === calendarId); - if (cal?.isShared) { - setSharedCalendarColor(sharedCalendarColorKey(cal), color); - return; - } - updateCalendar(client, calendarId, { color }); - } : undefined} - onResetColor={(cal) => { - // Drop the local override. A calendar with a server color goes - // back to it; one without gets a fresh unused color from the - // auto-assign effect (so it never reverts to a collision). - removeSharedCalendarColor(sharedCalendarColorKey(cal)); - }} - onShareCalendar={client ? (cal) => setSharingCalendarId(cal.id) : undefined} - onCreateEvent={(cal: Calendar) => { - setDefaultCalendarIdForCreate(cal.id); - openCreateModal(); - }} - onClearCalendar={client ? async (cal: Calendar) => { - const ok = await confirmAction({ - title: tMgmt("clear_events"), - message: tMgmt("confirm_clear", { name: shownName.calendar(cal) }), - variant: "destructive", - confirmText: tMgmt("clear_events"), - }); - if (!ok) return; - try { - const count = await clearCalendarEvents(client, cal.id); - toast.success(tMgmt("events_cleared", { count })); - } catch (err) { - // The store rethrows the server's reason (#434). - toast.error(err instanceof Error && err.message ? err.message : tMgmt("error_clear")); - } - } : undefined} - onDeleteCalendar={client ? async (cal: Calendar) => { - const ok = await confirmAction({ - title: tMgmt("delete"), - message: tMgmt("confirm_delete", { name: shownName.calendar(cal) }), - variant: "destructive", - confirmText: tMgmt("delete"), - }); - if (!ok) return; - try { - await removeCalendar(client, cal.id); - toast.success(tMgmt("calendar_deleted")); - } catch { - toast.error(tMgmt("error_delete")); - } - } : undefined} - onCreateCalendar={client ? () => setShowCreateCalendar(true) : undefined} - onSubscribe={canSubscribe ? () => setShowSubscriptionModal(true) : undefined} - onEditSubscription={(subId) => setEditingSubscription(subId)} - client={client} - multiAccountMode={multiAccountEnabled && accountClients.length > 1} - /> -
+ {calendarSidebar}
- {!isNarrow && ( - { dragStartWidth.current = calSidebarWidth; setIsResizing(true); }} - onResize={(delta) => setCalSidebarWidth(Math.max(180, Math.min(400, dragStartWidth.current + delta)))} - onResizeEnd={() => { - setIsResizing(false); - localStorage.setItem("calendar-sidebar-width", String(calSidebarWidth)); - }} - onDoubleClick={() => { setCalSidebarWidth(256); localStorage.setItem("calendar-sidebar-width", "256"); }} - /> - )} + { dragStartWidth.current = calSidebarWidth; setIsResizing(true); }} + onResize={(delta) => setCalSidebarWidth(Math.max(180, Math.min(400, dragStartWidth.current + delta)))} + onResizeEnd={() => { + setIsResizing(false); + localStorage.setItem("calendar-sidebar-width", String(calSidebarWidth)); + }} + onDoubleClick={() => { setCalSidebarWidth(256); localStorage.setItem("calendar-sidebar-width", "256"); }} + /> )} diff --git a/components/contacts/__tests__/contacts-app.test.tsx b/components/contacts/__tests__/contacts-app.test.tsx index ab4c422ed..393b29bac 100644 --- a/components/contacts/__tests__/contacts-app.test.tsx +++ b/components/contacts/__tests__/contacts-app.test.tsx @@ -102,6 +102,48 @@ describe('ContactsApp', () => { expect(within(drawer()).getByText('tabs.all')).toBeInTheDocument(); }); + // The same drawer as Mail's folders (usability test 2026-11-04): it opened + // beside the app rail, ignored Escape and left the focus on the page. + it("opens the drawer from the window's edge, over the app rail and under the top bar", () => { + renderContacts(); + const classes = drawer().className.split(/\s+/); + expect(classes).toEqual(expect.arrayContaining(['fixed', 'start-0', 'top-[var(--drawer-top)]', 'bottom-0'])); + expect(classes).not.toContain('absolute'); + }); + + it('takes the focus into the drawer, keeps Tab there and gives it back to the menu button on Escape', () => { + renderContacts(); + const menu = screen.getAllByRole('button', { name: 'open_categories' })[0]; + menu.focus(); + fireEvent.click(menu); + // The category on screen. + const current = within(drawer()).getByRole('button', { name: /tabs\.all/ }); + expect(document.activeElement).toBe(current); + const stops = Array.from(drawer().querySelectorAll('button:not(:disabled)')); + stops.at(-1)!.focus(); + fireEvent.keyDown(stops.at(-1)!, { key: 'Tab' }); + expect(document.activeElement).toBe(stops[0]); + + fireEvent.keyDown(document.activeElement!, { key: 'Escape' }); + expect(drawer()).toHaveAttribute('inert'); + expect(document.activeElement).toBe(menu); + }); + + it('dims the whole window behind the drawer and closes it on a click there, back to the menu button', () => { + renderContacts(); + const menu = screen.getAllByRole('button', { name: 'open_categories' })[0]; + menu.focus(); + fireEvent.click(menu); + const scrim = screen.getByTestId('drawer-scrim'); + expect(scrim.className.split(/\s+/)).toEqual(expect.arrayContaining(['fixed', 'inset-0'])); + // A press on the scrim drops the focus to the page. + (document.activeElement as HTMLElement).blur(); + fireEvent.click(scrim); + expect(drawer()).toHaveAttribute('inert'); + expect(screen.queryByTestId('drawer-scrim')).toBeNull(); + expect(document.activeElement).toBe(menu); + }); + it("closes the drawer when something in it is picked, so it doesn't stay over the form", () => { renderContacts(); fireEvent.click(screen.getAllByRole('button', { name: 'open_categories' })[0]); diff --git a/components/contacts/contacts-app.tsx b/components/contacts/contacts-app.tsx index 70d00e408..dbbebf3d3 100644 --- a/components/contacts/contacts-app.tsx +++ b/components/contacts/contacts-app.tsx @@ -49,6 +49,7 @@ import { useIsEmbedded } from "@/hooks/use-is-embedded"; import { useIsFocusedProTab } from "@/hooks/use-pane-context"; import { useProMultiAccountContacts } from "@/hooks/use-pro-multi-account-contacts"; import { ResizeHandle } from "@/components/layout/resize-handle"; +import { EdgeDrawer } from "@/components/layout/edge-drawer"; import { useIsFullDesktop, useIsMobile } from "@/hooks/use-media-query"; import { useRefreshGesture } from "@/hooks/use-refresh-gesture"; import type { ContactCard, AddressBook, AddressBookRights } from "@/lib/jmap/types"; @@ -210,6 +211,7 @@ function ContactsAppContent({ linkSegments: routeSegments }: ContactsAppProps = // into a burger-toggled overlay. const isNarrow = !isFullDesktop; const [narrowSidebarOpen, setNarrowSidebarOpen] = useState(false); + const closeNarrowSidebar = useCallback(() => setNarrowSidebarOpen(false), []); useEffect(() => { if (!isNarrow) setNarrowSidebarOpen(false); }, [isNarrow]); // A new view (a form, a group, a contact) replaces whatever the drawer was for. useEffect(() => { setNarrowSidebarOpen(false); }, [view]); @@ -1285,6 +1287,60 @@ function ContactsAppContent({ linkSegments: routeSegments }: ContactsAppProps = } })(); + // The categories: beside the list on the full desktop, a drawer below it. + const contactsSidebar = ( + setCreatingAddressBook(true)) : undefined} + onImport={fromDrawer(() => setShowImportDialog(true))} + onEditGroup={fromDrawer(guard(handleEditGroupFromSidebar))} + onDeleteGroup={fromDrawer(handleDeleteGroupFromSidebar)} + onComposeGroup={fromDrawer(handleComposeGroupFromSidebar)} + onDropContacts={handleDropContacts} + onDropContactsToCategory={handleDropContactsToCategory} + onRenameAddressBook={client ? fromDrawer((book: AddressBook) => setRenamingAddressBook(book)) : undefined} + onShareAddressBook={client ? fromDrawer((book: AddressBook) => setSharingAddressBookId(book.id)) : undefined} + onSetDefaultAddressBook={client ? fromDrawer(async (book: AddressBook) => { + try { + await setDefaultAddressBook(client, book); + toast.success(t("address_books.default_updated")); + } catch { + toast.error(t("address_books.set_default_failed")); + } + }) : undefined} + onCreateContactInBook={fromDrawer(guard((book: AddressBook) => { + setDefaultBookIdForCreate(book.id); + setSelectedContact(null); + setView("create"); + }))} + onDeleteAddressBook={client ? fromDrawer(async (book: AddressBook) => { + const ok = await confirmDialog({ + title: t("address_books.delete_title"), + message: t("address_books.confirm_delete", { name: shownName.addressBook(book) }), + variant: "destructive", + confirmText: t("address_books.delete"), + }); + if (!ok) return; + try { + await removeAddressBook(client, book); + toast.success(t("address_books.deleted")); + } catch { + toast.error(t("address_books.delete_failed")); + } + }) : undefined} + onRenameKeyword={fromDrawer((kw: string) => setRenamingKeyword(kw))} + onDeleteKeyword={fromDrawer((kw: string) => void handleDeleteKeyword(kw))} + directoryCount={showDirectory ? directoryPrincipals.length : undefined} + multiAccountMode={multiAccountEnabled && accountClients.length > 1} + /> + ); + const mobileBackToList = () => { if (returnToEmail) { setReturnToEmail(false); @@ -1331,105 +1387,49 @@ function ContactsAppContent({ linkSegments: routeSegments }: ContactsAppProps = {inlineApp && ( )} - {/* Clips the closed drawer, so it never sits over the nav rail. */} + {/* Holds the drawer in a Pro pane and clips it there when closed. */}
- {/* Narrow-pane backdrop for the overlay categories sidebar */} - {isNarrow && narrowSidebarOpen && ( -
setNarrowSidebarOpen(false)} - /> + {/* Panel 1: the categories. Below the full desktop a drawer from the + window's edge, over the app rail, as Mail's folders. */} + {showListPanel && isNarrow && ( + + {contactsSidebar} + + )} + {showListPanel && !isNarrow && !isMobile && ( + <> +
+ {contactsSidebar} +
+ { sidebarDragStartWidth.current = sidebarWidth; setIsSidebarResizing(true); }} + onResize={(delta) => setSidebarWidth(Math.max(180, Math.min(400, sidebarDragStartWidth.current + delta)))} + onResizeEnd={() => { + setIsSidebarResizing(false); + localStorage.setItem("contacts-sidebar-width", String(sidebarWidth)); + }} + onDoubleClick={() => { setSidebarWidth(256); localStorage.setItem("contacts-sidebar-width", "256"); }} + /> + )} - {/* Panel 1: Categories sidebar (in-flow on desktop, overlay on narrow) */} - {showListPanel && (!isMobile || isNarrow) && ( - <> -
- setCreatingAddressBook(true)) : undefined} - onImport={fromDrawer(() => setShowImportDialog(true))} - onEditGroup={fromDrawer(guard(handleEditGroupFromSidebar))} - onDeleteGroup={fromDrawer(handleDeleteGroupFromSidebar)} - onComposeGroup={fromDrawer(handleComposeGroupFromSidebar)} - onDropContacts={handleDropContacts} - onDropContactsToCategory={handleDropContactsToCategory} - onRenameAddressBook={client ? fromDrawer((book: AddressBook) => setRenamingAddressBook(book)) : undefined} - onShareAddressBook={client ? fromDrawer((book: AddressBook) => setSharingAddressBookId(book.id)) : undefined} - onSetDefaultAddressBook={client ? fromDrawer(async (book: AddressBook) => { - try { - await setDefaultAddressBook(client, book); - toast.success(t("address_books.default_updated")); - } catch { - toast.error(t("address_books.set_default_failed")); - } - }) : undefined} - onCreateContactInBook={fromDrawer(guard((book: AddressBook) => { - setDefaultBookIdForCreate(book.id); - setSelectedContact(null); - setView("create"); - }))} - onDeleteAddressBook={client ? fromDrawer(async (book: AddressBook) => { - const ok = await confirmDialog({ - title: t("address_books.delete_title"), - message: t("address_books.confirm_delete", { name: shownName.addressBook(book) }), - variant: "destructive", - confirmText: t("address_books.delete"), - }); - if (!ok) return; - try { - await removeAddressBook(client, book); - toast.success(t("address_books.deleted")); - } catch { - toast.error(t("address_books.delete_failed")); - } - }) : undefined} - onRenameKeyword={fromDrawer((kw: string) => setRenamingKeyword(kw))} - onDeleteKeyword={fromDrawer((kw: string) => void handleDeleteKeyword(kw))} - directoryCount={showDirectory ? directoryPrincipals.length : undefined} - multiAccountMode={multiAccountEnabled && accountClients.length > 1} - /> -
- {!isNarrow && ( - { sidebarDragStartWidth.current = sidebarWidth; setIsSidebarResizing(true); }} - onResize={(delta) => setSidebarWidth(Math.max(180, Math.min(400, sidebarDragStartWidth.current + delta)))} - onResizeEnd={() => { - setIsSidebarResizing(false); - localStorage.setItem("contacts-sidebar-width", String(sidebarWidth)); - }} - onDoubleClick={() => { setSidebarWidth(256); localStorage.setItem("contacts-sidebar-width", "256"); }} - /> - )} - - )} {/* The list and the contact: the main content, after the sidebar. */} onSelectCategory("all")} + // Marked as the other categories are: the drawer opens on it. + aria-current={isAllActive ? "true" : undefined} className={cn( "w-full flex items-center gap-2 px-3 text-sm transition-colors min-h-8 pointer-coarse:min-h-11", isAllActive @@ -342,6 +344,7 @@ export function ContactsSidebar({ {directoryCount !== undefined && ( ); } +/** + * The button in the composer's header that brings a folded panel back (none + * on phones). An open panel's Hide button is in its head instead + * (ComposerPanelHead). + */ +export function ComposerPanelToggle({ + side, + mode, + name = null, + onToggle, + className, +}: { + side: ComposerSidebarSide; + mode: ComposerSidebarMode | null; + name?: string | null; + onToggle: () => void; + className?: string; +}) { + if (mode !== "folded") return null; + return ; +} + +/** + * The part of the composer's header row above an open panel, as wide as the + * panel: its Hide button at the panel's inner edge, and for the right panel + * whatever else ends the row (the window buttons, Close last), so they stay + * at the far end of the composer. On phones there are no panels, and no head. + */ +export function ComposerPanelHead({ + side, + mode, + width = COMPOSER_SIDEBAR_WIDTH, + name = null, + onToggle, + className, + childrenClassName, + children, +}: { + side: ComposerSidebarSide; + mode: ComposerSidebarMode | null; + width?: number; + name?: string | null; + onToggle: () => void; + /** Padding of the row it is part of. */ + className?: string; + /** The gap between what it holds besides Hide, as in the row it is part of. */ + childrenClassName?: string; + children?: ReactNode; +}) { + if (!isPanelOpen(mode)) return null; + const hide = ; + return ( +
+ {side === "right" && hide} +
+ {/* No gap of the head's own around Hide and the space: a 260 px panel in the desktop app has just enough room for the buttons. */} + {children &&
{children}
} + {side === "left" && hide} +
+ ); +} + const COMPOSER_HEADER = "[data-composer-header], [data-mv-compose-titlebar], [data-mv-compose-inline-bar]"; const COMPOSER_FOOTER = "[data-composer-footer]"; diff --git a/components/email/email-composer.tsx b/components/email/email-composer.tsx index a1384e37c..d578f7d46 100644 --- a/components/email/email-composer.tsx +++ b/components/email/email-composer.tsx @@ -92,7 +92,7 @@ import { useIdentityStore } from "@/stores/identity-store"; import { useProMultiAccountIdentities, stripCrossAccountIdentityPrefix } from "@/hooks/use-pro-multi-account-identities"; import { useAccountStore } from "@/stores/account-store"; import { useSettingsStore } from "@/stores/settings-store"; -import { ComposerPanelToggle, ComposerPluginSidebar, useComposerSidebars } from "./composer-plugin-sidebars"; +import { ComposerPanelHead, ComposerPanelToggle, ComposerPluginSidebar, isPanelOpen, useComposerSidebars } from "./composer-plugin-sidebars"; import { dragKindFromTypes } from "@/components/pro/pro-shell-drop"; import { useIsPaneScoped } from "@/hooks/use-pane-context"; import { ComposerSelectionMenu, useComposerSelectionMenu } from "./composer-selection-menu"; @@ -188,7 +188,10 @@ import { fileStorage } from "@/lib/plugin-storage"; import { usePolicyStore } from "@/stores/policy-store"; import { isAppLockedNow } from "@/lib/app-lock/state"; import { registerComposeFlush, registerComposeSnapshot } from "@/lib/compose-flush-registry"; -import { getDesktopBridge } from "@/lib/desktop/bridge"; +import { getDesktopBridge, isDesktopApp } from "@/lib/desktop/bridge"; +import { readRecentFile, RECENT_FILE_MAX_BYTES, useRecentFilesOffered } from "@/lib/desktop/recent-files"; +import type { DesktopRecentFile } from "@/lib/desktop/types"; +import { RecentFilesMenuSection } from "@/components/email/recent-files-menu-section"; import { useDesktopCommands } from "@/lib/desktop/commands"; import { noteComposerLanguage } from "@/lib/desktop/languages"; import { noteOpenDraft } from "@/lib/desktop/window-restore"; @@ -650,6 +653,7 @@ export function EmailComposer({ const tEdit = useTranslations('desktopEdit'); const tOfflineDrafts = useTranslations('offlineDrafts'); const tOffline = useTranslations('offline'); + const tRecent = useTranslations('desktopAttachRecent'); const tOfflineNotes = useTranslations('offlineConflicts'); const tSendGuards = useTranslations('send_guards'); const tWords = useTranslations('compose_words'); @@ -2778,6 +2782,20 @@ export function EmailComposer({ void addFiles(initialFiles, { handedIn: true }); }, [client, initialFiles, addFiles]); + // The Attach menu's recent files, in the desktop app (lib/desktop/recent-files.ts). The + // shell reads the file; from there it's a file like one from the file dialog. + const recentOffered = useRecentFilesOffered(); + const attachRecentFile = useCallback(async (file: DesktopRecentFile) => { + const result = await readRecentFile(file.id); + if (result.ok) { + await addFiles([result.file]); + return; + } + if (result.reason === 'missing') toast.error(tRecent('missing', { name: file.name })); + else if (result.reason === 'too-large') toast.error(tRecent('too_large', { name: file.name, max: formatFileSize(RECENT_FILE_MAX_BYTES) })); + else if (result.reason === 'failed') toast.error(tRecent('failed', { name: file.name })); + }, [addFiles, tRecent]); + const handleFileSelect = async (event: React.ChangeEvent) => { if (!event.target.files) return; await addFiles(Array.from(event.target.files)); @@ -3621,13 +3639,28 @@ export function EmailComposer({ [pluginDraft, pluginSelection, pluginComposerId, pluginSidebars.focusRequests.right], ); - // The buttons that show and hide the plugin panels, in the header. - const leftPanelToggle = pluginSidebars.modes.left - ? pluginSidebars.toggle('left')} /> + // The plugin panels in the header row: a folded one's Show button, and an + // open one's head with its Hide button (see composer-plugin-sidebars.tsx). + const leftPanelToggle = pluginSidebars.modes.left === 'folded' + ? pluginSidebars.toggle('left')} /> : null; - const rightPanelToggle = pluginSidebars.modes.right - ? pluginSidebars.toggle('right')} /> + const rightPanelToggle = pluginSidebars.modes.right === 'folded' + ? pluginSidebars.toggle('right')} /> : null; + const rightPanelOpen = isPanelOpen(pluginSidebars.modes.right); + const panelHead = (side: 'left' | 'right', className: string, children?: React.ReactNode, childrenClassName?: string) => ( + pluginSidebars.toggle(side)} + className={className} + childrenClassName={childrenClassName} + > + {children} + + ); // The right-click menu on selected text, when a plugin put entries in it. const selectionMenu = useComposerSelectionMenu(); @@ -4737,6 +4770,86 @@ export function EmailComposer({ ); + // What ends the header row: the window buttons, Close last. With the right + // panel open they end its head instead, at the far end of the composer. + const windowButtons = ( + <> + {canMaximize && ( + + )} + {popOutButton(cn(phoneLayout ? "hidden md:grid" : "grid", "h-8 w-8 shrink-0 place-items-center rounded-md text-muted-foreground hover:bg-muted hover:text-foreground"), "w-4 h-4")} + {!closeBesideControls && composerCloseButton} + + ); + const mvInlineButtons = mvWindow && ( + <> + {mvWindow.popOut && ( + + )} + {popOutButton("grid h-8 w-8 shrink-0 place-items-center rounded-full text-muted-foreground hover:bg-muted hover:text-foreground", "h-4 w-4")} + + + ); + const mvWindowButtons = mvWindow && ( + <> + {mvWindow.state !== "minimized" && popOutButton("grid h-7 w-7 shrink-0 place-items-center rounded-full text-muted-foreground hover:bg-foreground/10 hover:text-foreground", "h-4 w-4")} + + + + + ); + // Files dropped on the header attach, as on the rest of the message. + const headerDropProps = { onDragEnter: handleDragEnter, onDragLeave: handleDragLeave, onDragOver: handleDragOver, onDrop: handleDrop }; + // `keepDraft`: the bin's discard, which deletes the draft once its Undo is // over, not here. const handleDiscardAndClose = ({ keepDraft = false }: { keepDraft?: boolean } = {}) => { @@ -5019,8 +5132,11 @@ export function EmailComposer({ data-testid="email-composer" // Edits made while the draft moves wouldn't move with it. inert={isPoppingOut || undefined} + // The header row on top, across the plugin panels too, so the window + // buttons and Close end the whole composer; panels and message below. + data-tour="composer" className={cn( - "flex h-full bg-background relative", + "flex flex-col h-full bg-background relative", className, // Over everything but dialogs (z-60) and toasts; below the desktop app's window controls. // At the folder sidebar's z-50 and after it in the page, so over it (compose-p2-5). @@ -5039,112 +5155,57 @@ export function EmailComposer({
{liveMessage && {liveMessage.text}}
- pluginSidebars.setSideWidth('left', w)} /> - {/* Right-side composer sidebar slot is rendered after the main content div below. */} -
- {/* Drag overlay */} - {isDraggingOver && ( -
-
- - {t('drop_files')} -
-
- )} {/* Header - mobile: clean bar with close/send, desktop: title bar. In Mountain View's window it is the window's title bar instead. */} {mvWindow?.variant === "inline" ? ( -
- {mode === 'replyAll' - ? - : mode === 'forward' - ? - : } -

- {mode === 'reply' ? t('reply') : mode === 'replyAll' ? t('reply_all') : mode === 'forward' ? t('forward') : t('new_message')} -

- {saveStatus === 'saving' && } - {leftPanelToggle} - {rightPanelToggle} - {mvWindow.popOut && ( - - )} - {popOutButton("grid h-8 w-8 place-items-center rounded-full text-muted-foreground hover:bg-muted hover:text-foreground", "h-4 w-4")} - +
+ {panelHead('left', 'px-1.5')} +
+ {mode === 'replyAll' + ? + : mode === 'forward' + ? + : } +

+ {mode === 'reply' ? t('reply') : mode === 'replyAll' ? t('reply_all') : mode === 'forward' ? t('forward') : t('new_message')} +

+ {saveStatus === 'saving' && } + {leftPanelToggle} + {rightPanelToggle} + {!rightPanelOpen && mvInlineButtons} +
+ {panelHead('right', 'ps-1.5 pe-1.5', mvInlineButtons, 'gap-2')}
) : mvWindow ? (
mvWindow.setState("normal") : undefined} + {...headerDropProps} > -

- {mode === 'reply' || mode === 'replyAll' || mode === 'forward' - ? (subject || t('new_message')) - : t('new_message')} -

- {saveStatus === 'saving' && } - {mvWindow.state !== "minimized" && leftPanelToggle} - {mvWindow.state !== "minimized" && rightPanelToggle} - {mvWindow.state !== "minimized" && popOutButton("grid h-7 w-7 place-items-center rounded-full text-muted-foreground hover:bg-foreground/10 hover:text-foreground", "h-4 w-4")} - - - + {mvWindow.state !== "minimized" && panelHead('left', 'px-1.5')} +
+

+ {mode === 'reply' || mode === 'replyAll' || mode === 'forward' + ? (subject || t('new_message')) + : t('new_message')} +

+ {saveStatus === 'saving' && } + {mvWindow.state !== "minimized" && leftPanelToggle} + {mvWindow.state !== "minimized" && rightPanelToggle} + {(mvWindow.state === "minimized" || !rightPanelOpen) && mvWindowButtons} +
+ {mvWindow.state !== "minimized" && panelHead('right', 'ps-1.5 pe-1.5', mvWindowButtons, 'gap-1')}
) : ( -
+
+ {panelHead('left', 'px-2')} +
{closeBesideControls && composerCloseButton} - {/* The left panel's button at the start, the right one's at the end: where each panel is. */} + {/* A folded panel's Show button where the panel goes: the left one's at the start, the right one's before the window buttons. */} {leftPanelToggle &&
{leftPanelToggle}
}
@@ -5214,23 +5275,31 @@ export function EmailComposer({ ))} {rightPanelToggle} - {canMaximize && ( - - )} - {popOutButton(cn(phoneLayout ? "hidden md:grid" : "grid", "h-8 w-8 place-items-center rounded-md text-muted-foreground hover:bg-muted hover:text-foreground"), "w-4 h-4")} - {!closeBesideControls && composerCloseButton} + {!rightPanelOpen && windowButtons} +
+ {panelHead('right', 'ps-1.5 pe-4', windowButtons, 'gap-3')}
)} + {/* The left panel, the message and the right panel, under the header. */} +
+ pluginSidebars.setSideWidth('left', w)} /> +
+ {/* Drag overlay */} + {isDraggingOver && ( +
+
+ + {t('drop_files')} +
+
+ )} {/* Fields + body. While pinFields holds, the fields sit outside the body's scroll container so From/To/Cc/Bcc/Subject stay reachable while scrolling long bodies, matching the pinned formatting toolbar @@ -5890,14 +5959,19 @@ export function EmailComposer({ className="hidden" accept="*/*" /> - {(filesEnabled && composerClient?.supportsFiles?.()) || hasAttachMenuActions ? ( + {recentOffered || (filesEnabled && composerClient?.supportsFiles?.()) || hasAttachMenuActions ? ( {(close) => <> + {/* As Outlook's: the recent files first, one click attaches one and closes. */} + {recentOffered && ( + { close(); void attachRecentFile(file); }} /> + )} { close(); fileInputRef.current?.click(); }} + testId="composer-attach-from-device" > - {t('attach_from_device')} + {isDesktopApp() ? tRecent('browse') : t('attach_from_device')} {filesEnabled && composerClient?.supportsFiles?.() && ( { close(); setFilesPicker({ client: composerClient, accountId: composerAccountId }); }} testId="composer-attach-from-files" > - {t('attach_from_files')} + {isDesktopApp() ? tRecent('from_files') : t('attach_from_files')} )} @@ -6305,6 +6379,7 @@ export function EmailComposer({ )}
pluginSidebars.setSideWidth('right', w)} /> +
); diff --git a/components/email/recent-files-menu-section.tsx b/components/email/recent-files-menu-section.tsx new file mode 100644 index 000000000..524478d26 --- /dev/null +++ b/components/email/recent-files-menu-section.tsx @@ -0,0 +1,88 @@ +"use client"; + +import { useEffect, useLayoutEffect, useRef, useState } from "react"; +import { useLocale, useTranslations } from "next-intl"; +import { CONTEXT_MENU_ITEM_CLASS, menuLevelItems } from "@/components/ui/context-menu"; +import { attachmentIcon } from "@/components/email/attachment-chips"; +import { listRecentFiles, recentWhen, shortFolder } from "@/lib/desktop/recent-files"; +import type { DesktopRecentFile } from "@/lib/desktop/types"; +import { cn } from "@/lib/utils"; + +/** Only an icon the shell made: a PNG as a data: URL. */ +const ICON_URL = /^data:image\/png;base64,[A-Za-z0-9+/=]+$/; + +/** + * The top of the composer's Attach menu in the desktop app: the files the OS says were + * used last, as Outlook lists them. Mounted when the menu opens, from that click, which is + * what the shell asks for. Until the list is there, and when it's empty, it takes no room. + * It stays an HTML menu (data-native-menu): a native one can't show the icons and folders. + */ +export function RecentFilesMenuSection({ onPick }: { onPick: (file: DesktopRecentFile) => void }) { + const t = useTranslations("desktopAttachRecent"); + const locale = useLocale(); + const [files, setFiles] = useState(null); + // One request per opening, also when a strict-mode remount runs the effect twice. + const request = useRef | null>(null); + const rootRef = useRef(null); + + useEffect(() => { + let cancelled = false; + request.current ??= listRecentFiles(); + void request.current.then((list) => { + if (!cancelled) setFiles(list); + }); + return () => { + cancelled = true; + }; + }, []); + + // The menu put the focus on its first entry before the list came. If it's still + // there, the first file takes it: the list is what comes first. + useLayoutEffect(() => { + const root = rootRef.current; + const menu = root?.closest('[role="menu"]'); + if (!root || !menu || !files?.length) return; + const active = document.activeElement; + const others = menuLevelItems(menu).filter((item) => !root.contains(item)); + if (active && active === others[0]) root.querySelector('[role="menuitem"]')?.focus({ preventScroll: true }); + }, [files]); + + const now = Date.now(); + return ( +