1 parent
7a18682b0e
commit
24fecc90f3
107 files changed
+14935
-1919
No files matched your search
@@ -0,0 +1,178 @@
|
||||
import { useState, type ReactNode } from 'react';
|
||||
import {
|
||||
appStore,
|
||||
changeLanguage,
|
||||
connectWithToken,
|
||||
getStoredToken,
|
||||
logout,
|
||||
requestToken,
|
||||
showView,
|
||||
type ViewName,
|
||||
} from '../lib/app';
|
||||
import { useStore } from '../lib/store';
|
||||
import { promptDialog } from '../lib/dialog';
|
||||
import { Avatar } from './Avatar';
|
||||
import {
|
||||
CodeIcon,
|
||||
GearIcon,
|
||||
HeartIcon,
|
||||
PlayIcon,
|
||||
QueueIcon,
|
||||
SearchIcon,
|
||||
StatsIcon,
|
||||
WatchIcon,
|
||||
} from './icons';
|
||||
import { t, useLanguage } from '../i18n';
|
||||
|
||||
const NAV: Array<{ view: ViewName; icon: ReactNode; label: string }> = [
|
||||
{ view: 'now', icon: <PlayIcon />, label: 'Now Playing' },
|
||||
{ view: 'queue', icon: <QueueIcon />, label: 'Queue' },
|
||||
{ view: 'search', icon: <SearchIcon />, label: 'Search' },
|
||||
{ view: 'library', icon: <HeartIcon />, label: 'Library' },
|
||||
{ view: 'stats', icon: <StatsIcon />, label: 'History & Stats' },
|
||||
{ view: 'watch', icon: <WatchIcon />, label: 'Watch Together' },
|
||||
{ view: 'server', icon: <GearIcon />, label: 'Server & Admin' },
|
||||
{ view: 'rpc', icon: <CodeIcon />, label: 'RPC / API' },
|
||||
];
|
||||
|
||||
export function Sidebar() {
|
||||
const s = useStore(appStore);
|
||||
const language = useLanguage();
|
||||
const [token, setToken] = useState(getStoredToken() || '');
|
||||
const isAdmin = !!(s.identity && s.identity.isAdmin);
|
||||
const playing = !!(
|
||||
s.status &&
|
||||
s.status.isPlaying &&
|
||||
!s.status.isPaused
|
||||
);
|
||||
const name = s.identity
|
||||
? s.identity.nickname || s.identity.uid || t('user')
|
||||
: '';
|
||||
|
||||
return (
|
||||
<aside className={'sidebar' + (s.sidebarOpen ? ' open' : '')}>
|
||||
<div className="brand">
|
||||
<div className="brand-icon">
|
||||
<svg viewBox="0 0 24 24" width="22" height="22" fill="#fff">
|
||||
<rect x="4" y="9" width="3.4" height="10" rx="1.6" />
|
||||
<rect x="10.3" y="4" width="3.4" height="15" rx="1.6" />
|
||||
<rect x="16.6" y="12" width="3.4" height="7" rx="1.6" />
|
||||
</svg>
|
||||
</div>
|
||||
<div>
|
||||
<div className="brand-name">Echoion</div>
|
||||
<div className="brand-sub">{t('MUSIC BOT · TS3')}</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<nav className="nav">
|
||||
{NAV.filter(
|
||||
(item) => item.view !== 'server' || isAdmin
|
||||
).map((item) => (
|
||||
<button
|
||||
key={item.view}
|
||||
className={
|
||||
'nav-item' + (s.view === item.view ? ' active' : '')
|
||||
}
|
||||
onClick={() => showView(item.view)}
|
||||
>
|
||||
<span className="nav-ico">{item.icon}</span>
|
||||
{t(item.label)}
|
||||
{item.view === 'now' && playing && (
|
||||
<span className="live-dot" />
|
||||
)}
|
||||
{item.view === 'queue' && s.queue.length > 0 && (
|
||||
<span className="nav-badge">{s.queue.length}</span>
|
||||
)}
|
||||
</button>
|
||||
))}
|
||||
</nav>
|
||||
|
||||
<div className="sidebar-foot">
|
||||
<div className="conn-row">
|
||||
<span
|
||||
className={
|
||||
'conn-dot' +
|
||||
(s.connection === 'connected'
|
||||
? ' on'
|
||||
: s.connection === 'error'
|
||||
? ' err'
|
||||
: '')
|
||||
}
|
||||
/>
|
||||
<span>{t(s.connection)}</span>
|
||||
<select
|
||||
className="lang-select"
|
||||
value={language}
|
||||
title={t('Language')}
|
||||
onChange={(e) =>
|
||||
changeLanguage(e.target.value as 'en' | 'ru')
|
||||
}
|
||||
>
|
||||
<option value="en">EN</option>
|
||||
<option value="ru">RU</option>
|
||||
</select>
|
||||
</div>
|
||||
{!s.identity ? (
|
||||
<div>
|
||||
<input
|
||||
type="password"
|
||||
placeholder={t('RPC token')}
|
||||
autoComplete="off"
|
||||
value={token}
|
||||
onChange={(e) => setToken(e.target.value)}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === 'Enter') {
|
||||
connectWithToken(token);
|
||||
}
|
||||
}}
|
||||
/>
|
||||
<button
|
||||
className="btn btn-accent"
|
||||
onClick={() => connectWithToken(token)}
|
||||
>
|
||||
{t('Connect')}
|
||||
</button>
|
||||
<button
|
||||
className="btn btn-ghost"
|
||||
title={t('Send my token via TeamSpeak PM')}
|
||||
onClick={async () => {
|
||||
const nickname = await promptDialog({
|
||||
title: t('Get token by nickname'),
|
||||
message: t(
|
||||
'Your TeamSpeak nickname (must be subscribed):'
|
||||
),
|
||||
placeholder: t('Nickname'),
|
||||
confirmLabel: t('Send'),
|
||||
});
|
||||
if (nickname) requestToken(nickname);
|
||||
}}
|
||||
>
|
||||
{t('Get token by nickname…')}
|
||||
</button>
|
||||
</div>
|
||||
) : (
|
||||
<div className="whoami">
|
||||
<Avatar name={name} uid={s.identity.uid} />
|
||||
<span>{name}</span>
|
||||
{isAdmin && (
|
||||
<span className="admin-chip">{t('ADMIN')}</span>
|
||||
)}
|
||||
{!isAdmin && s.identity.isDj && (
|
||||
<span className="admin-chip">{t('DJ')}</span>
|
||||
)}
|
||||
<button
|
||||
className="btn btn-ghost"
|
||||
onClick={() => {
|
||||
logout();
|
||||
setToken('');
|
||||
}}
|
||||
>
|
||||
{t('Logout')}
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</aside>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user