import { useEffect, useMemo } from 'react'; import { useQuery } from '@tanstack/react-query'; import { useTranslation } from 'react-i18next'; import { fetchChannels, guildChannelsQueryKey } from '@/api/guilds'; import type { Channel } from '@/api/types'; import { fetchMyGuilds, myGuildsQueryKey } from '@/api/users'; import { ErrorNotice } from '@/components/ui/ErrorNotice'; import { SelectField } from '@/components/ui/Field'; import { Card } from '@/components/ui/primitives'; import { SkeletonLines } from '@/components/ui/Skeleton'; import { canManageWebhooks } from '@/lib/identity'; import { useCurrentUser } from '@/lib/hooks'; import { useSessionStore } from '@/stores/session'; import { ChannelWebhooksSection } from '@/pages/settings/ChannelWebhooksSection'; import { GuildPicker } from '@/pages/settings/GuildPicker'; /** * Пункт «Комната» окна настроек: управление одной комнатой — пока это вебхуки * (AGENT.md 7.11). Сервер выбирается тем же списком, что и в пункте «Сервер», * комната — выпадающим списком текстовых комнат. */ export function ChannelSettingsPage() { const sessionGuilds = useSessionStore((state) => state.guilds); const upsertGuild = useSessionStore((state) => state.upsertGuild); const selectSettingsGuild = useSessionStore((state) => state.selectSettingsGuild); const settingsGuildId = useSessionStore((state) => state.settingsGuildId); // Подстраховка снапшота: без неё список серверов пуст до подключения шлюза. const myGuilds = useQuery({ queryKey: myGuildsQueryKey, queryFn: ({ signal }) => fetchMyGuilds(signal), retry: 0, enabled: sessionGuilds.length === 0, }); useEffect(() => { if (sessionGuilds.length > 0 || myGuilds.data === undefined) { return; } for (const guild of myGuilds.data) { upsertGuild(guild); } }, [sessionGuilds.length, myGuilds.data, upsertGuild]); const guilds = useMemo( () => (sessionGuilds.length > 0 ? sessionGuilds : (myGuilds.data ?? [])), [sessionGuilds, myGuilds.data], ); return (
{t('settings.channel.noGuild')}
{t('settings.channel.noChannels')}
{t('settings.channel.noPermission')}