diff --git a/apps/desktop/src/settings/DesktopClientSettings.test.ts b/apps/desktop/src/settings/DesktopClientSettings.test.ts index e785543b6..a5c7acded 100644 --- a/apps/desktop/src/settings/DesktopClientSettings.test.ts +++ b/apps/desktop/src/settings/DesktopClientSettings.test.ts @@ -45,6 +45,7 @@ const clientSettings: ClientSettings = { providerModelPreferences: {}, suppressCrossProviderSwitchWarning: false, sidebarGrouping: "none", + generalChatsPlacement: "page", inboxSort: "recent", inboxCustomOrder: [], inboxGroupOrder: [], diff --git a/apps/server/src/guide/topics.ts b/apps/server/src/guide/topics.ts index abbeb68e3..aa1180b99 100644 --- a/apps/server/src/guide/topics.ts +++ b/apps/server/src/guide/topics.ts @@ -42,6 +42,7 @@ export const GUIDE_TOPICS: ReadonlyArray = [ "wrap", "archive", "restart", + "general chats", ], body: `A thread is one conversation with an agent in a project. Threads are listed in the sidebar; one that needs you, finished or failed says so there. In a narrow window the sidebar floats over the thread instead of sitting beside it: the sidebar button at the top left, or Cmd+B (Ctrl+B on Windows and Linux), opens it, and picking a thread or clicking the thread puts it away. A thread you scrolled up in opens where you left it when you come back, until Threadlines reloads; one that finished, failed or needs you since then opens at the end. @@ -63,6 +64,8 @@ When Claude or Codex asks multiple-choice questions, a card takes the place of t When a thread is done it wraps up and moves to the Wrapped shelf at the bottom of the sidebar; {place:threads.whenDone} says when that happens on its own. An agent coming back later (a check-back) doesn't keep a thread out of Wrapped: the thread returns to the list when the agent does. Old threads can be archived for you: {place:archived.cleanup}. +General Chats are chats with an agent that aren't tied to a project. By default they have their own page in the left bar, with a New chat button over the list. With {place:threads.generalChats} set to Section in Threads, that button leaves the left bar and the chats sit in a General chats section at the bottom of the thread list, under Wrapped: its header opens and closes it and has its own New chat button, and the Threads button counts what the chats need and are doing. Old General Chats links then open Threads with the section open. Each device keeps its own choice. + When Threadlines quits, updates or crashes while an agent works on something the user asked for, the agent picks it back up when Threadlines starts again: the chat gets a message marked "Sent after a restart" telling the agent to check before repeating anything. A turn waiting on an approval or a question, or one another thread, a scheduled task or an outside agent started, stops with a note instead, as does a turn restarts cut off three times in five minutes. {place:threads.continueAfterRestart} turns this off.`, }, { diff --git a/apps/web/src/components/AppSidebarLayout.tsx b/apps/web/src/components/AppSidebarLayout.tsx index 21aeda9c9..c8f9f695d 100644 --- a/apps/web/src/components/AppSidebarLayout.tsx +++ b/apps/web/src/components/AppSidebarLayout.tsx @@ -16,6 +16,7 @@ import { useAppHistory } from "../appHistory"; import { useCommandPaletteStore } from "../commandPaletteStore"; import { isKnownEnvironment } from "../environments/runtime"; import { useHandleNewThread } from "../hooks/useHandleNewThread"; +import { getClientSettings } from "../hooks/useSettings"; import { resolveShortcutCommand } from "../keybindings"; import { startNewThreadFromContext } from "../lib/chatThreadActions"; import { isTerminalFocused } from "../lib/terminalFocus"; @@ -26,6 +27,12 @@ import { selectThreadTerminalState, useTerminalStateStore } from "../terminalSta import { buildThreadRouteParams } from "../threadRoutes"; import { selectSidebarListShown, useUiStateStore } from "../uiStateStore"; import ThreadSidebar from "./Sidebar"; +import { + consumeSidebarListReveal, + requestGeneralChatsReveal, + useGeneralChatsInThreads, +} from "./chats/generalChatsPlacement"; +import { GeneralChatsRevealer } from "./chats/GeneralChatsRevealer"; import { AppTitleBar } from "./sidebar/AppTitleBar"; import { TitleBarSlotContext } from "./sidebar/titleBarSlot"; import { destinationHasList } from "./sidebar/destinationLists"; @@ -144,7 +151,9 @@ function AppShellCommands({ hasList }: { readonly hasList: boolean }) { void navigate({ to: "/terminals" }); return; case "open-general-chats": - void navigate({ to: "/chats" }); + // Read when the item fires; the menu subscription stays put. + if (getClientSettings().generalChatsPlacement === "threads") requestGeneralChatsReveal(); + else void navigate({ to: "/chats" }); return; case "open-usage": void navigate({ to: "/usage" }); @@ -295,18 +304,22 @@ export function AppSidebarLayout({ children }: { children: ReactNode }) { const listFloats = useUiStateStore((store) => store.sidebarListFloats); const setSidebarListShown = useUiStateStore((store) => store.setSidebarListShown); const selectedDestination = useSelectedDestination(); + const generalChatsInThreads = useGeneralChatsInThreads(); const hasList = destinationHasList(selectedDestination); const isMobile = useIsMobile(); const panelRef = useRef(null); useSidebarListFloats(panelRef, isMobile); - // A floating list gets out of the way of whatever page opens next. + // A floating list gets out of the way of whatever page opens next, unless + // the change was asked to show it (opening the chats' section in Threads, + // GeneralChatsRevealer). const pathname = useLocation({ select: (location) => location.pathname }); const shownPathname = useRef(pathname); useEffect(() => { if (shownPathname.current === pathname) return; shownPathname.current = pathname; const state = useUiStateStore.getState(); - if (state.sidebarListFloats) state.setSidebarListShown(false); + if (consumeSidebarListReveal(pathname)) state.setSidebarListShown(true); + else if (state.sidebarListFloats) state.setSidebarListShown(false); }, [pathname]); usePageCrossFade(panelRef, selectedDestination); // Dialogs and other window-wide layers center over the page beside the list. @@ -354,6 +367,7 @@ export function AppSidebarLayout({ children }: { children: ReactNode }) { style={sidebarStyle} > + {generalChatsInThreads ? : null}
diff --git a/apps/web/src/components/ChatView.browser-harness.tsx b/apps/web/src/components/ChatView.browser-harness.tsx index 873b8a49c..1a3ce7310 100644 --- a/apps/web/src/components/ChatView.browser-harness.tsx +++ b/apps/web/src/components/ChatView.browser-harness.tsx @@ -3482,6 +3482,7 @@ export function registerChatViewSuiteHooks(): void { inboxProjectScopeKeys: [], collapsedInboxGroups: {}, inboxWrappedOpen: false, + inboxGeneralChatsOpen: true, sidebarListOpen: true, }); useTerminalStateStore.persist.clearStorage(); diff --git a/apps/web/src/components/ChatView.shell.browser.tsx b/apps/web/src/components/ChatView.shell.browser.tsx index 6b331c58b..32288a61a 100644 --- a/apps/web/src/components/ChatView.shell.browser.tsx +++ b/apps/web/src/components/ChatView.shell.browser.tsx @@ -15,6 +15,9 @@ import * as Effect from "effect/Effect"; import { page, userEvent } from "vite-plus/test/browser"; import { describe, expect, it, vi } from "vite-plus/test"; +import { DEFAULT_CLIENT_SETTINGS } from "@threadlines/contracts/settings"; + +import { CLIENT_SETTINGS_STORAGE_KEY } from "../clientPersistenceStorage"; import { useComposerDraftStore } from "../composerDraftStore"; import { isMacPlatform } from "../lib/utils"; import { useOptimisticThreadMessagesStore } from "../optimisticThreadMessages"; @@ -1091,6 +1094,90 @@ describe("ChatView (full app): app shell", () => { } }); + it("shows a floating list with the chats' section open when the old General Chats address leads to Threads", async () => { + localStorage.setItem( + CLIENT_SETTINGS_STORAGE_KEY, + JSON.stringify({ ...DEFAULT_CLIENT_SETTINGS, generalChatsPlacement: "threads" }), + ); + useUiStateStore.setState({ inboxGeneralChatsOpen: false }); + const mounted = await mountChatView({ + viewport: { ...DEFAULT_VIEWPORT, name: "list-floats-chats", width: 800 }, + snapshot: createSnapshotForTargetUser({ + targetMessageId: "msg-user-list-floats-chats" as MessageId, + targetText: "list floats chats", + }), + }); + + try { + const list = await waitForElement( + () => + document.querySelector('[data-testid="app-panel"] > [data-slot="sidebar"]'), + "Unable to find the list beside the rail.", + ); + await vi.waitFor(() => expect(list.dataset.state).toBe("collapsed")); + const threadPath = mounted.router.state.location.pathname; + // From another page, as the command palette or the desktop menu would go. + await mounted.router.navigate({ to: "/fleet" }); + await waitForURL(mounted.router, (pathname) => pathname === "/fleet", "Fleet should open."); + await mounted.router.navigate({ to: "/chats" }); + await waitForURL( + mounted.router, + (pathname) => pathname === threadPath, + "The old General Chats address should go where the Threads button does.", + ); + // Both page changes (to the old address, then on to Threads) leave it showing. + await nextFrames(5); + expect(list.dataset.state).toBe("expanded"); + await expect + .element(page.getByTestId("inbox-chats-toggle")) + .toHaveAttribute("aria-expanded", "true"); + // The next page change puts the floating list away as usual. + await mounted.router.navigate({ to: "/fleet" }); + await vi.waitFor(() => expect(list.dataset.state).toBe("collapsed")); + } finally { + localStorage.removeItem(CLIENT_SETTINGS_STORAGE_KEY); + await mounted.cleanup(); + } + }); + + it("keeps a floating list showing when the app opens on the old General Chats address", async () => { + localStorage.setItem( + CLIENT_SETTINGS_STORAGE_KEY, + JSON.stringify({ ...DEFAULT_CLIENT_SETTINGS, generalChatsPlacement: "threads" }), + ); + useUiStateStore.setState({ inboxGeneralChatsOpen: false }); + const mounted = await mountChatView({ + viewport: { ...DEFAULT_VIEWPORT, name: "list-floats-chats-launch", width: 800 }, + initialPath: "/chats", + snapshot: createSnapshotForTargetUser({ + targetMessageId: "msg-user-list-floats-chats-launch" as MessageId, + targetText: "list floats chats launch", + }), + }); + + try { + // Home, then on to where the launch lands: the list stays out through both. + await waitForURL( + mounted.router, + (pathname) => pathname !== "/chats" && pathname !== "/", + "The launch should land in work.", + ); + const list = await waitForElement( + () => + document.querySelector('[data-testid="app-panel"] > [data-slot="sidebar"]'), + "Unable to find the list beside the rail.", + ); + await nextFrames(5); + expect(list.dataset.state).toBe("expanded"); + await expect + .element(page.getByTestId("inbox-chats-toggle")) + .toHaveAttribute("aria-expanded", "true"); + } finally { + localStorage.removeItem(CLIENT_SETTINGS_STORAGE_KEY); + await mounted.cleanup(); + } + }); + it("folds the app's name away, then gives the thread's header its own row, as the title row runs out of room", async () => { const root = document.documentElement; root.classList.add("electron", "wco"); @@ -1769,7 +1856,14 @@ describe("ChatView (full app): app shell", () => { // A finger can't hover for the tooltip: each icon says its name. await expect .element(page.getByTestId("sidebar-destination-row")) - .toMatchTextContent(/Threads.*Chats.*Settings/); + .toMatchTextContent(/Threads.*Chats.*Shells.*Settings/); + // Every destination fits the phone's width, Settings last. + const row = document.querySelector('[data-testid="sidebar-destination-row"]')!; + expect(row.scrollWidth).toBeLessThanOrEqual(row.clientWidth); + const settingsButton = row.querySelector('[data-testid="rail-settings"]')!; + expect(settingsButton.getBoundingClientRect().right).toBeLessThanOrEqual( + row.getBoundingClientRect().right, + ); // The page shows a thumb's width beside the sheet: a strip to tap it shut. const sheet = document.querySelector( '[data-slot="sidebar"][data-mobile="true"]', @@ -1795,6 +1889,76 @@ describe("ChatView (full app): app shell", () => { } }); + it("on a phone with the chats in Threads, opens the sheet on them from the old page's address", async () => { + const chatId = "thread-phone-chat-section" as ThreadId; + const base = addThreadToSnapshot( + createSnapshotForTargetUser({ + targetMessageId: "msg-user-phone-chat-section" as MessageId, + targetText: "phone chat section", + }), + chatId, + ); + localStorage.setItem( + CLIENT_SETTINGS_STORAGE_KEY, + JSON.stringify({ ...DEFAULT_CLIENT_SETTINGS, generalChatsPlacement: "threads" }), + ); + useUiStateStore.setState({ inboxGeneralChatsOpen: false }); + const mounted = await mountChatView({ + viewport: PHONE_VIEWPORT, + snapshot: { + ...base, + projects: [ + ...base.projects, + { + id: GENERAL_CHATS_PROJECT_ID, + kind: "general-chat" as const, + title: "General Chats", + workspaceRoot: "/repo/general-chats", + defaultModelSelection: null, + scripts: [], + createdAt: NOW_ISO, + updatedAt: NOW_ISO, + deletedAt: null, + }, + ], + threads: base.threads.map((thread) => + thread.id === chatId + ? { ...thread, projectId: GENERAL_CHATS_PROJECT_ID, title: "Pocket question" } + : thread, + ), + }, + }); + + try { + await mounted.router.navigate({ to: "/chats" }); + await waitForURL( + mounted.router, + (pathname) => pathname !== "/chats", + "The old General Chats address should open Threads.", + ); + // The sheet opens on the thread list, with no Chats icon and the section open. + await expect + .element(page.getByTestId("sidebar-destination-row")) + .toMatchTextContent(/Threads.*Settings/); + expect(document.querySelector('[data-testid="rail-chats"]')).toBeNull(); + await expect + .element(page.getByTestId("inbox-chats-toggle")) + .toHaveAttribute("aria-expanded", "true"); + await expect.element(page.getByTestId(`thread-row-${THREAD_ID}`)).toBeVisible(); + + await page.getByTestId("chats-list-row").filter({ hasText: "Pocket question" }).click(); + await waitForURL( + mounted.router, + (pathname) => pathname.endsWith(`/${chatId}`), + "A chat in the sheet should open that chat.", + ); + await expect.element(page.getByTestId("sidebar-destination-row")).not.toBeInTheDocument(); + } finally { + localStorage.removeItem(CLIENT_SETTINGS_STORAGE_KEY); + await mounted.cleanup(); + } + }); + it("navigates phone settings through the full-page section index", async () => { const mounted = await mountChatView({ viewport: PHONE_VIEWPORT, diff --git a/apps/web/src/components/ChatView.sidebar.browser.tsx b/apps/web/src/components/ChatView.sidebar.browser.tsx index f6aaf4ee7..8dd8072b6 100644 --- a/apps/web/src/components/ChatView.sidebar.browser.tsx +++ b/apps/web/src/components/ChatView.sidebar.browser.tsx @@ -1116,6 +1116,187 @@ describe("ChatView (full app): sidebar", () => { } }); + it("lists general chats in a section of Threads when set to, opens it from the old page's address, and switching back restores the page", async () => { + const workingChatId = "thread-general-chat-section-working" as ThreadId; + const askingChatId = "thread-general-chat-section-asking" as ThreadId; + const withChats = addThreadToSnapshot( + addThreadToSnapshot( + createSnapshotForTargetUser({ + targetMessageId: "msg-user-general-chat-section" as MessageId, + targetText: "general chat section target", + }), + workingChatId, + ), + askingChatId, + ); + localStorage.setItem( + CLIENT_SETTINGS_STORAGE_KEY, + JSON.stringify({ ...DEFAULT_CLIENT_SETTINGS, generalChatsPlacement: "threads" }), + ); + const mounted = await mountChatView({ + viewport: DEFAULT_VIEWPORT, + snapshot: { + ...withChats, + projects: [ + ...withChats.projects, + { + id: GENERAL_CHATS_PROJECT_ID, + kind: "general-chat" as const, + title: "General Chats", + workspaceRoot: "/repo/general-chats", + defaultModelSelection: null, + scripts: [], + createdAt: NOW_ISO, + updatedAt: NOW_ISO, + deletedAt: null, + }, + ], + threads: withChats.threads.map((thread) => + thread.id === workingChatId + ? { + ...thread, + projectId: GENERAL_CHATS_PROJECT_ID, + title: "Best way to store passkeys", + } + : thread.id === askingChatId + ? { ...thread, projectId: GENERAL_CHATS_PROJECT_ID, title: "Draft reply" } + : thread, + ), + }, + configureFixture: (nextFixture) => { + nextFixture.serverConfig = { + ...nextFixture.serverConfig, + keybindings: [ + { + command: "thread.next", + shortcut: { + key: "]", + metaKey: false, + ctrlKey: false, + shiftKey: true, + altKey: false, + modKey: true, + }, + whenAst: { type: "not", node: { type: "identifier", name: "terminalFocus" } }, + }, + ], + }; + }, + }); + const useMetaForMod = isMacPlatform(navigator.platform); + const pressNext = () => + window.dispatchEvent( + new KeyboardEvent("keydown", { + key: "}", + code: "BracketRight", + shiftKey: true, + metaKey: useMetaForMod, + ctrlKey: !useMetaForMod, + bubbles: true, + cancelable: true, + }), + ); + + try { + const projectThreadPath = mounted.router.state.location.pathname; + setSidebarThreadWork(LOCAL_ENVIRONMENT_ID, workingChatId, "working"); + setSidebarThreadWork(LOCAL_ENVIRONMENT_ID, askingChatId, "needs-you"); + // No General Chats button: Threads carries what the chats need. + const threadsButton = page.getByTestId("rail-threads"); + await expect + .element(threadsButton.getByTestId("rail-needs-you-badge")) + .toMatchTextContent("1"); + expect(document.querySelector('[data-testid="rail-chats"]')).toBeNull(); + + // The chats sit open at the foot of the thread list, beside the project's threads. + const toggle = page.getByTestId("inbox-chats-toggle"); + await expect.element(toggle).toHaveAttribute("aria-expanded", "true"); + await expect.element(page.getByTestId(`thread-row-${THREAD_ID}`)).toBeVisible(); + await expect + .element( + page + .getByTestId("chats-list-row") + .filter({ hasText: "Best way to store passkeys" }) + .getByTestId("chats-list-row-status"), + ) + .toMatchTextContent(/^working/); + await expect.element(page.getByTestId("inbox-chats-new-chat")).toBeVisible(); + + // Folded, the header says what the hidden chats are doing. + await toggle.click(); + await expect.element(toggle).toHaveAttribute("aria-expanded", "false"); + expect(document.querySelector('[data-testid="chats-list-row"]')).toBeNull(); + await expect + .element(page.getByTestId("inbox-chats-folded")) + .toMatchTextContent(/1 needs you.*1 working/); + // Starting a chat needs no unfolding. + await expect.element(page.getByTestId("inbox-chats-new-chat")).toBeVisible(); + + // The palette opens the section where the user is, adding no step to Back. + const historyLength = window.history.length; + await openCommandPaletteFromTrigger(); + await page + .getByTestId("command-palette") + .getByText("Open general chats", { exact: true }) + .click(); + await expect.element(toggle).toHaveAttribute("aria-expanded", "true"); + expect(mounted.router.state.location.pathname).toBe(projectThreadPath); + expect(window.history.length).toBe(historyLength); + await toggle.click(); + await expect.element(toggle).toHaveAttribute("aria-expanded", "false"); + + // The old page's address opens Threads with the section open. + await mounted.router.navigate({ to: "/chats" }); + await waitForURL( + mounted.router, + (pathname) => pathname !== "/chats", + "The old General Chats address should open Threads.", + ); + await expect.element(toggle).toHaveAttribute("aria-expanded", "true"); + await expect.element(threadsButton).toHaveAttribute("aria-current", "page"); + + // Next walks the list as it reads: from the last project thread into the chats. + pressNext(); + await waitForURL( + mounted.router, + (pathname) => + pathname.endsWith(`/${workingChatId}`) || pathname.endsWith(`/${askingChatId}`), + "Next should step from the project's thread into the open section.", + ); + + await page.getByTestId("chats-list-row").filter({ hasText: "Draft reply" }).click(); + await waitForURL( + mounted.router, + (pathname) => pathname.endsWith(`/${askingChatId}`), + "A chat row should open its chat.", + ); + // A chat is part of Threads here. + await expect.element(threadsButton).toHaveAttribute("aria-current", "page"); + await expect + .element(page.getByTestId("chats-list-row").filter({ hasText: "Draft reply" })) + .toHaveAttribute("aria-current", "page"); + + // Back to its own page: the button returns, selected for the open chat, + // and the section leaves the thread list. + updateSettings({ generalChatsPlacement: "page" }); + await expect.element(page.getByTestId("rail-chats")).toHaveAttribute("aria-current", "page"); + await expect.element(page.getByTestId("inbox-chats-shelf")).not.toBeInTheDocument(); + await expect + .element(page.getByTestId("chats-list-row").filter({ hasText: "Draft reply" })) + .toHaveAttribute("aria-current", "page"); + // Threads goes back to project work, not to the chat opened from it. + await threadsButton.click(); + await waitForURL( + mounted.router, + (pathname) => pathname === projectThreadPath, + "Threads should return to the last project thread once the chats have their page.", + ); + } finally { + localStorage.removeItem(CLIENT_SETTINGS_STORAGE_KEY); + await mounted.cleanup(); + } + }); + it("swipes a general chat: left archives it with an undo, right pins it, and a working chat keeps it", async () => { const idleChatId = "thread-general-chat-swipe-idle" as ThreadId; const workingChatId = "thread-general-chat-swipe-working" as ThreadId; diff --git a/apps/web/src/components/CommandPaletteDialog.tsx b/apps/web/src/components/CommandPaletteDialog.tsx index 3fcfe4839..41d076a1e 100644 --- a/apps/web/src/components/CommandPaletteDialog.tsx +++ b/apps/web/src/components/CommandPaletteDialog.tsx @@ -46,6 +46,7 @@ import { LaptopIcon, LinkIcon, MessageSquareIcon, + MessageCirclePlusIcon, MessagesSquareIcon, PanelLeftCloseIcon, PanelLeftIcon, @@ -102,6 +103,8 @@ import { } from "../environments/runtime"; import { holdThreadDetailForOpen, prewarmHighlightedThread } from "../environments/runtime/service"; import { useHandleNewThread } from "../hooks/useHandleNewThread"; +import { useGeneralChats } from "./chats/useGeneralChats"; +import { requestGeneralChatsReveal } from "./chats/generalChatsPlacement"; import { useInboxThreads } from "../hooks/useInboxThreads"; import { useThreadMenu } from "../hooks/useThreadMenu"; import { @@ -583,6 +586,7 @@ export function OpenCommandPaletteDialog() { ); const projects = useStore(useShallow(selectProjectsAcrossEnvironments)); const threads = useStore(useShallow(selectSidebarThreadsAcrossEnvironments)); + const { startChat: startGeneralChat } = useGeneralChats(); const keybindings = useServerKeybindings(); const isHomeRoute = useLocation({ select: (location) => location.pathname === "/" }); const onTerminalsPage = useLocation({ @@ -1824,6 +1828,19 @@ export function OpenCommandPaletteDialog() { }); } + if (startGeneralChat !== null) { + actionItems.push({ + kind: "action", + value: "action:new-general-chat", + searchTerms: ["new chat", "general chat", "chat", "conversation", "no project"], + title: "New general chat", + icon: , + run: async () => { + startGeneralChat(); + }, + }); + } + actionItems.push({ kind: "action", value: "action:general-chats", @@ -1831,7 +1848,10 @@ export function OpenCommandPaletteDialog() { title: "Open general chats", icon: , run: async () => { - await navigate({ to: "/chats" }); + // Where the chats are a section of Threads, the shell opens it there + // without a stop at the old page's address. + if (settings.generalChatsPlacement === "threads") requestGeneralChatsReveal(); + else await navigate({ to: "/chats" }); }, }); diff --git a/apps/web/src/components/Sidebar.tsx b/apps/web/src/components/Sidebar.tsx index 4e9633292..f038c2c90 100644 --- a/apps/web/src/components/Sidebar.tsx +++ b/apps/web/src/components/Sidebar.tsx @@ -165,9 +165,12 @@ import { ThreadHoverCardProvider } from "./sidebar/ThreadHoverCard"; import { resolveThreadActionProjectRef, startNewGeneralChatThread } from "../lib/chatThreadActions"; import { SidebarDestinationRow, useSelectedDestination } from "./sidebar/NavigationRail"; import { AppWordmark } from "./sidebar/AppWordmark"; +import { InboxShelfHeader } from "./sidebar/InboxShelfHeader"; import { resolveShownDestinationList } from "./sidebar/destinationLists"; import { useListNewThreadStore } from "./sidebar/listNewThreadStore"; import { useGeneralChats } from "./chats/useGeneralChats"; +import { useGeneralChatsInThreads } from "./chats/generalChatsPlacement"; +import { lazyWithPreload } from "../lib/lazyWithPreload"; import { AttentionCounts } from "./sidebar/AttentionCounts"; import { ProjectFavicon } from "./ProjectFavicon"; import { isRoom } from "../rooms"; @@ -343,7 +346,8 @@ function inboxLiveGroupKey( * chat): a section's name, its count, how many wrapped today, then a hairline * running out to the chevron. The whole line is the control. Open, it rises * with its own scroll: as tall as its rows, and no taller than leaves the - * live list room for all of its rows or half the column, whichever is more. + * live list room for all of its rows or half the column, whichever is more + * (the column less the General chats section under it, when that is there). * The live list above keeps its place and scrolls in what is left. */ function InboxWrappedShelf({ @@ -351,6 +355,7 @@ function InboxWrappedShelf({ count, todayCount, liveContentHeight, + chatsShelfPx, shelfRef, onToggle, foldLine, @@ -361,6 +366,8 @@ function InboxWrappedShelf({ todayCount: number; /** See InboxColumnLayout.liveContentHeight. */ liveContentHeight: number | null; + /** See InboxColumnLayout.chatsShelfPx: the room under the shelf it doesn't share. */ + chatsShelfPx: number; shelfRef: (element: HTMLElement | null) => void; onToggle: () => void; /** The "Show N more…" line under the rows; open only. */ @@ -378,43 +385,31 @@ function InboxWrappedShelf({ ? { maxHeight: liveContentHeight === null - ? "50%" - : `max(50%, calc(100% - ${liveContentHeight}px))`, + ? `calc((100% - ${chatsShelfPx}px) / 2)` + : `max(calc((100% - ${chatsShelfPx}px) / 2), calc(100% - ${chatsShelfPx + liveContentHeight}px))`, } : undefined } > - + 0 ? ( + + · {todayCount} today + + ) : null + } + /> {open ? ( {children} @@ -427,6 +422,20 @@ function InboxWrappedShelf({ ); } +/** + * The General chats section, a chunk of its own: only a device that lists + * the chats in Threads fetches it. + */ +const GeneralChatsShelf = lazyWithPreload(() => + import("./chats/GeneralChatsShelf").then((module) => module.GeneralChatsShelf), +); + +/** + * The open General chats section's cap: about a third of the column, so the + * live list keeps most of it even with Wrapped open too. + */ +const GENERAL_CHATS_SHELF_MAX_HEIGHT = "35%"; + /** A day's label over the first of its rows in the open Wrapped shelf. */ function InboxWrappedDayLabel({ group }: { group: WrappedDayGroup }) { return ( @@ -673,10 +682,13 @@ export default function Sidebar() { remoteChildRowPx, groupHeaderPx, doneRowPx, + chatsShelfPx, columnRef: inboxColumnRef, liveContentRef: inboxLiveContentRef, shelfRef: wrappedShelfRef, + chatsShelfRef, } = useInboxColumnLayout(); + const generalChatsInThreads = useGeneralChatsInThreads(); const todayStartMs = useLocalDayStartMs(); const renamingCommittedRef = useRef(false); const renamingInputRef = useRef(null); @@ -1504,8 +1516,13 @@ export default function Sidebar() { const orderedThreadKeys = useKept(orderedThreadKeysNow, shallow); // The general chats in the General Chats list's order. They never join the // inbox, so while one is open previous/next walk these instead: chat to - // chat, the way the list shows them. - const { chats: generalChats } = useGeneralChats(); + // chat, the way the list shows them. Where the chats are an open section + // at the foot of this list, previous/next walk the whole list top to + // bottom, chats last, as it reads. + const { chats: generalChats } = useGeneralChats( + generalChatsInThreads ? { environmentId: scopedEnvironmentIdValue } : undefined, + ); + const generalChatsSectionOpen = useUiStateStore((store) => store.inboxGeneralChatsOpen); const generalChatThreadKeys = useMemo( () => generalChats.map((thread) => @@ -1513,10 +1530,16 @@ export default function Sidebar() { ), [generalChats], ); + const listedTraversalKeys = useMemo( + () => [...orderedThreadKeys, ...generalChatThreadKeys], + [generalChatThreadKeys, orderedThreadKeys], + ); const traversalThreadKeys = - routeThreadKey !== null && generalChatThreadKeys.includes(routeThreadKey) - ? generalChatThreadKeys - : orderedThreadKeys; + generalChatsInThreads && generalChatsSectionOpen + ? listedTraversalKeys + : routeThreadKey !== null && generalChatThreadKeys.includes(routeThreadKey) + ? generalChatThreadKeys + : orderedThreadKeys; const navigateToThread = useCallback( (threadRef: ScopedThreadRef) => { @@ -2046,7 +2069,8 @@ export default function Sidebar() { {isMobile ? : null} {PageListBody !== null ? ( - // A page with a list of its own (General chats, Computers, Settings) + // A page with a list of its own (General chats unless they are a + // section of Threads, Computers, Settings) // on a wide screen; on a phone, only one whose list is in the sheet. <> {/* Holds the list's place while its code loads, so the footer stays put. */} @@ -2396,7 +2420,7 @@ export default function Sidebar() {
) : null} - {wrappedRows.length > 0 ? ( + {wrappedRows.length > 0 || generalChatsInThreads ? (