From 12be71faf1a3bed4e58d136ede3c69835622fddb Mon Sep 17 00:00:00 2001 From: aiongg <67543387+aiongg@users.noreply.github.com> Date: Tue, 24 Nov 2026 02:24:39 +0000 Subject: [PATCH] Discord channels: always start folded to in-use channels, with an empty state, and fold the full list by server --- web/src/api/mock/mockApi.ts | 26 ++++++++++---------- web/src/modules/admin/discordViews.tsx | 33 ++++++++++++++++++-------- 2 files changed, 35 insertions(+), 24 deletions(-) diff --git a/web/src/api/mock/mockApi.ts b/web/src/api/mock/mockApi.ts index c015de35..ac20ef6d 100644 --- a/web/src/api/mock/mockApi.ts +++ b/web/src/api/mock/mockApi.ts @@ -131,20 +131,18 @@ export function createMockApi(): Api { { id: "l1", login: "mira-anders", linkedAt: new Date(Date.now() - 3 * 86_400_000).toISOString() }, { id: "l2", login: "tomas-vale", linkedAt: new Date(Date.now() - 40 * 3_600_000).toISOString() }, ], - channels: [ - { channelId: "9000000000000004", guildId: "9000000000000001", guildName: "Glasswing Community", name: "general", watched: false, defaultRepo: null, category: null }, - { channelId: "9000000000000005", guildId: "9000000000000001", guildName: "Glasswing Community", name: "announcements", watched: false, defaultRepo: null, category: null }, - { channelId: "9000000000000006", guildId: "9000000000000001", guildName: "Glasswing Community", name: "rules", watched: false, defaultRepo: null, category: null }, - { channelId: "9000000000000002", guildId: "9000000000000001", guildName: "Glasswing Community", name: "dev-chat", watched: true, defaultRepo: "photocraft", category: "Development" }, - { channelId: "9000000000000007", guildId: "9000000000000001", guildName: "Glasswing Community", name: "release-notes", watched: false, defaultRepo: null, category: "Development" }, - { channelId: "9000000000000003", guildId: "9000000000000001", guildName: "Glasswing Community", name: "support", watched: true, defaultRepo: null, category: "Community" }, - { channelId: "9000000000000008", guildId: "9000000000000001", guildName: "Glasswing Community", name: "help-desk", watched: false, defaultRepo: null, category: "Community" }, - { channelId: "9100000000000011", guildId: "9100000000000001", guildName: "Open Tools Collective", name: "general", watched: false, defaultRepo: null, category: null }, - { channelId: "9100000000000012", guildId: "9100000000000001", guildName: "Open Tools Collective", name: "showcase", watched: false, defaultRepo: null, category: "Community" }, - { channelId: "9100000000000013", guildId: "9100000000000001", guildName: "Open Tools Collective", name: "bug-reports", watched: true, defaultRepo: "pdfcraft", category: "Support" }, - { channelId: "9100000000000014", guildId: "9100000000000001", guildName: "Open Tools Collective", name: "off-topic", watched: false, defaultRepo: null, category: "Community" }, - { channelId: "9100000000000015", guildId: "9100000000000001", guildName: "Open Tools Collective", name: "voice-lounge", watched: false, defaultRepo: null, category: "Community" }, - ], + channels: Array.from({ length: 70 }, (_, i) => { + const first = i < 35; + return { + channelId: `${first ? "90" : "91"}0000000000${String(100 + i)}`, + guildId: first ? "9000000000000001" : "9100000000000001", + guildName: first ? "Glasswing Community" : "Open Tools Collective", + name: `channel-${i + 1}`, + watched: new URLSearchParams(location.search).get("inuse") === "1" && i === 3, + defaultRepo: null, + category: i % 10 < 5 ? "Community" : "Development", + }; + }), }; const find = (id: string) => { const d = decisions.find((x) => x.id === id); diff --git a/web/src/modules/admin/discordViews.tsx b/web/src/modules/admin/discordViews.tsx index 00a95eb6..c684e406 100644 --- a/web/src/modules/admin/discordViews.tsx +++ b/web/src/modules/admin/discordViews.tsx @@ -1,4 +1,4 @@ -import { Fragment, useEffect, useState } from "react"; +import { Fragment, useEffect, useState, type ReactNode } from "react"; import { useApi, useQuery } from "../../api/client"; import type { DiscordSetup } from "../../api/types"; import type { ViewProps } from "../../registry/types"; @@ -25,14 +25,30 @@ const STATE: Record = { off: ["Off", "neutral"], connecting: ["Connecting", "warn"], connected: ["Connected", "ok"], reconnecting: ["Reconnecting", "warn"], failed: ["Failed", "bad"], }; +function GuildSection({ guildId, name, count, defaultOpen, children }: { guildId: string; name: string; count: number; defaultOpen: boolean; children: ReactNode }) { + const [open, setOpen] = useState(defaultOpen); + const id = `discord-guild-${guildId}`; + return ( +
+ + + {name} + {guildId} + + {count} {count === 1 ? "channel" : "channels"} + + {open &&
{children}
} +
+ ); +} + export function DiscordView(_: ViewProps) { const { data, error, refetch } = useQuery("discord-setup", (api) => api.discord.setup()); const api = useApi(); const write = useWrite(); const [showAll, setShowAll] = useRememberedOpen("discord-channels"); const inUse = data ? data.channels.filter((c) => c.watched || c.defaultRepo !== null) : []; - const allShown = showAll || inUse.length === 0; - const shown = data ? (allShown ? data.channels : inUse) : []; + const shown = data ? (showAll ? data.channels : inUse) : []; const guilds = [...new Set(shown.map((c) => c.guildId))]; return ( @@ -51,13 +67,10 @@ export function DiscordView(_: ViewProps) { c.watched).length} watched`} flush> {data.channels.length === 0 &&
The bot has reported no channels.
} + {data.channels.length > 0 && !showAll && inUse.length === 0 &&
No channel is watched or has a default repo.
}
{guilds.map((g) => ( -
-
- {data.channels.find((c) => c.guildId === g)?.guildName ?? "Server"} - {g} -
+ c.guildId === g)?.guildName ?? "Server"} count={data.channels.filter((c) => c.guildId === g).length} defaultOpen={!showAll}>
    {shown.filter((c) => c.guildId === g).map((c, i, all) => ( @@ -85,10 +98,10 @@ export function DiscordView(_: ViewProps) { ))}
-
+ ))}
- {inUse.length > 0 && inUse.length < data.channels.length ? ( + {inUse.length < data.channels.length ? ( {showAll ? "Show fewer" : `Show all channels (${data.channels.length})`}