]> littlesong.place Git - littlesongplace.git/commitdiff
More work on playlist UI
authorChris Fulljames <christianfulljames@gmail.com>
Fri, 14 Feb 2025 12:33:38 +0000 (07:33 -0500)
committerChris Fulljames <christianfulljames@gmail.com>
Fri, 14 Feb 2025 12:33:38 +0000 (07:33 -0500)
main.py
templates/song-list.html
todo.txt

diff --git a/main.py b/main.py
index 0f2f5cd4968a75553a67932e575e23cf68880f14..9c9f1b01257017412324eaa9cdfbd9c302a7702f 100644 (file)
--- a/main.py
+++ b/main.py
@@ -738,12 +738,17 @@ def delete_playlist(playlistid):
     flash_and_log(f"Deleted playlist {plist_data['name']}", "success")
     return redirect(request.referrer)
 
-@app.post("/append-to-playlist/<int:playlistid>")
-def append_to_playlist(playlistid):
+@app.post("/append-to-playlist")
+def append_to_playlist():
     if not "userid" in session:
         abort(401)
 
     # Make sure playlist exists
+    try:
+        playlistid = int(request.form["playlistid"])
+    except ValueError:
+        abort(400)
+
     plist_data = query_db("select * from playlists where playlistid = ?", args=[playlistid])
     if not plist_data:
         abort(404)
@@ -752,7 +757,7 @@ def append_to_playlist(playlistid):
     if session["userid"] != plist_data["userid"]:
         abort(401)
 
-    songid = request.args["songid"]
+    songid = request.form["songid"]
 
     # Make sure song exists
     song_data = query_db("select * from songs where songid = ?", args=[songid])
index 0aa815f4eb842f19f7251b80edfded3a808d2f6f..168721f4b897cbf0e7c091fd4932f2ba75ebbcb7 100644 (file)
     </div>
 {% endfor %}
 
+    {% if playlists -%}
     <!-- Playlist selector, shown when Add to Playlist is clicked -->
     <div class="playlist-selector" hidden>
-        <!-- TODO -->
+        <form>
+            <input type="hidden" name="songid" value="-1" id="playlist-selector-songid"/>
+            <select name="playlistid">
+                {% for plist in playlists -%}
+                <option value="{{ plist.playlistid }}">{{ plist.name }}</option>
+                {%- endfor %}
+            </select>
+            <input type="submit" value="submit" />
+        </form>
     </div>
+    {%- endif %}
 </div>
 
 <script>
@@ -180,12 +190,16 @@ function showDetails(event) {
     return false;
 }
 
+{% if playlists %}
 var m_addToPlaylistSongid = null;
 function showPlaylistSelector(event, songid) {
     m_addToPlaylistSongid = songid;
     var songList = event.target.closest(".song-list");
     var playlistSelector = songList.querySelector(".playlist-selector");
     playlistSelector.hidden = false;
+    var songidInput = playlistSelector.querySelector("#playlist-selector-songid")
+    songInput.value = songid
     return false;
 }
+{% endif $}
 </script>
index 16eded905fcbced4cbba6019cc0a6117583710df..397801773b4c28f58a5292537b4ce0ed1218d091 100644 (file)
--- a/todo.txt
+++ b/todo.txt
@@ -1,5 +1,13 @@
 NOW
-- Apply user colors to songs in lists outside profile
+- Playlists:
+    - Create
+    - Play
+    - Remove song
+    - Reorder songs
+    - Delete
+    - Pin to profile
+    - Albums?
+- Show upload date in song list
 
 SOON
 - Player minimize button
@@ -11,14 +19,6 @@ SOON
     - Remove songs
     - Reorder songs
     - Automatically use songs on page when queue ends
-- Playlists:
-    - Create
-    - Play
-    - Remove song
-    - Reorder songs
-    - Delete
-    - Pin to profile
-    - Albums?
 
 LATER
 - Show song info for song in player (description, tags)