From 728c900bb29006782ccea7cd1df759d13243524d Mon Sep 17 00:00:00 2001 From: Moepchi Date: Sat, 3 Oct 2026 00:53:06 +0000 Subject: [PATCH] feat: search channels and users in the tree A search field above the channel tree filters it live: a channel whose name matches keeps all of its clients, a client whose name matches keeps its channel, and the parent chain of every match stays so it is shown in place. Collapsed channels open while searching; Escape clears the field. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Hu2cuPLqpuKVfd9wWFFakU --- web/src/App.css | 12 ++++++++++ web/src/App.tsx | 45 +++++++++++++++++++++++++++++++++++--- web/src/locales/de.json | 2 ++ web/src/locales/en.json | 2 ++ web/src/locales/fa.json | 2 ++ web/src/locales/zh-CN.json | 2 ++ 6 files changed, 62 insertions(+), 3 deletions(-) diff --git a/web/src/App.css b/web/src/App.css index cdbbcc7..4611745 100644 --- a/web/src/App.css +++ b/web/src/App.css @@ -2016,6 +2016,18 @@ box-sizing: border-box; } +.ts-tree-search { + box-sizing: border-box; + width: 100%; + margin: 0 0 0.3rem; + background: var(--input-bg); + color: var(--input-text); + border: 1px solid var(--border); + border-radius: 3px; + padding: 0.25rem 0.5rem; + font-size: 12px; +} + .ts-server-row { font-weight: 600; color: var(--accent); diff --git a/web/src/App.tsx b/web/src/App.tsx index 6fec76b..2403e70 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -903,6 +903,7 @@ function ChannelTree({ groupIconImages, selected, sessionKey, + expandAll, onSelectItem, onSwitchChannel, onOpenPrivateChat, @@ -921,6 +922,8 @@ function ChannelTree({ /** Identifies which multi-join tab this tree belongs to, so the manual * double-click detection below can't pair clicks across two tabs. */ sessionKey: string; + /** While searching: show every match, ignoring channels the user collapsed. */ + expandAll?: boolean; onSelectItem: (item: SelectedItem) => void; onSwitchChannel: (channelId: number) => void; onOpenPrivateChat: (clientId: number, clientName: string) => void; @@ -961,7 +964,7 @@ function ChannelTree({ const channelClients = clients.filter((c) => c.channel === channel.id); const hasSubChannels = channels.some((c) => c.parent === channel.id); const hasChildren = channelClients.length > 0 || hasSubChannels; - const isCollapsed = collapsed.has(channel.id); + const isCollapsed = !expandAll && collapsed.has(channel.id); const spacerClass = spacer.isSpacer ? ` ts-spacer ts-spacer-align-${spacer.alignment}${spacer.isLine ? " ts-spacer-line" : ""}${ spacer.isBoxArt ? " ts-spacer-boxart" : "" @@ -1156,6 +1159,7 @@ function ChannelTree({ groupIconImages={groupIconImages} selected={selected} sessionKey={sessionKey} + expandAll={expandAll} onSelectItem={onSelectItem} onSwitchChannel={onSwitchChannel} onOpenPrivateChat={onOpenPrivateChat} @@ -6437,6 +6441,7 @@ function AppInner() { const [connectError, setConnectError] = useState(null); const [channels, setChannels] = useState([]); const [clients, setClients] = useState([]); + const [treeFilter, setTreeFilter] = useState(""); const [clientVolumes, setClientVolumes] = useState>(loadClientVolumes); /** Stream metadata per publishing client id, keyed by clid. */ const [streamInfos, setStreamInfos] = useState>({}); @@ -9487,6 +9492,25 @@ function AppInner() { () => (showServerQueryClients ? clients : clients.filter((c) => !c.isQuery)), [clients, showServerQueryClients] ); + // Tree search: a channel whose name matches keeps all its clients, a client + // whose name matches keeps its channel; either way the parent chain stays so + // the match is shown where it lives. + const treeSearch = useMemo(() => { + const query = treeFilter.trim().toLowerCase(); + if (!query) return null; + const hit = (name: string) => name.toLowerCase().includes(query); + const channelHits = new Set(channels.filter((c) => hit(c.name)).map((c) => c.id)); + const shownClients = treeClients.filter((c) => hit(c.name) || channelHits.has(c.channel)); + const parentOf = new Map(channels.map((c) => [c.id, c.parent])); + const keep = new Set(); + for (let id of [...channelHits, ...shownClients.map((c) => c.channel)]) { + while (id && !keep.has(id)) { + keep.add(id); + id = parentOf.get(id) ?? 0; + } + } + return { channels: channels.filter((c) => keep.has(c.id)), clients: shownClients }; + }, [treeFilter, channels, treeClients]); const queryClientCount = useMemo( () => clients.reduce((n, c) => n + (c.isQuery ? 1 : 0), 0), [clients] @@ -11207,9 +11231,24 @@ function AppInner() { {serverName || host} + setTreeFilter(e.target.value)} + onKeyDown={(e) => { + if (e.key === "Escape") setTreeFilter(""); + }} + /> + {treeSearch && treeSearch.channels.length === 0 && ( +
{t("tree.noMatches")}
+ )}