diff --git a/apps/webui/src/components/ui/discord-channel-select.tsx b/apps/webui/src/components/ui/discord-channel-select.tsx index 9c87776..8e9b7a9 100644 --- a/apps/webui/src/components/ui/discord-channel-select.tsx +++ b/apps/webui/src/components/ui/discord-channel-select.tsx @@ -16,11 +16,9 @@ import { import { DiscordResourceMultiSelect } from '@/components/ui/discord-resource-multi-select'; import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover'; import { useGuildChannels } from '@/hooks/use-guild-channels'; -import { CHANNEL_TYPES, channelPrefix } from '@/lib/discord-guild-resources'; +import { CHANNEL_TYPES, channelPrefix, type ChannelKind } from '@/lib/discord-channel-types'; import { cn } from '@/lib/utils'; -type ChannelKind = keyof typeof CHANNEL_TYPES; - function filterChannels( channels: DiscordChannelOption[], kinds: ChannelKind[] | undefined diff --git a/apps/webui/src/lib/discord-channel-types.ts b/apps/webui/src/lib/discord-channel-types.ts new file mode 100644 index 0000000..0dbf974 --- /dev/null +++ b/apps/webui/src/lib/discord-channel-types.ts @@ -0,0 +1,31 @@ +/** Discord channel type helpers shared by server fetchers and client pickers. */ + +export const CHANNEL_TYPES = { + text: [0, 5, 15, 16], + voice: [2, 13], + category: [4], + messageable: [0, 5, 15, 16] +} as const; + +export type ChannelKind = keyof typeof CHANNEL_TYPES; + +/** Channel types returned by the dashboard channels API. */ +export const DASHBOARD_CHANNEL_TYPES = new Set([ + 0, // GUILD_TEXT + 2, // GUILD_VOICE + 4, // GUILD_CATEGORY + 5, // GUILD_ANNOUNCEMENT + 13, // GUILD_STAGE_VOICE + 15, // GUILD_FORUM + 16 // GUILD_MEDIA +]); + +export function channelPrefix(type: number): string { + if (type === 2 || type === 13) { + return '🔊 '; + } + if (type === 4) { + return '📁 '; + } + return '#'; +} diff --git a/apps/webui/src/lib/discord-guild-resources.ts b/apps/webui/src/lib/discord-guild-resources.ts index 01346d0..fbd96a3 100644 --- a/apps/webui/src/lib/discord-guild-resources.ts +++ b/apps/webui/src/lib/discord-guild-resources.ts @@ -1,28 +1,11 @@ import type { DiscordChannelOption, DiscordRoleOption } from '@nexumi/shared'; +import { DASHBOARD_CHANNEL_TYPES } from './discord-channel-types'; import { env } from './env'; import { redis } from './redis'; const DISCORD_API_BASE = 'https://discord.com/api/v10'; const CACHE_TTL_SECONDS = 60; -/** Channel types useful in the dashboard (text, voice, category, forum, …). */ -const DASHBOARD_CHANNEL_TYPES = new Set([ - 0, // GUILD_TEXT - 2, // GUILD_VOICE - 4, // GUILD_CATEGORY - 5, // GUILD_ANNOUNCEMENT - 13, // GUILD_STAGE_VOICE - 15, // GUILD_FORUM - 16 // GUILD_MEDIA -]); - -export const CHANNEL_TYPES = { - text: [0, 5, 15, 16], - voice: [2, 13], - category: [4], - messageable: [0, 5, 15, 16] -} as const; - async function discordBotFetch(path: string): Promise { const response = await fetch(`${DISCORD_API_BASE}${path}`, { headers: { Authorization: `Bot ${env.BOT_TOKEN}` }, @@ -94,12 +77,4 @@ export async function listGuildRolesForDashboard(guildId: string): Promise