fix(library): poll track list while enrichment is pending
The library tracks query wasn't refetching, so a track stayed on "Identifying metadata…" until an unrelated Track-tag invalidation. Poll every 4s while any listed track is metadata_status=pending, then stop (and never while offline). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
import { useNavigate } from 'react-router';
|
import { useNavigate } from 'react-router';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import {
|
import {
|
||||||
@@ -54,8 +54,14 @@ export function LibraryPage() {
|
|||||||
const [search, setSearch] = useState('');
|
const [search, setSearch] = useState('');
|
||||||
const [debouncedSearch] = useDebounce(search, 300);
|
const [debouncedSearch] = useDebounce(search, 300);
|
||||||
|
|
||||||
|
// Poll while any listed track is still being enriched, then stop. Enrichment
|
||||||
|
// runs asynchronously in a worker after import/upload; without this the row
|
||||||
|
// stays stuck on "Identifying metadata…" until something else invalidates the
|
||||||
|
// Track tag. Cleared to 0 once nothing is pending (and while offline).
|
||||||
|
const [tracksPollMs, setTracksPollMs] = useState(0);
|
||||||
const tracksQuery = useGetTracksQuery(
|
const tracksQuery = useGetTracksQuery(
|
||||||
debouncedSearch ? { search } : undefined,
|
debouncedSearch ? { search } : undefined,
|
||||||
|
{ pollingInterval: tracksPollMs },
|
||||||
);
|
);
|
||||||
const albumsQuery = useGetAlbumsQuery(
|
const albumsQuery = useGetAlbumsQuery(
|
||||||
debouncedSearch ? { search } : undefined,
|
debouncedSearch ? { search } : undefined,
|
||||||
@@ -73,6 +79,14 @@ export function LibraryPage() {
|
|||||||
const localArtists = useAppSelector(selectLocalArtists);
|
const localArtists = useAppSelector(selectLocalArtists);
|
||||||
const q = debouncedSearch.trim().toLowerCase();
|
const q = debouncedSearch.trim().toLowerCase();
|
||||||
|
|
||||||
|
const anyPending =
|
||||||
|
!offline &&
|
||||||
|
(tracksQuery.data?.items.some((tr) => tr.metadataStatus === 'pending') ??
|
||||||
|
false);
|
||||||
|
useEffect(() => {
|
||||||
|
setTracksPollMs(anyPending ? 4000 : 0);
|
||||||
|
}, [anyPending]);
|
||||||
|
|
||||||
// Live server data wins; offline we fall back to the locally-composed list.
|
// Live server data wins; offline we fall back to the locally-composed list.
|
||||||
const tracksToShow =
|
const tracksToShow =
|
||||||
tracksQuery.data?.items ??
|
tracksQuery.data?.items ??
|
||||||
|
|||||||
Reference in New Issue
Block a user