diff --git a/app/src/components/app-sidebar/app-sidebar.tsx b/app/src/components/app-sidebar/app-sidebar.tsx index e0b9575aaf..3cde57e09e 100644 --- a/app/src/components/app-sidebar/app-sidebar.tsx +++ b/app/src/components/app-sidebar/app-sidebar.tsx @@ -13,9 +13,6 @@ export { isUnread, matchingChannels, pinnedFirst, - SEARCH_DEBOUNCE_MS, - SEARCH_HINT, - SEARCH_SCOPE, } from "./conversations-panel"; /** diff --git a/app/src/components/app-sidebar/bots-panel.tsx b/app/src/components/app-sidebar/bots-panel.tsx index 30460283aa..24758b3027 100644 --- a/app/src/components/app-sidebar/bots-panel.tsx +++ b/app/src/components/app-sidebar/bots-panel.tsx @@ -58,6 +58,7 @@ import { isWorking, NONE_DELEGATING, pinnedFirst, + workStatus, } from "./conversations-panel"; /** Where a Bot's row hands up that its conversations are held back, by Bot, for the panel to say once. */ @@ -172,6 +173,7 @@ function BotConversations({ {pinnedFirst(conversations.data).map((channel) => ( ) : null; /* - * While a Bot works on it, the row says so where its time goes, in the scheme's color for what is - * working: said as well as shown by the orb, and the time is news only once the work is done. + * The age is for the row a person is looking at, so with a mouse it waits for the pointer or the + * keyboard. A touch screen (`pointer-coarse`) and the sheet below 768px (`max-md`) have no hover, + * so there it shows at rest. Out of sight it stays readable to a screen reader (`sr-only`). + * + * While the Bot works, its status takes the age's place, muted like the age and always shown. The + * age is then only said, not drawn. */ - const time = busy ? ( - - Working - - ) : ( - + const statusText = status ?? (busy ? "Working" : undefined); + const time = statusText ? ( + <> + + {statusText} + + {lastMessageAt ? ( + + {lastMessageAt} + + ) : null} + + ) : lastMessageAt ? ( + {lastMessageAt} - ); + ) : null; const caret = revealing ? ( ) : null; diff --git a/app/src/components/app-sidebar/channel.tsx b/app/src/components/app-sidebar/channel.tsx index c1109c5b15..fcd6bfb0ce 100644 --- a/app/src/components/app-sidebar/channel.tsx +++ b/app/src/components/app-sidebar/channel.tsx @@ -42,6 +42,7 @@ export const Channel = memo(function Channel({ canRename, unread, busy, + status, emphasis, view = "detailed", avatar = true, @@ -60,6 +61,8 @@ export const Channel = memo(function Channel({ canRename: boolean; unread: boolean; busy: boolean; + /** What its Bot is doing while it works, said in place of its age. See `ChannelItemContent`. */ + status?: string; emphasis: MessageListEmphasis; /** One line or two: see `ChannelItemContent`. */ view?: ConversationView; @@ -108,7 +111,8 @@ export const Channel = memo(function Channel({ data-slot={slot} type="button" className={cn( - "flex flex-row px-2.5 gap-2 items-center w-full hover:bg-foreground/5 rounded-lg [content-visibility:auto]", + // `group/row`: with a mouse, the row's age shows while the pointer or the keyboard is on it. + "group/row flex flex-row px-2.5 gap-2 items-center w-full hover:bg-foreground/5 rounded-lg [content-visibility:auto]", view === "compact" ? "py-1.5 [contain-intrinsic-size:auto_2rem]" : "py-2 [contain-intrinsic-size:auto_3.25rem]", @@ -125,6 +129,7 @@ export const Channel = memo(function Channel({ lastMessageAt={lastMessageAt} emphasis={emphasis} busy={busy} + status={status} unread={unread} pinned={pinned} revealing={revealed.typing} diff --git a/app/src/components/app-sidebar/conversations-panel.tsx b/app/src/components/app-sidebar/conversations-panel.tsx index b8a9cce622..0efe55898a 100644 --- a/app/src/components/app-sidebar/conversations-panel.tsx +++ b/app/src/components/app-sidebar/conversations-panel.tsx @@ -6,16 +6,17 @@ import { import { useInfiniteQuery, useQuery } from "@tanstack/react-query"; import { Link, useParams } from "@tanstack/react-router"; import { AnimatePresence, motion, useReducedMotion } from "motion/react"; -import { useEffect, useLayoutEffect, useRef, useState } from "react"; +import { type ReactNode, useRef } from "react"; import { SectionPanel } from "@/components/layout/section-panel"; import { - InputGroup, - InputGroupAddon, - InputGroupInput, -} from "@/components/ui/input-group"; + COMMAND_MENU_KEYS, + HotkeyKeys, + openCommandMenu, +} from "@/components/navigation/command-menu"; import { SidebarContent, SidebarGroup, + SidebarGroupLabel, SidebarMenu, SidebarMenuButton, SidebarMenuItem, @@ -24,11 +25,7 @@ import { untitledLine } from "@/lib/channels/label"; import { type ChannelSummary, channelListQueryOptions, - channelSearchInfiniteQueryOptions, - isChannelSearchable, - normalizeChannelSearch, } from "@/lib/channels/queries"; -import { loadFailure } from "@/lib/load-failure"; import { EASE_OUT, ENTRANCE_SECONDS } from "@/lib/motion"; import { relativeTimeShort } from "@/lib/relative-time"; import { @@ -40,7 +37,6 @@ import { useMessageListEmphasis, } from "@/lib/settings/message-list"; import { delegatingConversationsQueryOptions } from "@/lib/tasks/queries"; -import { Button } from "../ui/button"; import { Empty, EmptyDescription, EmptyHeader, EmptyTitle } from "../ui/empty"; import { Channel } from "./channel"; import { ChannelPagination } from "./channel-pagination"; @@ -58,8 +54,9 @@ const MAX_ANIMATED_ROWS = 60; * cannot account for. The opening and the last message are included because one of them is what the * second line draws until the conversation has been named. * - * Only what is loaded. This sidebar asks the server instead (see `SearchResults`), which searches - * the whole history; the alternate skins' rosters still narrow their loaded rows with this. + * Only what is loaded. This sidebar has no box of its own: its Search row opens the command menu, + * which asks the server and searches the whole history. The alternate skins' rosters still narrow + * their loaded rows with this. * * An empty query returns the input array unchanged rather than a copy, so typing and clearing does * not hand `AnimatePresence` a new array identity and restage the whole list. @@ -82,26 +79,6 @@ export function matchingChannels( ); } -/** How long typing has to pause before the box is searched. */ -export const SEARCH_DEBOUNCE_MS = 250; - -/** What the search box searches, said where the person types. Not every word of every message. */ -export const SEARCH_SCOPE = "Search conversation names and recent messages"; -export const SEARCH_HINT = "Type at least 2 characters to search history"; - -/** - * `value`, once it has stopped changing for `delay`. Each search is a request, so one per pause in - * typing rather than one per keystroke. - */ -function useDebounced(value: string, delay: number): string { - const [debounced, setDebounced] = useState(value); - useEffect(() => { - const timer = setTimeout(() => setDebounced(value), delay); - return () => clearTimeout(timer); - }, [value, delay]); - return debounced; -} - /** * Pinned channels first, everything else after, newest activity first within each group. * @@ -148,6 +125,26 @@ export function isWorking( ); } +/** + * What a working conversation's row says in place of its age, from what the roster already knows: a turn + * running says Working, a Bot it asked and waits on is named, a routine firing into it says so, and + * work handed out to a task still under way says Working. Null while nothing is under way. + */ +export function workStatus( + channel: ChannelSummary, + delegating: readonly string[], +): string | null { + if (channel.busy) return "Working"; + const waiting = channel.work?.[0]; + if (waiting?.kind === "handoff") { + return waiting.botName + ? `Waiting on ${waiting.botName}` + : "Waiting on another Bot"; + } + if (waiting?.kind === "routine") return "Running a routine"; + return delegating.includes(channel.id) ? "Working" : null; +} + /** No conversation's work handed out and still working: the answer before the task list is read. */ export const NONE_DELEGATING: readonly string[] = []; @@ -216,127 +213,59 @@ function ChannelRow({ unread={unread} // A turn running, work the conversation waits on (a hop, a routine), or a task it handed out. busy={isWorking(channel, delegating)} + status={workStatus(channel, delegating) ?? undefined} /> ); } /** - * What the server found for the search box, a page at a time. - * - * The answer is for the text in the box or it is not shown: while the box is still settling, or the - * first page is on its way, this says it is searching. A list left over from what was typed a - * moment ago would answer a question nobody is asking any more, and an empty one would say there - * is nothing to find. A failure says so and offers Retry. It is never shown as no matches. - * - * FILTERING DOES NOT ANIMATE. The rows are drawn without the roster's order animation: results - * replace each other as somebody types, and a list that moves under them is the very thing they - * are trying to read. + * A group of the roster's rows under a small muted label, as Claude's sidebar lists Pinned and + * Recents. Each group animates its own rows: a pin moves a row from one group to the other. */ -function SearchResults({ - term, - settled, +function RosterGroup({ + label, + channels, + animateOrder, emphasis, view, delegating, + children, }: { - /** The search as it was when typing last paused, normalised. This is what is asked for. */ - term: string; - /** Whether that is still what is in the box. */ - settled: boolean; + label: string; + channels: ChannelSummary[]; + animateOrder: boolean; emphasis: MessageListEmphasis; view: ConversationView; delegating: readonly string[]; + children?: ReactNode; }) { - const results = useInfiniteQuery(channelSearchInfiniteQueryOptions(term)); - - if (!settled || results.isPending) { - return ( -

- Searching… -

- ); - } - if (!results.data) { - return ( -
-

- {loadFailure( - results.error, - results.error?.message || "Couldn't search your conversations.", - )} -

- -
- ); - } - if (results.data.length === 0) { - return ( -
- - - No conversations match your search - - {`No conversation has “${term}” in its name or recent messages.`} - - - -
- ); - } return ( - <> - {/* Mounted with its first rows, so they appear without the entrance a new channel gets. */} + + {label} - {results.data.map((channel) => ( + {channels.map((channel) => ( ))} - {results.hasNextPage ? ( -
- {results.isFetchNextPageError ? ( -

- {loadFailure(results.error, "Couldn't load more results.")} -

- ) : null} - -
- ) : null} - + {children} +
); } /** - * The Conversations section's panel: every conversation, pinned first and newest first after, with - * a search over the whole history and New conversation at the top. Today's roster, moved beside the - * strip and otherwise unchanged. + * The Conversations section's panel. + * + * At the top, three rows with words on them: New conversation and its shortcut, Search and its + * shortcut, and Artifacts. Search opens the command menu, which searches every conversation on the + * server. Under them the conversations, pinned under Pinned, the rest newest first under Recents. */ export function ConversationsPanel({ hidden = false }: { hidden?: boolean }) { const emphasis = useMessageListEmphasis(); @@ -344,34 +273,12 @@ export function ConversationsPanel({ hidden = false }: { hidden?: boolean }) { const channels = useInfiniteQuery(channelListQueryOptions()); const delegating = useQuery(delegatingConversationsQueryOptions()).data ?? NONE_DELEGATING; - const [search, setSearch] = useState(""); - const debouncedSearch = useDebounced(search, SEARCH_DEBOUNCE_MS); const scrollRoot = useRef(null); - const term = normalizeChannelSearch(search); - const debouncedTerm = normalizeChannelSearch(debouncedSearch); - const searching = term.length > 0; - const searchable = isChannelSearchable(term); - /* - * WHILE SEARCHING, THE ROSTER IS NOT ON SCREEN. Its rows and its pagination unmount, so nothing - * pages through recent history looking for a match: the server searches all of it. Clearing the - * box puts the roster back as it was, scrolled where it was. - */ - const rosterScroll = useRef(null); - const changeSearch = (value: string) => { - if (!searching && normalizeChannelSearch(value)) { - rosterScroll.current = scrollRoot.current?.scrollTop ?? 0; - } - setSearch(value); - }; - useLayoutEffect(() => { - if (searching || rosterScroll.current === null || !scrollRoot.current) { - return; - } - scrollRoot.current.scrollTop = rosterScroll.current; - rosterScroll.current = null; - }, [searching]); const visibleChannels = pinnedFirst(channels.data ?? []); + const pinned = visibleChannels.filter((channel) => channel.pinned); + const recents = visibleChannels.filter((channel) => !channel.pinned); const animateOrder = (channels.data?.length ?? 0) <= MAX_ANIMATED_ROWS; + const rows = { animateOrder, emphasis, view, delegating }; return (