Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

MUL-5842: fix(layout): fold inbox and chat to one column below lg (#6543)

Bowser035bd20e5b39
diff --git a/apps/desktop/src/renderer/src/components/desktop-layout.tsx b/apps/desktop/src/renderer/src/components/desktop-layout.tsx
index e55569cded..562c0d811c 100644
--- a/apps/desktop/src/renderer/src/components/desktop-layout.tsx
+++ b/apps/desktop/src/renderer/src/components/desktop-layout.tsx
@@ -105,8 +105,8 @@ function useNativeNavigationGestures() {
// is not occupying main-flow width, leave room for the fixed window toolbar
// so tabs do not land beneath the traffic lights / navigation controls.
function MainTopBar() {
- const { state, isMobile } = useSidebar();
- const sidebarHidden = state === "collapsed" || isMobile;
+ const { state, isCompact } = useSidebar();
+ const sidebarHidden = state === "collapsed" || isCompact;
return (
<motion.header
@@ -134,8 +134,8 @@ function MainTopBar() {
// leaves the main flow, the left margin must grow to mirror the fixed mr-2 so
// the floating canvas sits symmetrically inside the window frame.
function MainCanvas({ children }: { children: React.ReactNode }) {
- const { state, isMobile } = useSidebar();
- const sidebarHidden = state === "collapsed" || isMobile;
+ const { state, isCompact } = useSidebar();
+ const sidebarHidden = state === "collapsed" || isCompact;
return (
<motion.div
diff --git a/packages/ui/components/ui/sidebar.tsx b/packages/ui/components/ui/sidebar.tsx
index a5257a2f99..72b10c54c8 100644
--- a/packages/ui/components/ui/sidebar.tsx
+++ b/packages/ui/components/ui/sidebar.tsx
@@ -6,7 +6,7 @@ import { useRender } from "@base-ui/react/use-render"
import { cva, type VariantProps } from "class-variance-authority"
import { useTranslation } from "react-i18next"
-import { useIsMobile } from "@multica/ui/hooks/use-mobile"
+import { useIsCompact } from "@multica/ui/hooks/use-mobile"
import { cn } from "@multica/ui/lib/utils"
import { Button } from "@multica/ui/components/ui/button"
import { Input } from "@multica/ui/components/ui/input"
@@ -35,6 +35,10 @@ const SIDEBAR_WIDTH_STORAGE_KEY = "sidebar_width"
const SIDEBAR_WIDTH_MOBILE = "18rem"
const SIDEBAR_WIDTH_ICON = "3rem"
const SIDEBAR_DRAG_THRESHOLD = 2
+// Tailwind `lg`–`xl`: wide enough to keep a two-pane list/detail surface, too
+// narrow to also spend 256px on the nav. The nav starts collapsed here and the
+// header's trigger brings it back.
+const SIDEBAR_AUTO_COLLAPSE_QUERY = "(min-width: 1024px) and (max-width: 1279px)"
function clampSidebarWidth(width: number) {
return Math.max(SIDEBAR_WIDTH_MIN, Math.min(SIDEBAR_WIDTH_MAX, width))
@@ -46,7 +50,12 @@ type SidebarContextProps = {
setOpen: (open: boolean) => void
openMobile: boolean
setOpenMobile: (open: boolean) => void
- isMobile: boolean
+ /**
+ * The sidebar is an overlay sheet rather than a column in the main flow.
+ * True below the compact breakpoint, which covers tablets and folded inner
+ * screens as well as phones, not phones alone.
+ */
+ isCompact: boolean
toggleSidebar: () => void
}
@@ -94,7 +103,7 @@ function SidebarProvider({
open?: boolean
onOpenChange?: (open: boolean) => void
}) {
- const isMobile = useIsMobile()
+ const isCompact = useIsCompact()
const [openMobile, setOpenMobile] = React.useState(false)
const [width, _setWidth] = React.useState(SIDEBAR_WIDTH_DEFAULT)
@@ -132,10 +141,42 @@ function SidebarProvider({
[setOpenProp, open]
)
+ // Auto-collapse across the `lg`–`xl` band. Only the two crossings are
+ // automated: entering it parks the state we came in with and closes the nav,
+ // leaving it restores that state. Anything the user does in between — most
+ // of all re-opening the nav — is left alone until the next crossing.
+ //
+ // `setOpen`'s identity changes with `open`, so the listener reads both
+ // through a ref instead of resubscribing on every toggle. The ref is seeded
+ // at first render and refreshed after each commit — declared above the
+ // listener so on mount it is already current when that effect first runs.
+ const latest = React.useRef({ open, setOpen })
+ React.useEffect(() => {
+ latest.current = { open, setOpen }
+ })
+ const parkedOpenRef = React.useRef<boolean | null>(null)
+ React.useEffect(() => {
+ const mql = window.matchMedia(SIDEBAR_AUTO_COLLAPSE_QUERY)
+ const apply = (matches: boolean) => {
+ if (matches) {
+ if (parkedOpenRef.current !== null) return
+ parkedOpenRef.current = latest.current.open
+ latest.current.setOpen(false)
+ } else if (parkedOpenRef.current !== null) {
+ latest.current.setOpen(parkedOpenRef.current)
+ parkedOpenRef.current = null
+ }
+ }
+ apply(mql.matches)
+ const onChange = (e: MediaQueryListEvent) => apply(e.matches)
+ mql.addEventListener("change", onChange)
+ return () => mql.removeEventListener("change", onChange)
+ }, [])
+
// Helper to toggle the sidebar.
const toggleSidebar = React.useCallback(() => {
- return isMobile ? setOpenMobile((open) => !open) : setOpen((open) => !open)
- }, [isMobile, setOpen, setOpenMobile])
+ return isCompact ? setOpenMobile((open) => !open) : setOpen((open) => !open)
+ }, [isCompact, setOpen, setOpenMobile])
// We add a state so that we can do data-state="expanded" or "collapsed".
// This makes it easier to style the sidebar with Tailwind classes.
@@ -146,12 +187,12 @@ function SidebarProvider({
state,
open,
setOpen,
- isMobile,
+ isCompact,
openMobile,
setOpenMobile,
toggleSidebar,
}),
- [state, open, setOpen, isMobile, openMobile, setOpenMobile, toggleSidebar]
+ [state, open, setOpen, isCompact, openMobile, setOpenMobile, toggleSidebar]
)
const resizeContextValue = React.useMemo<SidebarResizeContextProps>(
() => ({
@@ -198,7 +239,7 @@ function Sidebar({
variant?: "sidebar" | "floating" | "inset"
collapsible?: "offcanvas" | "icon" | "none"
}) {
- const { isMobile, state, openMobile, setOpenMobile } = useSidebar()
+ const { isCompact, state, openMobile, setOpenMobile } = useSidebar()
if (collapsible === "none") {
return (
@@ -215,7 +256,7 @@ function Sidebar({
)
}
- if (isMobile) {
+ if (isCompact) {
return (
<Sheet open={openMobile} onOpenChange={setOpenMobile} {...props}>
<SheetContent
@@ -241,9 +282,13 @@ function Sidebar({
)
}
+ // `lg`, not `md`: this CSS gate has to agree with the `useIsCompact()` gate
+ // that chose the in-flow branch over the sheet above. While they disagreed,
+ // every load between the two breakpoints painted a 256px sidebar for one
+ // frame before the hook resolved and collapsed it into a sheet.
return (
<div
- className="group peer hidden text-sidebar-foreground md:block"
+ className="group peer hidden text-sidebar-foreground lg:block"
data-state={state}
data-collapsible={state === "collapsed" ? collapsible : ""}
data-variant={variant}
@@ -266,7 +311,7 @@ function Sidebar({
data-slot="sidebar-container"
data-side={side}
className={cn(
- "fixed inset-y-0 z-10 hidden h-svh w-(--sidebar-width) transition-[left,right,width] duration-200 ease-out motion-reduce:transition-none md:flex",
+ "fixed inset-y-0 z-10 hidden h-svh w-(--sidebar-width) transition-[left,right,width] duration-200 ease-out motion-reduce:transition-none lg:flex",
"data-[side=left]:left-0 data-[side=left]:group-data-[collapsible=offcanvas]:left-[calc(var(--sidebar-width)*-1)] data-[side=right]:right-0 data-[side=right]:group-data-[collapsible=offcanvas]:right-[calc(var(--sidebar-width)*-1)]",
// Adjust the padding for floating and inset variants.
variant === "floating" || variant === "inset"
@@ -470,7 +515,7 @@ function SidebarInset({ className, ...props }: React.ComponentProps<"main">) {
<main
data-slot="sidebar-inset"
className={cn(
- "relative flex w-full flex-1 flex-col bg-page-canvas md:peer-data-[variant=inset]:m-2 md:peer-data-[variant=inset]:ml-0 md:peer-data-[variant=inset]:rounded-xl md:peer-data-[variant=inset]:ring-1 md:peer-data-[variant=inset]:ring-surface-border md:peer-data-[variant=inset]:shadow-[var(--surface-shadow)] md:peer-data-[variant=inset]:peer-data-[state=collapsed]:ml-2",
+ "relative flex w-full flex-1 flex-col bg-page-canvas lg:peer-data-[variant=inset]:m-2 lg:peer-data-[variant=inset]:ml-0 lg:peer-data-[variant=inset]:rounded-xl lg:peer-data-[variant=inset]:ring-1 lg:peer-data-[variant=inset]:ring-surface-border lg:peer-data-[variant=inset]:shadow-[var(--surface-shadow)] lg:peer-data-[variant=inset]:peer-data-[state=collapsed]:ml-2",
className
)}
{...props}
@@ -672,7 +717,7 @@ function SidebarMenuButton({
isActive?: boolean
tooltip?: string | React.ComponentProps<typeof TooltipContent>
} & VariantProps<typeof sidebarMenuButtonVariants>) {
- const { isMobile, state } = useSidebar()
+ const { isCompact, state } = useSidebar()
const comp = useRender({
defaultTagName: "button",
props: mergeProps<"button">(
@@ -706,7 +751,7 @@ function SidebarMenuButton({
<TooltipContent
side="right"
align="center"
- hidden={state !== "collapsed" || isMobile}
+ hidden={state !== "collapsed" || isCompact}
{...tooltip}
/>
</Tooltip>
diff --git a/packages/ui/hooks/use-mobile.ts b/packages/ui/hooks/use-mobile.ts
index 2b0fe1dfef..6107c04390 100644
--- a/packages/ui/hooks/use-mobile.ts
+++ b/packages/ui/hooks/use-mobile.ts
@@ -1,19 +1,31 @@
import * as React from "react"
const MOBILE_BREAKPOINT = 768
+// Tailwind `lg`. Below it a 256px nav plus a 320px list column leave a
+// list/detail surface only a couple hundred pixels of reading width, so those
+// surfaces fold to the single column phones already get.
+const COMPACT_BREAKPOINT = 1024
-export function useIsMobile() {
- const [isMobile, setIsMobile] = React.useState<boolean | undefined>(undefined)
+function useIsBelow(breakpoint: number) {
+ const [isBelow, setIsBelow] = React.useState<boolean | undefined>(undefined)
React.useEffect(() => {
- const mql = window.matchMedia(`(max-width: ${MOBILE_BREAKPOINT - 1}px)`)
+ const mql = window.matchMedia(`(max-width: ${breakpoint - 1}px)`)
const onChange = () => {
- setIsMobile(window.innerWidth < MOBILE_BREAKPOINT)
+ setIsBelow(window.innerWidth < breakpoint)
}
mql.addEventListener("change", onChange)
- setIsMobile(window.innerWidth < MOBILE_BREAKPOINT)
+ setIsBelow(window.innerWidth < breakpoint)
return () => mql.removeEventListener("change", onChange)
- }, [])
+ }, [breakpoint])
+
+ return !!isBelow
+}
+
+export function useIsMobile() {
+ return useIsBelow(MOBILE_BREAKPOINT)
+}
- return !!isMobile
+export function useIsCompact() {
+ return useIsBelow(COMPACT_BREAKPOINT)
}
diff --git a/packages/views/chat/chat-page.test.tsx b/packages/views/chat/chat-page.test.tsx
index 5bd43d6a04..8a878a2171 100644
--- a/packages/views/chat/chat-page.test.tsx
+++ b/packages/views/chat/chat-page.test.tsx
@@ -71,8 +71,16 @@ vi.mock("@multica/ui/components/ui/resizable", () => ({
),
ResizableHandle: () => null,
}));
+// Same width-driven layout mock the inbox page tests use: the deep-link tests
+// all want the desktop two-pane layout, the breakpoint tests at the bottom set
+// their own width.
+const FOLD_INNER = 851;
+const TABLET = 1024;
+const DESKTOP = 1440;
+const layout = vi.hoisted(() => ({ width: 1440 }));
vi.mock("@multica/ui/hooks/use-mobile", () => ({
- useIsMobile: () => false,
+ useIsMobile: () => layout.width < 768,
+ useIsCompact: () => layout.width < 1024,
}));
vi.mock("@multica/core/paths", () => ({
useWorkspacePaths: () => ({ chat: () => "/acme/chat" }),
@@ -229,6 +237,7 @@ beforeEach(() => {
storeListeners.clear();
availableAgentsRef.current = [agent];
agentsSettledRef.current = true;
+ layout.width = DESKTOP;
});
describe("ChatPage ?agent= deep link", () => {
@@ -314,3 +323,50 @@ describe("ChatPage ?agent= deep link", () => {
expect(screen.getByText("chat-input")).toBeInTheDocument();
});
});
+
+describe("ChatPage responsive layout", () => {
+ const SELECT_PROMPT = "Pick a conversation, or start a new one with +";
+
+ it("folds to a single column on a folded inner screen", () => {
+ // 851px — the reported Pixel Fold inner screen. Too narrow for nav + thread
+ // list + conversation, so with nothing open it spends the whole width on
+ // the list instead of an empty conversation pane.
+ layout.width = FOLD_INNER;
+ renderPage("");
+
+ expect(
+ screen.getByRole("button", { name: "select-thread" }),
+ ).toBeInTheDocument();
+ expect(screen.queryByText(SELECT_PROMPT)).not.toBeInTheDocument();
+ });
+
+ it("gives the open conversation the whole folded inner screen", () => {
+ // Opening a thread replaces the list, so the way back has to travel with
+ // the conversation — same trip the phone layout already had.
+ layout.width = FOLD_INNER;
+ // The page reconciles the store against `?session=`, so the open thread has
+ // to be in the URL too — otherwise the sync effect closes it.
+ storeRef.current = { activeSessionId: "session-1" };
+ renderPage("session=session-1");
+
+ expect(
+ screen.queryByRole("button", { name: "select-thread" }),
+ ).not.toBeInTheDocument();
+ expect(screen.getByText("chat-input")).toBeInTheDocument();
+ expect(screen.getByRole("button", { name: "Chat" })).toBeInTheDocument();
+ });
+
+ it("keeps both panes at the compact breakpoint", () => {
+ // 1024px is the first width that keeps two panes. The nav auto-collapses
+ // there instead (see the sidebar), so the thread list stays on screen next
+ // to an open conversation.
+ layout.width = TABLET;
+ storeRef.current = { activeSessionId: "session-1" };
+ renderPage("session=session-1");
+
+ expect(
+ screen.getByRole("button", { name: "select-thread" }),
+ ).toBeInTheDocument();
+ expect(screen.getByText("chat-input")).toBeInTheDocument();
+ });
+});
diff --git a/packages/views/chat/chat-page.tsx b/packages/views/chat/chat-page.tsx
index 954463eed1..1427001bb7 100644
--- a/packages/views/chat/chat-page.tsx
+++ b/packages/views/chat/chat-page.tsx
@@ -10,7 +10,7 @@ import {
ResizablePanel,
ResizableHandle,
} from "@multica/ui/components/ui/resizable";
-import { useIsMobile } from "@multica/ui/hooks/use-mobile";
+import { useIsCompact } from "@multica/ui/hooks/use-mobile";
import { useWorkspacePaths } from "@multica/core/paths";
import { useChatStore } from "@multica/core/chat";
import { chatQuickActionsPendingOptions } from "@multica/core/chat/queries";
@@ -58,7 +58,7 @@ export function ChatPage() {
const { t } = useT("chat");
const { searchParams, replace } = useNavigation();
const wsPaths = useWorkspacePaths();
- const isMobile = useIsMobile();
+ const isCompact = useIsCompact();
const c = useChatController({ isActive: true });
const { data: quickActionsPending = null } = useQuery(
@@ -74,7 +74,7 @@ export function ChatPage() {
const urlAgent = searchParams.get("agent") || null;
// "Composing a brand-new chat" — the user hit ⊕ but hasn't sent yet, so no
- // session exists. On mobile this decides list-vs-conversation; on desktop the
+ // session exists. At compact widths this decides list-vs-conversation; on desktop the
// conversation pane is always mounted so it only needs to reset itself once a
// real session takes over.
const [composingNew, setComposingNew] = useState(false);
@@ -140,13 +140,13 @@ export function ChatPage() {
// Single archive path for both entry points (thread-list row + conversation
// header). When the archived chat is the one in view, move the pane off it:
- // on desktop advance to the next chat (Inbox-style); on mobile drop back to
+ // on desktop advance to the next chat (Inbox-style); when compact drop back to
// the list, which reads more naturally than being thrown into an unrelated
// conversation full-screen. Archiving any other chat leaves the view put.
const handleArchive = (session: ChatSession) => {
supersedeAgentIntent();
if (session.id === c.activeSessionId) {
- if (isMobile) {
+ if (isCompact) {
c.setActiveSession(null);
setComposingNew(false);
} else {
@@ -169,8 +169,9 @@ export function ChatPage() {
if (projectId === c.activeProjectId) return;
c.handleProjectChange(projectId);
// Removing a project stays in the current conversation. Choosing a
- // project for an existing conversation starts a clean session, and mobile
- // must remain in the compose pane after activeSessionId is cleared.
+ // project for an existing conversation starts a clean session, and a
+ // compact layout must stay in the compose pane after activeSessionId is
+ // cleared.
if (!c.currentSession || projectId !== null) setComposingNew(true);
};
@@ -332,8 +333,8 @@ export function ChatPage() {
</div>
);
- // -- Mobile: list / conversation toggle -----------------------------------
- if (isMobile) {
+ // -- Compact: list / conversation toggle -----------------------------------
+ if (isCompact) {
if (c.activeSessionId || composingNew) {
return (
<div className="flex flex-1 flex-col min-h-0">
diff --git a/packages/views/inbox/components/inbox-page.test.tsx b/packages/views/inbox/components/inbox-page.test.tsx
index c23f72a2c3..98830eacfc 100644
--- a/packages/views/inbox/components/inbox-page.test.tsx
+++ b/packages/views/inbox/components/inbox-page.test.tsx
@@ -81,13 +81,19 @@ vi.mock("../../navigation", () => ({
useNavigation: () => ({ searchParams, replace }),
}));
-// Mobile by default — it renders the list and the detail as one column, which
-// keeps most assertions simple. Tests about actioning a row WHILE it is open
-// need the two-panel desktop layout, since mobile swaps the list out for the
-// detail on selection.
-const layout = { isMobile: true };
+// Drive the layout from a viewport width so a test can name the device it
+// cares about instead of a boolean, and the two breakpoints stay in one place.
+// Phone-width by default — one column keeps most assertions simple. Tests
+// about actioning a row WHILE it is open need the two-panel desktop layout,
+// since a single column swaps the list out for the detail on selection.
+const PHONE = 390;
+const FOLD_INNER = 851;
+const TABLET = 1024;
+const DESKTOP = 1440;
+const layout = { width: PHONE };
vi.mock("@multica/ui/hooks/use-mobile", () => ({
- useIsMobile: () => layout.isMobile,
+ useIsMobile: () => layout.width < 768,
+ useIsCompact: () => layout.width < 1024,
}));
vi.mock("@multica/ui/components/ui/resizable", () => ({
ResizablePanelGroup: ({ children }: { children: React.ReactNode }) => (
@@ -171,7 +177,7 @@ function reset() {
markReadMutate.mockClear();
markUnreadMutate.mockClear();
rowActions = null;
- layout.isMobile = true;
+ layout.width = PHONE;
}
describe("InboxPage", () => {
@@ -305,7 +311,7 @@ describe("InboxPage", () => {
// silently undoes the user's "mark as unread" — the action looks like a
// no-op.
reset();
- layout.isMobile = false;
+ layout.width = DESKTOP;
listData.active = [
item({ id: "inbox-a", issue_id: "issue-a", read: false }),
];
@@ -325,7 +331,7 @@ describe("InboxPage", () => {
// The guard is scoped to the row while it stays selected. Coming back to it
// later is a fresh open and must behave like any other.
reset();
- layout.isMobile = false;
+ layout.width = DESKTOP;
listData.active = [
item({ id: "inbox-a", issue_id: "issue-a", read: false }),
item({ id: "inbox-b", issue_id: "issue-b", read: false }),
@@ -343,6 +349,36 @@ describe("InboxPage", () => {
expect(markReadMutate).toHaveBeenCalledWith("inbox-a", expect.anything());
});
+ it("folds to a single column on a folded inner screen", () => {
+ // 851px — the reported Pixel Fold inner screen. Above the phone breakpoint
+ // but far too narrow for nav + list + detail, so it takes the same single
+ // column: opening a row replaces the list rather than sharing the width.
+ reset();
+ layout.width = FOLD_INNER;
+ listData.active = [item({ id: "inbox-a", issue_id: "issue-a" })];
+
+ render(<InboxPage />);
+ expect(screen.queryByTestId("list")).not.toBeNull();
+
+ fireEvent.click(screen.getByTestId("row"));
+
+ expect(screen.queryByTestId("list")).toBeNull();
+ });
+
+ it("keeps both panes at the compact breakpoint", () => {
+ // 1024px is the first width that keeps the two-pane layout. The nav
+ // auto-collapses there instead (see the sidebar), so the list has to stay
+ // on screen next to an open item.
+ reset();
+ layout.width = TABLET;
+ listData.active = [item({ id: "inbox-a", issue_id: "issue-a" })];
+
+ render(<InboxPage />);
+ fireEvent.click(screen.getByTestId("row"));
+
+ expect(screen.queryByTestId("list")).not.toBeNull();
+ });
+
it("does not swallow a deep link to an issue that is not in the archive", () => {
// ?view=archived&issue=X with an empty archive: the drain effect and the
// unresolved-selection fallback both want to navigate. The fallback must
diff --git a/packages/views/inbox/components/inbox-page.tsx b/packages/views/inbox/components/inbox-page.tsx
index 5ecfbca05d..c2408ac2a7 100644
--- a/packages/views/inbox/components/inbox-page.tsx
+++ b/packages/views/inbox/components/inbox-page.tsx
@@ -56,7 +56,7 @@ import {
DropdownMenuItem,
DropdownMenuSeparator,
} from "@multica/ui/components/ui/dropdown-menu";
-import { useIsMobile } from "@multica/ui/hooks/use-mobile";
+import { useIsCompact } from "@multica/ui/hooks/use-mobile";
import { PageHeader } from "../../layout/page-header";
import { useTimeAgo } from "./inbox-list-item";
import { InboxList } from "./inbox-list";
@@ -202,7 +202,7 @@ export function InboxPage() {
id: "multica_inbox_layout",
});
- const isMobile = useIsMobile();
+ const isCompact = useIsCompact();
const unreadCount = useInboxUnreadCount(wsId);
const markReadMutation = useMarkInboxRead();
@@ -482,14 +482,14 @@ export function InboxPage() {
</>
);
- // Phone only: the detail fills the screen there, so the trip back to the list
- // has to live inside it. On desktop the list is still on screen in the left
- // panel and needs no back control at all.
+ // Compact widths only: the detail fills the screen there, so the trip back to
+ // the list has to live inside it. On desktop the list is still on screen in
+ // the left panel and needs no back control at all.
//
- // The detail owns the whole phone screen in four states — loaded, loading,
+ // The detail owns the whole compact screen in four states — loaded, loading,
// not-found and crashed — so this control is threaded into all four below.
// Miss one and that state strands the reader with no way out.
- const mobileBackAction = isMobile ? (
+ const compactBackAction = isCompact ? (
<Button
variant="ghost"
size="sm"
@@ -503,8 +503,8 @@ export function InboxPage() {
</Button>
) : undefined;
- const mobileBackBar = mobileBackAction ? (
- <div className="flex h-12 shrink-0 items-center gap-2 border-b px-4">{mobileBackAction}</div>
+ const compactBackBar = compactBackAction ? (
+ <div className="flex h-12 shrink-0 items-center gap-2 border-b px-4">{compactBackAction}</div>
) : null;
const detailContent = selected?.issue_id ? (
@@ -517,9 +517,9 @@ export function InboxPage() {
// The default fallback is a bare message card. On a phone it would be the
// only thing on screen, so it has to carry the way back too — the bar is
// the point here, the message is whatever the boundary caught.
- fallback={mobileBackAction ? ({ error }) => (
+ fallback={compactBackAction ? ({ error }) => (
<div className="flex flex-1 min-h-0 flex-col">
- {mobileBackBar}
+ {compactBackBar}
<div className="flex flex-1 min-h-0 items-center justify-center px-4 text-center text-body text-muted-foreground">
{error.message}
</div>
@@ -532,7 +532,7 @@ export function InboxPage() {
defaultSidebarOpen={false}
layoutId="multica_inbox_issue_detail_layout"
highlightCommentId={selected.details?.comment_id ?? undefined}
- leadingAction={mobileBackAction}
+ leadingAction={compactBackAction}
onDelete={() => {
// Issue deletion CASCADE-deletes the inbox item server-side, and the
// issue:deleted WS event prunes it from the inbox cache. Just clear
@@ -612,9 +612,9 @@ export function InboxPage() {
</div>
) : null;
- // -- Mobile layout: list / detail toggle -----------------------------------
+ // -- Compact layout: list / detail toggle -----------------------------------
- if (isMobile) {
+ if (isCompact) {
if (viewLoading) {
return (
<div className="flex flex-1 flex-col min-h-0">
@@ -636,7 +636,7 @@ export function InboxPage() {
);
}
- // Mobile: show detail full-screen when an item is selected. The two kinds
+ // Compact: show detail full-screen when an item is selected. The two kinds
// of selection get their chrome from different places, so they render
// differently — `InboxItem.issue_id` is nullable and a null one is a plain
// notification (a failed quick-create, say), not an issue.
@@ -657,13 +657,13 @@ export function InboxPage() {
// slot and no scroller of its own, so this branch keeps supplying both.
return (
<div className="flex flex-1 flex-col min-h-0">
- {mobileBackBar}
+ {compactBackBar}
<div className="flex-1 min-h-0 overflow-y-auto">{detailContent}</div>
</div>
);
}
- // Mobile: full-screen list
+ // Compact: full-screen list
return <div className="flex flex-1 flex-col min-h-0">{listPanel}</div>;
}
diff --git a/packages/views/layout/page-header.tsx b/packages/views/layout/page-header.tsx
index 663c83083d..1fecac1041 100644
--- a/packages/views/layout/page-header.tsx
+++ b/packages/views/layout/page-header.tsx
@@ -3,10 +3,19 @@
import { cn } from "@multica/ui/lib/utils";
import { SidebarTrigger, useSidebarSafe } from "@multica/ui/components/ui/sidebar";
-function MobileSidebarTrigger() {
+/**
+ * The way back to the nav wherever it is not a permanent column: a sheet below
+ * the compact breakpoint, auto-collapsed from there up to `xl`.
+ *
+ * Every surface below `xl` needs one of these. `PageHeader` supplies it for
+ * free, so this is exported for the pages that build their own chrome instead
+ * — without it a touch user has no way to reopen the nav at all. Renders
+ * nothing outside a `SidebarProvider` so such a page still stands alone.
+ */
+export function CollapsedNavTrigger() {
const sidebar = useSidebarSafe();
if (!sidebar) return null;
- return <SidebarTrigger className="mr-2 md:hidden" />;
+ return <SidebarTrigger className="mr-2 xl:hidden" />;
}
interface PageHeaderProps {
@@ -27,7 +36,7 @@ interface PageHeaderProps {
export function PageHeader({ children, leading, className }: PageHeaderProps) {
return (
<header className={cn("flex h-12 shrink-0 items-center border-b px-4", className)}>
- {leading ?? <MobileSidebarTrigger />}
+ {leading ?? <CollapsedNavTrigger />}
{children}
</header>
);
diff --git a/packages/views/layout/sidebar-auto-collapse.test.tsx b/packages/views/layout/sidebar-auto-collapse.test.tsx
new file mode 100644
index 0000000000..b928b436a9
--- /dev/null
+++ b/packages/views/layout/sidebar-auto-collapse.test.tsx
@@ -0,0 +1,173 @@
+import { act, fireEvent, screen } from "@testing-library/react";
+import { afterEach, beforeEach, describe, expect, it } from "vitest";
+
+import {
+ Sidebar,
+ SidebarProvider,
+ useSidebar,
+} from "@multica/ui/components/ui/sidebar";
+import { renderWithI18n } from "../test/i18n";
+
+// A width-driven `matchMedia`: the provider watches the `lg`–`xl` band and
+// `useIsCompact` watches `max-width: 1023px`, so both have to answer against
+// the same viewport and both have to be notified when it changes.
+type Listener = (e: MediaQueryListEvent) => void;
+
+let width = 1440;
+const queries = new Set<{ query: string; listeners: Set<Listener> }>();
+const realMatchMedia = window.matchMedia;
+
+function evaluate(query: string, viewport: number) {
+ const min = /min-width:\s*(\d+)px/.exec(query);
+ const max = /max-width:\s*(\d+)px/.exec(query);
+ if (min && viewport < Number(min[1])) return false;
+ if (max && viewport > Number(max[1])) return false;
+ return true;
+}
+
+function setWidth(next: number) {
+ width = next;
+ Object.defineProperty(window, "innerWidth", {
+ configurable: true,
+ value: next,
+ writable: true,
+ });
+ act(() => {
+ for (const entry of queries) {
+ const event = { matches: evaluate(entry.query, next) } as MediaQueryListEvent;
+ for (const listener of entry.listeners) listener(event);
+ }
+ });
+}
+
+function Probe() {
+ const { state, toggleSidebar } = useSidebar();
+ return (
+ <button type="button" data-testid="state" onClick={toggleSidebar}>
+ {state}
+ </button>
+ );
+}
+
+function state() {
+ return screen.getByTestId("state").textContent;
+}
+
+describe("sidebar auto-collapse between lg and xl", () => {
+ beforeEach(() => {
+ queries.clear();
+ window.matchMedia = ((query: string) => {
+ const entry = { query, listeners: new Set<Listener>() };
+ queries.add(entry);
+ return {
+ get matches() {
+ return evaluate(query, width);
+ },
+ media: query,
+ onchange: null,
+ addListener: () => {},
+ removeListener: () => {},
+ addEventListener: (_: string, listener: Listener) =>
+ entry.listeners.add(listener),
+ removeEventListener: (_: string, listener: Listener) =>
+ entry.listeners.delete(listener),
+ dispatchEvent: () => false,
+ } as unknown as MediaQueryList;
+ }) as typeof window.matchMedia;
+ setWidth(1440);
+ });
+
+ afterEach(() => {
+ window.matchMedia = realMatchMedia;
+ });
+
+ it("leaves the nav alone at desktop widths", () => {
+ renderWithI18n(
+ <SidebarProvider>
+ <Probe />
+ </SidebarProvider>,
+ );
+
+ expect(state()).toBe("expanded");
+ });
+
+ it("starts collapsed when the page opens inside the band", () => {
+ setWidth(1100);
+ renderWithI18n(
+ <SidebarProvider>
+ <Probe />
+ </SidebarProvider>,
+ );
+
+ expect(state()).toBe("collapsed");
+ });
+
+ it("collapses on the way in and restores on the way out", () => {
+ renderWithI18n(
+ <SidebarProvider>
+ <Probe />
+ </SidebarProvider>,
+ );
+
+ setWidth(1100);
+ expect(state()).toBe("collapsed");
+
+ setWidth(1440);
+ expect(state()).toBe("expanded");
+ });
+
+ it("keeps a manual re-open until the next crossing", () => {
+ // Automating the crossings must not mean fighting the user inside the
+ // band: once they bring the nav back it stays until the width changes
+ // bands again.
+ renderWithI18n(
+ <SidebarProvider>
+ <Probe />
+ </SidebarProvider>,
+ );
+
+ setWidth(1100);
+ fireEvent.click(screen.getByTestId("state"));
+ expect(state()).toBe("expanded");
+
+ setWidth(1200);
+ expect(state()).toBe("expanded");
+ });
+
+ it("gates the in-flow sidebar on the same breakpoint the hook uses", () => {
+ // `useIsCompact()` resolves after the first paint, so between the two
+ // breakpoints the CSS gate alone decides that frame. While it said `md`
+ // and the hook said `lg`, every load in 768–1023 painted a 256px sidebar
+ // before collapsing it into a sheet. jsdom applies no stylesheet, so the
+ // agreement is asserted on the class itself.
+ const { container } = renderWithI18n(
+ <SidebarProvider>
+ <Sidebar />
+ </SidebarProvider>,
+ );
+
+ const root = container.querySelector<HTMLElement>("[data-slot='sidebar']")!;
+ const inner = container.querySelector<HTMLElement>(
+ "[data-slot='sidebar-container']",
+ )!;
+
+ expect(root.className).toContain("lg:block");
+ expect(root.className).not.toContain("md:block");
+ expect(inner.className).toContain("lg:flex");
+ expect(inner.className).not.toContain("md:flex");
+ });
+
+ it("does not touch the collapsed state below the band", () => {
+ // Under 1024 the nav is a sheet, which has its own open state — the
+ // in-flow state must be left where the user last put it.
+ renderWithI18n(
+ <SidebarProvider>
+ <Probe />
+ </SidebarProvider>,
+ );
+
+ setWidth(851);
+
+ expect(state()).toBe("expanded");
+ });
+});
diff --git a/packages/views/settings/components/settings-page.test.tsx b/packages/views/settings/components/settings-page.test.tsx
new file mode 100644
index 0000000000..f35701faca
--- /dev/null
+++ b/packages/views/settings/components/settings-page.test.tsx
@@ -0,0 +1,107 @@
+import { fireEvent, screen } from "@testing-library/react";
+import { beforeEach, describe, expect, it, vi } from "vitest";
+
+import { SidebarProvider, useSidebar } from "@multica/ui/components/ui/sidebar";
+import { renderWithI18n } from "../../test/i18n";
+
+// This file tests the settings SHELL — the chrome around the tabs — so every
+// tab panel is stubbed out. Their contents have their own test files.
+const stub = vi.hoisted(
+ () => (name: string) => () => ({ [name]: () => <div>{name}</div> }),
+);
+vi.mock("./account-tab", stub("AccountTab"));
+vi.mock("./preferences-tab", stub("PreferencesTab"));
+vi.mock("./chat-tab", stub("ChatTab"));
+vi.mock("./issue-tab", stub("IssueTab"));
+vi.mock("./tokens-tab", stub("TokensTab"));
+vi.mock("./workspace-tab", stub("WorkspaceTab"));
+vi.mock("./members-tab", stub("MembersTab"));
+vi.mock("./repositories-tab", stub("RepositoriesTab"));
+vi.mock("./github-tab", stub("GitHubTab"));
+vi.mock("./integrations-tab", stub("IntegrationsTab"));
+vi.mock("./labs-tab", stub("LabsTab"));
+vi.mock("./notifications-tab", stub("NotificationsTab"));
+vi.mock("./labels-tab", stub("LabelsTab"));
+vi.mock("./properties-tab", stub("PropertiesTab"));
+vi.mock("./quick-actions-tab", stub("QuickActionsTab"));
+vi.mock("./keyboard-shortcuts-tab", stub("KeyboardShortcutsTab"));
+
+vi.mock("@multica/core/paths", () => ({
+ useCurrentWorkspace: () => ({ name: "Acme" }),
+}));
+
+const replace = vi.fn();
+vi.mock("../../navigation", () => ({
+ useNavigation: () => ({
+ searchParams: new URLSearchParams(),
+ pathname: "/acme/settings",
+ replace,
+ }),
+}));
+
+// Compact by default: that is the width where the nav is a sheet and this
+// trigger is the only way to reach it.
+const layout = { compact: true };
+vi.mock("@multica/ui/hooks/use-mobile", () => ({
+ useIsMobile: () => layout.compact,
+ useIsCompact: () => layout.compact,
+}));
+
+import { SettingsPage } from "./settings-page";
+
+function NavStateProbe() {
+ const { openMobile } = useSidebar();
+ return <div data-testid="nav-open">{String(openMobile)}</div>;
+}
+
+function trigger() {
+ return screen.getByRole("button", { name: "Toggle Sidebar" });
+}
+
+beforeEach(() => {
+ layout.compact = true;
+ replace.mockClear();
+});
+
+describe("SettingsPage nav trigger", () => {
+ it("opens the nav from settings at compact widths", () => {
+ // Settings builds its own chrome instead of a PageHeader, so without this
+ // control a touch user who lands here has no way back to the nav at all —
+ // the keyboard shortcut is not an answer on a tablet.
+ renderWithI18n(
+ <SidebarProvider>
+ <NavStateProbe />
+ <SettingsPage />
+ </SidebarProvider>,
+ );
+
+ expect(screen.getByTestId("nav-open").textContent).toBe("false");
+
+ fireEvent.click(trigger());
+
+ expect(screen.getByTestId("nav-open").textContent).toBe("true");
+ });
+
+ it("hides the trigger only where the nav is a permanent column", () => {
+ // The nav is in-flow from `xl` up, so the control is CSS-gated rather than
+ // unmounted — jsdom applies no stylesheet, hence the class assertion.
+ renderWithI18n(
+ <SidebarProvider>
+ <SettingsPage />
+ </SidebarProvider>,
+ );
+
+ expect(trigger().className).toContain("xl:hidden");
+ });
+
+ it("still renders standalone, without a sidebar around it", () => {
+ // Desktop mounts settings inside its own shell; the trigger has to no-op
+ // rather than throw when there is no SidebarProvider above it.
+ renderWithI18n(<SettingsPage />);
+
+ expect(
+ screen.queryByRole("button", { name: "Toggle Sidebar" }),
+ ).not.toBeInTheDocument();
+ expect(screen.getByText("Settings")).toBeInTheDocument();
+ });
+});
diff --git a/packages/views/settings/components/settings-page.tsx b/packages/views/settings/components/settings-page.tsx
index 1fa9020fc0..e9457bd333 100644
--- a/packages/views/settings/components/settings-page.tsx
+++ b/packages/views/settings/components/settings-page.tsx
@@ -38,6 +38,7 @@ import { LabelsTab } from "./labels-tab";
import { PropertiesTab } from "./properties-tab";
import { QuickActionsTab } from "./quick-actions-tab";
import { KeyboardShortcutsTab } from "./keyboard-shortcuts-tab";
+import { CollapsedNavTrigger } from "../../layout/page-header";
import { useT } from "../../i18n";
const ACCOUNT_TAB_KEYS = ["profile", "preferences", "shortcuts", "issue", "chat", "notifications", "tokens"] as const;
@@ -157,7 +158,13 @@ export function SettingsPage({ extraAccountTabs }: SettingsPageProps = {}) {
tab merges into the card top, and a tinted panel under the first tabs
breaks that seam (MUL-4439). Zoning comes from the divider instead. */}
<div className="shrink-0 overflow-x-auto border-b border-surface-border p-2 md:w-56 md:overflow-y-auto md:border-b-0 md:border-r md:p-4">
- <h1 className="sr-only text-body font-semibold md:not-sr-only md:mb-4 md:px-2">{t(($) => $.page.title)}</h1>
+ {/* This page builds its own chrome instead of a PageHeader, so it has
+ to supply the nav trigger itself — below `xl` the nav is a sheet or
+ auto-collapsed, and settings has no other way back to it. */}
+ <div className="flex items-center">
+ <CollapsedNavTrigger />
+ <h1 className="sr-only text-body font-semibold md:not-sr-only md:mb-4 md:px-2">{t(($) => $.page.title)}</h1>
+ </div>
<TabsList
variant="line"
className="flex w-max min-w-full flex-row items-center gap-1 p-0 md:w-full md:flex-col md:items-stretch"