feat(playlists): keep the player queue live across tabs
Track the playing item by id instead of a frozen index, deriving the index from the live queue so the N / M counter and prev/next neighbours stay correct when the playlist changes underneath (e.g. an item removed in another tab) without disrupting playback of the current video. Refetch the playlist list/detail on window focus so such changes flow in, updating the player's queue length in near-real-time.
This commit is contained in:
parent
4689d2cbbd
commit
ddb1890e84
2 changed files with 20 additions and 6 deletions
|
|
@ -108,7 +108,11 @@ export default function Playlists() {
|
|||
// The open player, as an index into `items` (the queue); null = closed.
|
||||
const [playingIndex, setPlayingIndex] = useState<number | null>(null);
|
||||
|
||||
const listQuery = useQuery({ queryKey: ["playlists"], queryFn: () => api.playlists() });
|
||||
const listQuery = useQuery({
|
||||
queryKey: ["playlists"],
|
||||
queryFn: () => api.playlists(),
|
||||
refetchOnWindowFocus: true,
|
||||
});
|
||||
const playlists = listQuery.data ?? [];
|
||||
|
||||
// Keep the selection valid: default to the first playlist, and if the selected one
|
||||
|
|
@ -127,6 +131,9 @@ export default function Playlists() {
|
|||
queryKey: ["playlist", selectedId],
|
||||
queryFn: () => api.playlist(selectedId as number),
|
||||
enabled: selectedId != null,
|
||||
// Refetch when returning to the tab so a change made elsewhere (another tab/device)
|
||||
// shows up — including the player's live N / M count, which reads the queue length.
|
||||
refetchOnWindowFocus: true,
|
||||
});
|
||||
const detail = detailQuery.data;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue