···9292 // flatmap flattens the returned array into the new map
9393 .flatMap((x, i) => (i === 0 ? x : [", ", x]))
9494 ) : (
9595- // artist defined by default because
9595+ // artist defined by default because
9696 // i cant be bothered to do client error handling
9797 // and this is easier
9898 <a href="#">Artist Name</a>
···513513 );
514514 const addArtists = playing.artists.slice(artistLen);
515515516516- console.log(replaceArtists, addArtists);
517517-518516 let lastValidArtist = elIs(
519517 this.elements.artists.children[0],
520518 HTMLElement,
···633631 const ev = new EventSource("/now-playing-sse");
634632635633 // close event source safely
636636- window.addEventListener("beforeunload", () => ev.close())
634634+ window.addEventListener("beforeunload", () => ev.close());
637635638636 let i = -1;
639637 ev.addEventListener("playing", (event) => {
···648646 if (!isNowPlaying(data))
649647 return console.warn("Unexpected package from server:", data, event.data);
650648649649+ // data is valid nowPlayingData
651650 try {
652652- // data is valid nowPlayingData
653653- // first call so assume prev is in an invalid state (which it is)
654654- if (i === 0) console.log("SKIP: i = 0");
655655- // if both are null, quit since re-rendering is pointless
656656- else if (data == prev) console.log("MATCH: null = null");
657657- // now if both are valid play items, so check the ID for equality
658658- else if (data !== null && prev !== null && data.id === prev.id)
659659- console.log("MATCH: nowPlaying = nowPlaying");
660660- else {
661661- console.log("DIFFERENT");
651651+ if (
652652+ !(
653653+ // first call so assume prev is in an invalid state (which it is)
654654+ (
655655+ i === 0 ||
656656+ // if both are null, quit since re-rendering is pointless
657657+ data == prev ||
658658+ // now if both are valid play items, so check the ID for equality
659659+ (data !== null && prev !== null && data.id === prev.id)
660660+ )
661661+ )
662662+ ) {
662663 // there is now a difference between the previous setting and the new setting
663664 // so it is worth updating the UI
664664-665665- if (data) elements.nowPlaying.updateMetadata(data);
666666- else elements.nowPlaying.nothingPlaying();
667665668666 // spinner head animation:
669667 // 1. pause current animation.
···682680 ? data?.album.images[0].url
683681 : "https://undefined";
684682685685- // 5. reset the position of the infinite animation
683683+ // 5. update popup
684684+ if (data) elements.nowPlaying.updateMetadata(data);
685685+ else elements.nowPlaying.nothingPlaying();
686686+687687+ // 6. reset the position of the infinite animation
686688 animations.forEach((anim) => (anim.currentTime = 0));
687689688688- // 6. if new track is not null then, after 2s
690690+ // 7. if new track is not null then, after 2s
689691 if (data)
690692 setTimeout(() => {
691691- // 7. resume the infinite animation
693693+ // 8. resume the infinite animation
692694 animations.forEach((anim) => anim.play());
693695 }, 2000);
694696695695- // 8. make sure the record is in the right state (playing or paused)
697697+ // 9. make sure the record is in the right state (playing or paused)
696698 elements.player.dataset.playing = data ? "true" : "false";
697699 }),
698700 );