69 lines
1.8 KiB
TypeScript
69 lines
1.8 KiB
TypeScript
import { appStore, safeCall } from '../lib/app';
|
|
import { useStore } from '../lib/store';
|
|
import { Bar } from './Bar';
|
|
import { coverStyle, fmtMs } from '../lib/format';
|
|
import { PauseIcon, PlayIcon, SkipNextIcon } from './icons';
|
|
import { t } from '../i18n';
|
|
|
|
async function togglePlay() {
|
|
const st = appStore.get().status || {};
|
|
if (st.isPlaying && !st.isPaused) await safeCall('Pause');
|
|
else await safeCall('Resume');
|
|
}
|
|
|
|
// Mini player mirrors the current track on views other than Now Playing.
|
|
export function MiniPlayer() {
|
|
const s = useStore(appStore);
|
|
if (s.view === 'dashboard' || !s.current) return null;
|
|
const playing = !!(s.status && s.status.isPlaying && !s.status.isPaused);
|
|
const canForceSkip = !!(
|
|
s.identity &&
|
|
(s.identity.isAdmin || s.identity.isDj)
|
|
);
|
|
const durationMs = s.durationMs || s.current.duration || 0;
|
|
const pct =
|
|
durationMs > 0 ? Math.min(100, (s.positionMs / durationMs) * 100) : 0;
|
|
return (
|
|
<div className="miniplayer">
|
|
<div
|
|
className="mini-cover"
|
|
style={{ background: coverStyle(s.current) }}
|
|
/>
|
|
<div className="mini-info">
|
|
<div className="mini-title">{s.current.title}</div>
|
|
<div className="mini-artist">{s.current.artist || ''}</div>
|
|
</div>
|
|
<button
|
|
className="ctrl"
|
|
title={t('Play/Pause')}
|
|
onClick={togglePlay}
|
|
>
|
|
{playing ? <PauseIcon /> : <PlayIcon />}
|
|
</button>
|
|
{canForceSkip && (
|
|
<button
|
|
className="ctrl"
|
|
title={t('Force skip')}
|
|
onClick={() => safeCall('Skip', { count: 1 })}
|
|
>
|
|
<SkipNextIcon />
|
|
</button>
|
|
)}
|
|
<Bar
|
|
slim
|
|
className="mini-bar"
|
|
pct={pct}
|
|
formatValue={(f) =>
|
|
durationMs ? fmtMs(Math.round(f * durationMs)) : ''
|
|
}
|
|
onDragStart={() => durationMs > 0}
|
|
onCommit={(f) =>
|
|
safeCall('Seek', {
|
|
position: Math.round(f * durationMs),
|
|
})
|
|
}
|
|
/>
|
|
</div>
|
|
);
|
|
}
|