web music: closing the dock clears the saved now-playing (so it stays closed)
The dock's X only reset local player state; the server's now-playing snapshot survived, so a reload restored the dock. Closing now also DELETEs /music/now-playing before clearing the queue. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -30,7 +30,7 @@ const fmt = (s: number): string =>
|
|||||||
Number.isFinite(s) && s >= 0 ? `${Math.floor(s / 60)}:${String(Math.floor(s % 60)).padStart(2, '0')}` : '0:00';
|
Number.isFinite(s) && s >= 0 ? `${Math.floor(s / 60)}:${String(Math.floor(s % 60)).padStart(2, '0')}` : '0:00';
|
||||||
|
|
||||||
export const MusicPlayerHost = () => {
|
export const MusicPlayerHost = () => {
|
||||||
const { token, get, put } = useClient();
|
const { token, get, put, delete: del } = useClient();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const [, setCwd] = usePanelChannel<string | null>(MUSIC_CWD_CHANNEL, null);
|
const [, setCwd] = usePanelChannel<string | null>(MUSIC_CWD_CHANNEL, null);
|
||||||
const { current, index, queue, playing, toggle, next, prev, setPlaying, syncIndex, close, loadQueue } =
|
const { current, index, queue, playing, toggle, next, prev, setPlaying, syncIndex, close, loadQueue } =
|
||||||
@@ -233,6 +233,13 @@ export const MusicPlayerHost = () => {
|
|||||||
const subtitle = current?.artist ?? current?.albumRel.split('/').slice(-2, -1)[0] ?? '';
|
const subtitle = current?.artist ?? current?.albumRel.split('/').slice(-2, -1)[0] ?? '';
|
||||||
const pct = duration ? (position / duration) * 100 : 0;
|
const pct = duration ? (position / duration) * 100 : 0;
|
||||||
|
|
||||||
|
// Closing the dock also clears the saved "currently playing" snapshot, so it doesn't get restored on
|
||||||
|
// the next load. (Merely close()-ing the local queue would leave the server snapshot to bring it back.)
|
||||||
|
const handleClose = () => {
|
||||||
|
del('/music/now-playing').catch(() => {});
|
||||||
|
close();
|
||||||
|
};
|
||||||
|
|
||||||
// Clicking the track info jumps the /music library to the playing album (and navigates there).
|
// Clicking the track info jumps the /music library to the playing album (and navigates there).
|
||||||
const openCurrentAlbum = () => {
|
const openCurrentAlbum = () => {
|
||||||
if (!current) return;
|
if (!current) return;
|
||||||
@@ -347,7 +354,7 @@ export const MusicPlayerHost = () => {
|
|||||||
|
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
onClick={close}
|
onClick={handleClose}
|
||||||
className="shrink-0 cursor-pointer p-1.5 text-muted-foreground hover:text-foreground"
|
className="shrink-0 cursor-pointer p-1.5 text-muted-foreground hover:text-foreground"
|
||||||
>
|
>
|
||||||
<X size={16} />
|
<X size={16} />
|
||||||
|
|||||||
Reference in New Issue
Block a user