diff --git a/light9/ascoltami/index.html b/light9/ascoltami/index.html --- a/light9/ascoltami/index.html +++ b/light9/ascoltami/index.html @@ -41,11 +41,6 @@ - -
Running on
diff --git a/light9/ascoltami/main.ts b/light9/ascoltami/main.ts --- a/light9/ascoltami/main.ts +++ b/light9/ascoltami/main.ts @@ -29,12 +29,17 @@ async function onLoad() { } byId("currentTime").innerText = data.t.toFixed(1); byId("leftTime").innerText = (data.duration - data.t).toFixed(1); - byId("leftAutoStopTime").innerText = Math.max(0, data.duration - times.post - data.t).toFixed(1); + byId("leftAutoStopTime").innerText = Math.max( + 0, + data.duration - times.post - data.t + ).toFixed(1); byId("states").innerText = JSON.stringify(data.state); currentDuration = data.duration; // document.querySelector("#timeSlider").slider({ value: data.t, max: data.duration }); if (data.playing != lastPlaying) { - document.querySelectorAll(".playMode").forEach((e: Element) => e.classList.remove("active")); + document + .querySelectorAll(".playMode") + .forEach((e: Element) => e.classList.remove("active")); byId(data.playing ? "cmd-play" : "cmd-stop").classList.add("active"); lastPlaying = data.playing; } @@ -42,38 +47,47 @@ async function onLoad() { } function showCurrentSong(uri: string) { - document.querySelectorAll(".songs div").forEach((row: Element, i: number) => { - if (row.querySelector("button")!.dataset.uri == uri) { - row.classList.add("currentSong"); - } else { - row.classList.remove("currentSong"); - } - }); + document + .querySelectorAll(".songs div") + .forEach((row: Element, i: number) => { + if (row.querySelector("button")!.dataset.uri == uri) { + row.classList.add("currentSong"); + } else { + row.classList.remove("currentSong"); + } + }); currentHighlightedSong = uri; } - const data = await (await fetch('api/songs')).json() - data.songs.forEach((song)=> { - const button = document.createElement("button"); - // link is just for dragging, not clicking - const link = document.createElement("a"); - link.appendChild($("").addClass("num").text(song.label.slice(0, 2))); - link.appendChild($("").addClass("song-name").text(song.label.slice(2).trim())); - link.setAttribute("href", song.uri); - link.addEventListener("click", (ev) => { - ev.stopPropagation() - button.click(); - }); - button.appendChild(link); - button.dataset.uri=(song); - button.click(function () { - fetch('api/song', {method: 'POST', body: song$.post("song", button.data("uri"), function (data, textStatus, xhr) { - showCurrentSong(song.uri); - }); - }); - $(".songs").append($("