// 겜녹이 설정 창 렌더러 진입점. 라우팅: #/wizard[/단계] · #/settings/<탭> import { useEffect, useState, type ReactNode } from 'react'; import { createRoot } from 'react-dom/client'; import { ROLE_LABEL, isAdminRole } from '../core/roles'; import tray from './assets/tray@2x.png'; import { AuthGate } from './auth/Login'; import { AppProvider, isMock, useApp } from './store'; import './styles.css'; import { AdminTab } from './tabs/AdminTab'; import { AudioTab } from './tabs/AudioTab'; import { DiagTab } from './tabs/DiagTab'; import { DictTab } from './tabs/DictTab'; import { DiscordTab } from './tabs/DiscordTab'; import { GamesTab } from './tabs/GamesTab'; import { GeneralTab } from './tabs/GeneralTab'; import { StorageTab } from './tabs/StorageTab'; import { SttTab } from './tabs/SttTab'; import { Avatar, Dot } from './ui'; import { go } from './util'; import { Wizard } from './wizard/Wizard'; const TABS: { id: string; icon: string; label: string; el: () => ReactNode }[] = [ { id: 'discord', icon: '🤖', label: '디스코드', el: () => }, { id: 'games', icon: '🎯', label: '게임 연동', el: () => }, { id: 'stt', icon: '🧠', label: 'STT 모델', el: () => }, { id: 'audio', icon: '🔊', label: '음성 처리', el: () => }, { id: 'dict', icon: '📖', label: '단어사전', el: () => }, { id: 'storage', icon: '💾', label: '저장 · 사이트', el: () => }, { id: 'diag', icon: '🔬', label: '진단', el: () => }, { id: 'general', icon: '⚙️', label: '일반', el: () => }, ]; /** 관리자 · 최고 관리자에게만 보이는 탭 */ const ADMIN_TAB = { id: 'admin', icon: '🛡️', label: '관리자', el: () => }; const tabsFor = (role: string | null) => (isAdminRole(role as never) ? [...TABS, ADMIN_TAB] : TABS); function useHash(): string { const [h, setH] = useState(location.hash); useEffect(() => { const on = () => setH(location.hash); window.addEventListener('hashchange', on); return () => window.removeEventListener('hashchange', on); }, []); return h; } function Router() { const { settings, state } = useApp(); const hash = useHash(); const parts = hash.replace(/^#\/?/, '').split('/'); // 첫 실행이면 마법사로, 주소가 비었으면 디스코드 탭으로 useEffect(() => { if (!hash || hash === '#' || hash === '#/') go(settings.firstRunDone ? '#/settings/discord' : '#/wizard'); }, [hash, settings.firstRunDone]); const isWizard = parts[0] === 'wizard'; useEffect(() => { document.title = isWizard ? '겜녹이 · 첫 실행 설정' : '겜녹이 · 설정'; }, [isWizard]); if (isWizard) return ; const tabs = tabsFor(state.account.role); const tab = tabs.find((t) => t.id === parts[1]) ?? tabs[0]!; return (
); } function Nav({ current, tabs }: { current: string; tabs: typeof TABS }) { const { state } = useApp(); const acc = state.account; const bot = state.bot.status; const botTone = bot === 'ready' ? 'ok' : bot === 'connecting' ? 'warn' : bot === 'error' ? 'err' : 'off'; const botText = bot === 'ready' ? (state.bot.recording.active ? '녹음 중' : '정상') : bot === 'connecting' ? '연결 중' : bot === 'error' ? '오류' : '꺼짐'; const r = state.relay.state; const relayTone = r === 'online' ? 'ok' : r === 'connecting' ? 'warn' : r === 'error' ? 'err' : 'off'; const relayText = r === 'online' ? '연결됨' : r === 'connecting' ? '연결 중' : r === 'error' ? '오류' : '미등록'; return ( ); } createRoot(document.getElementById('root')!).render( , );