From c635ca5b82ea65ef79d2e80f017f5899959b84d8 Mon Sep 17 00:00:00 2001 From: BoulderBadgeDad Date: Wed, 3 Jun 2026 15:52:59 -0700 Subject: [PATCH] Similar Artists orb: toggle from real backend state (fix 'won't unpause') MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Class-based toggle had a hole: the orb may lack the 'paused' class even when the backend is paused (before the first 2s status poll, or worker fallback), so a click would PAUSE the already-paused worker (no-op) → 'clicking doesn't unpause'. Now the toggle reads /status first and does the opposite of the real paused state, so a paused worker always resumes on click. --- webui/static/enrichment.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/webui/static/enrichment.js b/webui/static/enrichment.js index 7b341db7..2646f8e3 100644 --- a/webui/static/enrichment.js +++ b/webui/static/enrichment.js @@ -1360,14 +1360,18 @@ function updateSimilarArtistsEnrichmentStatusFromData(data) { async function toggleSimilarArtistsEnrichment() { try { - const button = document.getElementById('similar-artists-enrich-button'); - if (!button) return; - // Pause unless it's already paused — so a worker that has finished its - // library (green 'complete'/idle state, not 'active') can still be paused. - const isPaused = button.classList.contains('paused'); - const endpoint = isPaused ? '/api/enrichment/similar_artists/resume' : '/api/enrichment/similar_artists/pause'; + // Decide from the ACTUAL backend state, not the orb's CSS class — the + // class can be stale/absent (before the first status poll, or a 'complete' + // worker isn't 'active'/'paused'), which made class-based toggling pause a + // paused worker (no-op). Read paused, then do the opposite. + let paused = false; + try { + const s = await fetch('/api/enrichment/similar_artists/status'); + if (s.ok) paused = (await s.json()).paused === true; + } catch (_e) { /* fall back to pause */ } + const endpoint = paused ? '/api/enrichment/similar_artists/resume' : '/api/enrichment/similar_artists/pause'; const response = await fetch(endpoint, { method: 'POST' }); - if (!response.ok) throw new Error(`Failed to ${isPaused ? 'resume' : 'pause'} Similar Artists enrichment`); + if (!response.ok) throw new Error(`Failed to ${paused ? 'resume' : 'pause'} Similar Artists enrichment`); await updateSimilarArtistsEnrichmentStatus(); } catch (error) { console.error('Error toggling Similar Artists enrichment:', error);