108 lines
3.3 KiB
TypeScript
108 lines
3.3 KiB
TypeScript
import { useEffect } from 'react';
|
|
import { appStore, boot } from './lib/app';
|
|
import { initRouter } from './lib/router';
|
|
import { initShortcuts } from './lib/shortcuts';
|
|
import { initMediaSession } from './lib/mediaSession';
|
|
import { useStore } from './lib/store';
|
|
import { useLanguage, t } from './i18n';
|
|
import { HelpIcon, MenuIcon } from './components/icons';
|
|
import { Sidebar } from './components/Sidebar';
|
|
import { MiniPlayer } from './components/MiniPlayer';
|
|
import { DialogHost } from './components/DialogHost';
|
|
import { ShortcutsHelp } from './components/ShortcutsHelp';
|
|
import { DashboardView } from './views/DashboardView';
|
|
import { QueueView } from './views/QueueView';
|
|
import { SearchView } from './views/SearchView';
|
|
import { LibraryView } from './views/LibraryView';
|
|
import { StatsView } from './views/StatsView';
|
|
import { ServerView } from './views/ServerView';
|
|
import { UpdatesView } from './views/UpdatesView';
|
|
import { RpcView } from './views/RpcView';
|
|
|
|
const HEADS: Record<string, [string, string]> = {
|
|
dashboard: ['Dashboard', 'Live playback and TeamSpeak server activity'],
|
|
queue: ['Queue', 'Reorder and manage upcoming tracks'],
|
|
search: ['Search', 'Find tracks across YouTube and Yandex Music'],
|
|
library: ['Library', 'Your favorites and saved playlists'],
|
|
stats: ['History & Stats', 'Playback history and server insights'],
|
|
server: ['Server & Admin', 'Manage subscribers and broadcast'],
|
|
updates: ['Updates', 'Runtime, Core, and plugin release control'],
|
|
rpc: ['RPC / API', 'Connect to Echoion programmatically'],
|
|
};
|
|
|
|
export function App() {
|
|
const s = useStore(appStore);
|
|
useLanguage(); // re-render everything on language switch
|
|
|
|
useEffect(() => {
|
|
boot();
|
|
initRouter();
|
|
initShortcuts();
|
|
initMediaSession();
|
|
}, []);
|
|
|
|
const [title, sub] = HEADS[s.view] || HEADS.dashboard;
|
|
|
|
return (
|
|
<div id="app">
|
|
<Sidebar />
|
|
{s.sidebarOpen && (
|
|
<div
|
|
className="drawer-backdrop"
|
|
onClick={() => appStore.set({ sidebarOpen: false })}
|
|
/>
|
|
)}
|
|
<main className="main">
|
|
<header className="header">
|
|
<div className="header-title">
|
|
<button
|
|
className="icon-btn hamburger"
|
|
title={t('Menu')}
|
|
aria-label={t('Menu')}
|
|
onClick={() =>
|
|
appStore.set({ sidebarOpen: !s.sidebarOpen })
|
|
}
|
|
>
|
|
<MenuIcon />
|
|
</button>
|
|
<div>
|
|
<h1>{t(title)}</h1>
|
|
<div className="header-sub">{t(sub)}</div>
|
|
</div>
|
|
</div>
|
|
<div className="header-right">
|
|
<span className="pill">
|
|
<span className="dot dot-green" />
|
|
{s.onlineCount} {t('online')}
|
|
</span>
|
|
<button
|
|
className="icon-btn"
|
|
title={t('Keyboard shortcuts')}
|
|
aria-label={t('Keyboard shortcuts')}
|
|
onClick={() =>
|
|
appStore.set({ shortcutsOpen: true })
|
|
}
|
|
>
|
|
<HelpIcon />
|
|
</button>
|
|
</div>
|
|
</header>
|
|
|
|
{s.view === 'dashboard' && <DashboardView />}
|
|
{s.view === 'queue' && <QueueView />}
|
|
{s.view === 'search' && <SearchView />}
|
|
{s.view === 'library' && <LibraryView />}
|
|
{s.view === 'stats' && <StatsView />}
|
|
{s.view === 'server' && <ServerView />}
|
|
{s.view === 'updates' && <UpdatesView />}
|
|
{s.view === 'rpc' && <RpcView />}
|
|
|
|
<MiniPlayer />
|
|
</main>
|
|
{s.toast && <div className="toast">{s.toast}</div>}
|
|
<DialogHost />
|
|
<ShortcutsHelp />
|
|
</div>
|
|
);
|
|
}
|