Similar Artists orb: reliable pause + standard addEventListener wiring
- Orb wouldn't pause when the worker had finished its library: the toggle keyed
off classList.contains('active'), but a done worker sits in the green
'complete'/idle state, so clicking tried to resume (no-op). Now it pauses
unless already paused → pausable in any state.
- Switched from inline onclick to addEventListener (matches spotify/itunes/etc.,
the majority pattern) instead of the amazon/discogs inline style.
This commit is contained in:
parent
8ba20f7c49
commit
5949c104c3
2 changed files with 7 additions and 5 deletions
|
|
@ -567,8 +567,7 @@
|
|||
</div>
|
||||
<!-- Similar Artists (MusicMap) Enrichment Status Icon -->
|
||||
<div class="similar-artists-enrich-button-container">
|
||||
<button class="similar-artists-enrich-button" id="similar-artists-enrich-button" title="Similar Artists (MusicMap) Enrichment"
|
||||
onclick="toggleSimilarArtistsEnrichment()">
|
||||
<button class="similar-artists-enrich-button" id="similar-artists-enrich-button" title="Similar Artists (MusicMap) Enrichment">
|
||||
<img src="https://www.music-map.com/elements/objects/og_logo.png"
|
||||
alt="Similar Artists" class="similar-artists-enrich-logo">
|
||||
<div class="similar-artists-enrich-spinner"></div>
|
||||
|
|
|
|||
|
|
@ -1362,10 +1362,12 @@ async function toggleSimilarArtistsEnrichment() {
|
|||
try {
|
||||
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';
|
||||
// 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';
|
||||
const response = await fetch(endpoint, { method: 'POST' });
|
||||
if (!response.ok) throw new Error(`Failed to ${isRunning ? 'pause' : 'resume'} Similar Artists enrichment`);
|
||||
if (!response.ok) throw new Error(`Failed to ${isPaused ? 'resume' : 'pause'} Similar Artists enrichment`);
|
||||
await updateSimilarArtistsEnrichmentStatus();
|
||||
} catch (error) {
|
||||
console.error('Error toggling Similar Artists enrichment:', error);
|
||||
|
|
@ -1377,6 +1379,7 @@ async function toggleSimilarArtistsEnrichment() {
|
|||
const wire = () => {
|
||||
const button = document.getElementById('similar-artists-enrich-button');
|
||||
if (button) {
|
||||
button.addEventListener('click', toggleSimilarArtistsEnrichment); // standard wiring (like spotify/itunes)
|
||||
updateSimilarArtistsEnrichmentStatus();
|
||||
setInterval(updateSimilarArtistsEnrichmentStatus, 2000);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue