mirror of
https://github.com/Moepchi/webspeak3.git
synced 2026-12-03 01:42:50 +08:00
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 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Hu2cuPLqpuKVfd9wWFFakU
This commit is contained in:
1 parent
4b245d69d3
commit
728c900bb2
6 files changed
+62
-3
No files matched your search
@@ -2016,6 +2016,18 @@
|
|||||||
box-sizing: border-box;
|
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 {
|
.ts-server-row {
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
color: var(--accent);
|
color: var(--accent);
|
||||||
|
|||||||
+42
-3
@@ -903,6 +903,7 @@ function ChannelTree({
|
|||||||
groupIconImages,
|
groupIconImages,
|
||||||
selected,
|
selected,
|
||||||
sessionKey,
|
sessionKey,
|
||||||
|
expandAll,
|
||||||
onSelectItem,
|
onSelectItem,
|
||||||
onSwitchChannel,
|
onSwitchChannel,
|
||||||
onOpenPrivateChat,
|
onOpenPrivateChat,
|
||||||
@@ -921,6 +922,8 @@ function ChannelTree({
|
|||||||
/** Identifies which multi-join tab this tree belongs to, so the manual
|
/** Identifies which multi-join tab this tree belongs to, so the manual
|
||||||
* double-click detection below can't pair clicks across two tabs. */
|
* double-click detection below can't pair clicks across two tabs. */
|
||||||
sessionKey: string;
|
sessionKey: string;
|
||||||
|
/** While searching: show every match, ignoring channels the user collapsed. */
|
||||||
|
expandAll?: boolean;
|
||||||
onSelectItem: (item: SelectedItem) => void;
|
onSelectItem: (item: SelectedItem) => void;
|
||||||
onSwitchChannel: (channelId: number) => void;
|
onSwitchChannel: (channelId: number) => void;
|
||||||
onOpenPrivateChat: (clientId: number, clientName: string) => void;
|
onOpenPrivateChat: (clientId: number, clientName: string) => void;
|
||||||
@@ -961,7 +964,7 @@ function ChannelTree({
|
|||||||
const channelClients = clients.filter((c) => c.channel === channel.id);
|
const channelClients = clients.filter((c) => c.channel === channel.id);
|
||||||
const hasSubChannels = channels.some((c) => c.parent === channel.id);
|
const hasSubChannels = channels.some((c) => c.parent === channel.id);
|
||||||
const hasChildren = channelClients.length > 0 || hasSubChannels;
|
const hasChildren = channelClients.length > 0 || hasSubChannels;
|
||||||
const isCollapsed = collapsed.has(channel.id);
|
const isCollapsed = !expandAll && collapsed.has(channel.id);
|
||||||
const spacerClass = spacer.isSpacer
|
const spacerClass = spacer.isSpacer
|
||||||
? ` ts-spacer ts-spacer-align-${spacer.alignment}${spacer.isLine ? " ts-spacer-line" : ""}${
|
? ` ts-spacer ts-spacer-align-${spacer.alignment}${spacer.isLine ? " ts-spacer-line" : ""}${
|
||||||
spacer.isBoxArt ? " ts-spacer-boxart" : ""
|
spacer.isBoxArt ? " ts-spacer-boxart" : ""
|
||||||
@@ -1156,6 +1159,7 @@ function ChannelTree({
|
|||||||
groupIconImages={groupIconImages}
|
groupIconImages={groupIconImages}
|
||||||
selected={selected}
|
selected={selected}
|
||||||
sessionKey={sessionKey}
|
sessionKey={sessionKey}
|
||||||
|
expandAll={expandAll}
|
||||||
onSelectItem={onSelectItem}
|
onSelectItem={onSelectItem}
|
||||||
onSwitchChannel={onSwitchChannel}
|
onSwitchChannel={onSwitchChannel}
|
||||||
onOpenPrivateChat={onOpenPrivateChat}
|
onOpenPrivateChat={onOpenPrivateChat}
|
||||||
@@ -6437,6 +6441,7 @@ function AppInner() {
|
|||||||
const [connectError, setConnectError] = useState<string | null>(null);
|
const [connectError, setConnectError] = useState<string | null>(null);
|
||||||
const [channels, setChannels] = useState<ChannelInfo[]>([]);
|
const [channels, setChannels] = useState<ChannelInfo[]>([]);
|
||||||
const [clients, setClients] = useState<ClientInfo[]>([]);
|
const [clients, setClients] = useState<ClientInfo[]>([]);
|
||||||
|
const [treeFilter, setTreeFilter] = useState("");
|
||||||
const [clientVolumes, setClientVolumes] = useState<Record<string, number>>(loadClientVolumes);
|
const [clientVolumes, setClientVolumes] = useState<Record<string, number>>(loadClientVolumes);
|
||||||
/** Stream metadata per publishing client id, keyed by clid. */
|
/** Stream metadata per publishing client id, keyed by clid. */
|
||||||
const [streamInfos, setStreamInfos] = useState<Record<number, StreamInfo>>({});
|
const [streamInfos, setStreamInfos] = useState<Record<number, StreamInfo>>({});
|
||||||
@@ -9487,6 +9492,25 @@ function AppInner() {
|
|||||||
() => (showServerQueryClients ? clients : clients.filter((c) => !c.isQuery)),
|
() => (showServerQueryClients ? clients : clients.filter((c) => !c.isQuery)),
|
||||||
[clients, showServerQueryClients]
|
[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<number>();
|
||||||
|
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(
|
const queryClientCount = useMemo(
|
||||||
() => clients.reduce((n, c) => n + (c.isQuery ? 1 : 0), 0),
|
() => clients.reduce((n, c) => n + (c.isQuery ? 1 : 0), 0),
|
||||||
[clients]
|
[clients]
|
||||||
@@ -11207,9 +11231,24 @@ function AppInner() {
|
|||||||
<ServerIcon />
|
<ServerIcon />
|
||||||
<span>{serverName || host}</span>
|
<span>{serverName || host}</span>
|
||||||
</div>
|
</div>
|
||||||
|
<input
|
||||||
|
type="search"
|
||||||
|
className="ts-tree-search"
|
||||||
|
value={treeFilter}
|
||||||
|
placeholder={t("tree.search")}
|
||||||
|
aria-label={t("tree.search")}
|
||||||
|
onChange={(e) => setTreeFilter(e.target.value)}
|
||||||
|
onKeyDown={(e) => {
|
||||||
|
if (e.key === "Escape") setTreeFilter("");
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
{treeSearch && treeSearch.channels.length === 0 && (
|
||||||
|
<div className="ts-tree-empty">{t("tree.noMatches")}</div>
|
||||||
|
)}
|
||||||
<ChannelTree
|
<ChannelTree
|
||||||
channels={channels}
|
channels={treeSearch?.channels ?? channels}
|
||||||
clients={treeClients}
|
clients={treeSearch?.clients ?? treeClients}
|
||||||
|
expandAll={!!treeSearch}
|
||||||
parent={0}
|
parent={0}
|
||||||
ownClientId={ownClientId ?? ownClient?.id ?? null}
|
ownClientId={ownClientId ?? ownClient?.id ?? null}
|
||||||
talkers={displayTalkers}
|
talkers={displayTalkers}
|
||||||
|
|||||||
@@ -383,6 +383,8 @@
|
|||||||
"info.serverGroups": "Servergruppen:",
|
"info.serverGroups": "Servergruppen:",
|
||||||
"info.yes": "Ja",
|
"info.yes": "Ja",
|
||||||
"info.no": "Nein",
|
"info.no": "Nein",
|
||||||
|
"tree.noMatches": "Keine Treffer",
|
||||||
|
"tree.search": "Kanäle und Nutzer suchen",
|
||||||
"tree.notConnected": "Nicht verbunden",
|
"tree.notConnected": "Nicht verbunden",
|
||||||
"tree.clickToSelect": "Klicken zum Auswählen, Doppelklick zum Beitreten",
|
"tree.clickToSelect": "Klicken zum Auswählen, Doppelklick zum Beitreten",
|
||||||
"tree.clickToJoin": "Doppelklick zum Beitreten",
|
"tree.clickToJoin": "Doppelklick zum Beitreten",
|
||||||
|
|||||||
@@ -383,6 +383,8 @@
|
|||||||
"info.serverGroups": "Server groups:",
|
"info.serverGroups": "Server groups:",
|
||||||
"info.yes": "Yes",
|
"info.yes": "Yes",
|
||||||
"info.no": "No",
|
"info.no": "No",
|
||||||
|
"tree.noMatches": "No matches",
|
||||||
|
"tree.search": "Search channels and users",
|
||||||
"tree.notConnected": "Not connected",
|
"tree.notConnected": "Not connected",
|
||||||
"tree.clickToSelect": "Click to select, double-click to join",
|
"tree.clickToSelect": "Click to select, double-click to join",
|
||||||
"tree.clickToJoin": "Double-click to join",
|
"tree.clickToJoin": "Double-click to join",
|
||||||
|
|||||||
@@ -382,6 +382,8 @@
|
|||||||
"info.serverGroups": "گروههای سرور:",
|
"info.serverGroups": "گروههای سرور:",
|
||||||
"info.yes": "بله",
|
"info.yes": "بله",
|
||||||
"info.no": "خیر",
|
"info.no": "خیر",
|
||||||
|
"tree.noMatches": "نتیجهای یافت نشد",
|
||||||
|
"tree.search": "جستجوی کانالها و کاربران",
|
||||||
"tree.notConnected": "متصل نیست",
|
"tree.notConnected": "متصل نیست",
|
||||||
"tree.clickToSelect": "برای انتخاب کلیک کن، برای ورود دوبار کلیک کن",
|
"tree.clickToSelect": "برای انتخاب کلیک کن، برای ورود دوبار کلیک کن",
|
||||||
"tree.clickToJoin": "برای ورود دوبار کلیک کن",
|
"tree.clickToJoin": "برای ورود دوبار کلیک کن",
|
||||||
|
|||||||
@@ -284,6 +284,8 @@
|
|||||||
"info.serverGroups": "服务器组:",
|
"info.serverGroups": "服务器组:",
|
||||||
"info.yes": "是",
|
"info.yes": "是",
|
||||||
"info.no": "否",
|
"info.no": "否",
|
||||||
|
"tree.noMatches": "无匹配结果",
|
||||||
|
"tree.search": "搜索频道和用户",
|
||||||
"tree.notConnected": "未连接",
|
"tree.notConnected": "未连接",
|
||||||
"tree.clickToSelect": "单击选择,双击加入",
|
"tree.clickToSelect": "单击选择,双击加入",
|
||||||
"tree.clickToJoin": "双击加入",
|
"tree.clickToJoin": "双击加入",
|
||||||
|
|||||||
Reference in new issue
Block a user