]> littlesong.place Git - littlesongplace.git/commitdiff
Add delete confirmation, fix play button
authorChris Fulljames <christianfulljames@gmail.com>
Sun, 12 Jan 2025 17:39:19 +0000 (12:39 -0500)
committerChris Fulljames <christianfulljames@gmail.com>
Sun, 12 Jan 2025 17:39:19 +0000 (12:39 -0500)
main.py
static/player.js
templates/song-list.html

diff --git a/main.py b/main.py
index 7783812bbc3545d177336cb8bc19455343061f05..b3d0ba67a009e0fd2fa4c3ae2888461120258f8a 100644 (file)
--- 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/<userid>/<songid>")
index 5fa54e715024306b62f6dfab68411f1c3376094a..b9fbc951844fb677c981445f5cca26115b62b60d 100644 (file)
@@ -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);
     }
 });
index 1f9bd195e8353ec8e254205e511c1c275ea11694..af59a11e392d3891fa13d1318bfb0808859be3f8 100644 (file)
@@ -34,7 +34,7 @@
                 <a href="/edit-song?songid={{ song.songid }}">Edit</a>
                 </div>
                 <div class="song-delete-button">
-                <a href="/delete-song/{{ song.userid }}/{{ song.songid }}">Delete</a>
+                <a href="/delete-song/{{ song.userid }}/{{ song.songid }}" onclick="return confirm(&#34;Are you sure you want to delete this song?&#34;)">Delete</a>
                 </div>
                 {% endif %}