Similar Artists orb: use the exact same toggle logic as the other orbs

Stop diverging — match toggleAmazonEnrichment/toggleSpotifyEnrichment verbatim:
contains('active') ? pause : resume. A paused orb isn't 'active', so a click
resumes it (same as every other worker). My earlier 'paused'-class variant was
what broke unpausing.
This commit is contained in:
BoulderBadgeDad 2026-06-03 15:53:47 -07:00
parent c635ca5b82
commit 940afbf4b2

View file

@ -1359,19 +1359,16 @@ function updateSimilarArtistsEnrichmentStatusFromData(data) {
}
async function toggleSimilarArtistsEnrichment() {
// Identical logic to the other orbs (e.g. toggleAmazonEnrichment): if the orb
// is 'active' (running) → pause, otherwise → resume. A paused orb isn't
// 'active', so this resumes it.
try {
// 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 button = document.getElementById('similar-artists-enrich-button');
if (!button) return;
const isRunning = button.classList.contains('active');
const endpoint = isRunning ? '/api/enrichment/similar_artists/pause' : '/api/enrichment/similar_artists/resume';
const response = await fetch(endpoint, { method: 'POST' });
if (!response.ok) throw new Error(`Failed to ${paused ? 'resume' : 'pause'} Similar Artists enrichment`);
if (!response.ok) throw new Error(`Failed to ${isRunning ? 'pause' : 'resume'} Similar Artists enrichment`);
await updateSimilarArtistsEnrichmentStatus();
} catch (error) {
console.error('Error toggling Similar Artists enrichment:', error);