From: Chris Fulljames Date: Sun, 12 Jan 2025 17:39:19 +0000 (-0500) Subject: Add delete confirmation, fix play button X-Git-Url: https://littlesong.place/gitweb/gitweb.cgi?a=commitdiff_plain;h=0684afad0e913d8570b70e06a5b181d16df56de8;p=littlesongplace.git Add delete confirmation, fix play button --- diff --git a/main.py b/main.py index 7783812..b3d0ba6 100644 --- a/main.py +++ b/main.py @@ -361,7 +361,9 @@ def delete_song(userid, songid): if int(userid) != session["userid"]: abort(401) - if not query_db("select * from songs where songid = ?", [songid]): + song_data = query_db("select * from songs where songid = ?", [songid], one=True) + + if not song_data: abort(404) # Song doesn't exist # Delete tags, collaborators @@ -377,6 +379,8 @@ def delete_song(userid, songid): if songpath.exists(): os.remove(songpath) + flash(f"Deleted {song_data['title']}") + return redirect(request.referrer) @app.get("/song//") diff --git a/static/player.js b/static/player.js index 5fa54e7..b9fbc95 100644 --- a/static/player.js +++ b/static/player.js @@ -3,13 +3,14 @@ var m_songIndex = 0; // Play a new song from the list in the player function play(event) { - var song = event.target.parentElement; + var song = event.target.parentElement.parentElement.parentElement; m_songIndex = m_allSongs.indexOf(song); playCurrentSong(); } function playCurrentSong() { var song = m_allSongs[m_songIndex]; + console.log(song); var songData = JSON.parse(song.dataset.song); var audio = document.getElementById("player-audio"); @@ -156,7 +157,7 @@ document.addEventListener("DOMContentLoaded", (event) => { // Song play for (const element of document.getElementsByClassName("song-play-button")) { - m_allSongs.push(element.parentElement); + m_allSongs.push(element.parentElement.parentElement.parentElement); element.addEventListener("click", play); } }); diff --git a/templates/song-list.html b/templates/song-list.html index 1f9bd19..af59a11 100644 --- a/templates/song-list.html +++ b/templates/song-list.html @@ -34,7 +34,7 @@ Edit {% endif %}