···92 // flatmap flattens the returned array into the new map
93 .flatMap((x, i) => (i === 0 ? x : [", ", x]))
94 ) : (
95- // artist defined by default because
96 // i cant be bothered to do client error handling
97 // and this is easier
98 <a href="#">Artist Name</a>
···513 );
514 const addArtists = playing.artists.slice(artistLen);
515516- console.log(replaceArtists, addArtists);
517-518 let lastValidArtist = elIs(
519 this.elements.artists.children[0],
520 HTMLElement,
···633 const ev = new EventSource("/now-playing-sse");
634635 // close event source safely
636- window.addEventListener("beforeunload", () => ev.close())
637638 let i = -1;
639 ev.addEventListener("playing", (event) => {
···648 if (!isNowPlaying(data))
649 return console.warn("Unexpected package from server:", data, event.data);
6500651 try {
652- // data is valid nowPlayingData
653- // first call so assume prev is in an invalid state (which it is)
654- if (i === 0) console.log("SKIP: i = 0");
655- // if both are null, quit since re-rendering is pointless
656- else if (data == prev) console.log("MATCH: null = null");
657- // now if both are valid play items, so check the ID for equality
658- else if (data !== null && prev !== null && data.id === prev.id)
659- console.log("MATCH: nowPlaying = nowPlaying");
660- else {
661- console.log("DIFFERENT");
00662 // there is now a difference between the previous setting and the new setting
663 // so it is worth updating the UI
664-665- if (data) elements.nowPlaying.updateMetadata(data);
666- else elements.nowPlaying.nothingPlaying();
667668 // spinner head animation:
669 // 1. pause current animation.
···682 ? data?.album.images[0].url
683 : "https://undefined";
684685- // 5. reset the position of the infinite animation
0000686 animations.forEach((anim) => (anim.currentTime = 0));
687688- // 6. if new track is not null then, after 2s
689 if (data)
690 setTimeout(() => {
691- // 7. resume the infinite animation
692 animations.forEach((anim) => anim.play());
693 }, 2000);
694695- // 8. make sure the record is in the right state (playing or paused)
696 elements.player.dataset.playing = data ? "true" : "false";
697 }),
698 );
···92 // flatmap flattens the returned array into the new map
93 .flatMap((x, i) => (i === 0 ? x : [", ", x]))
94 ) : (
95+ // artist defined by default because
96 // i cant be bothered to do client error handling
97 // and this is easier
98 <a href="#">Artist Name</a>
···513 );
514 const addArtists = playing.artists.slice(artistLen);
51500516 let lastValidArtist = elIs(
517 this.elements.artists.children[0],
518 HTMLElement,
···631 const ev = new EventSource("/now-playing-sse");
632633 // close event source safely
634+ window.addEventListener("beforeunload", () => ev.close());
635636 let i = -1;
637 ev.addEventListener("playing", (event) => {
···646 if (!isNowPlaying(data))
647 return console.warn("Unexpected package from server:", data, event.data);
648649+ // data is valid nowPlayingData
650 try {
651+ if (
652+ !(
653+ // first call so assume prev is in an invalid state (which it is)
654+ (
655+ i === 0 ||
656+ // if both are null, quit since re-rendering is pointless
657+ data == prev ||
658+ // now if both are valid play items, so check the ID for equality
659+ (data !== null && prev !== null && data.id === prev.id)
660+ )
661+ )
662+ ) {
663 // there is now a difference between the previous setting and the new setting
664 // so it is worth updating the UI
000665666 // spinner head animation:
667 // 1. pause current animation.
···680 ? data?.album.images[0].url
681 : "https://undefined";
682683+ // 5. update popup
684+ if (data) elements.nowPlaying.updateMetadata(data);
685+ else elements.nowPlaying.nothingPlaying();
686+687+ // 6. reset the position of the infinite animation
688 animations.forEach((anim) => (anim.currentTime = 0));
689690+ // 7. if new track is not null then, after 2s
691 if (data)
692 setTimeout(() => {
693+ // 8. resume the infinite animation
694 animations.forEach((anim) => anim.play());
695 }, 2000);
696697+ // 9. make sure the record is in the right state (playing or paused)
698 elements.player.dataset.playing = data ? "true" : "false";
699 }),
700 );