From: Chris Fulljames Date: Sun, 26 Jan 2025 23:02:25 +0000 (-0500) Subject: More work on comments X-Git-Url: https://littlesong.place/gitweb/gitweb.cgi?a=commitdiff_plain;h=ba36a77cded5813c065581e5be3f65de44c2d97e;p=littlesongplace.git More work on comments --- diff --git a/main.py b/main.py index e390285..244d889 100644 --- a/main.py +++ b/main.py @@ -489,9 +489,9 @@ def comment_get(): abort(401) # Must be logged in comment = None - if "commentid" in request.args: - commentid = request.args["commentid"] - comment = query_db("select * from song_comments inner join users on song_comments.userid == users.userid where commentid = ?", [commentid], one=True) + if "replytoid" in request.args: + replytoid = request.args["replytoid"] + comment = query_db("select * from song_comments inner join users on song_comments.userid == users.userid where commentid = ?", [replytoid], one=True) session["previous_page"] = request.referrer return render_template("comment.html", song=song, comment=comment) @@ -507,9 +507,9 @@ def comment_post(): abort(404) # Invald songid comment = None - if "commentid" in request.args: - commentid = request.args["commentid"] - comment = query_db("select * from song_comments inner join users on song_comments.userid == users.userid where commentid = ?", [commentid], one=True) + if "replytoid" in request.args: + replytoid = request.args["replytoid"] + comment = query_db("select * from song_comments inner join users on song_comments.userid == users.userid where commentid = ?", [replytoid], one=True) if not comment: abort(404) # Invalid comment @@ -521,7 +521,7 @@ def comment_post(): content = request.form["content"] userid = session["userid"] songid = request.args["songid"] - replytoid = request.args.get("commentid", None) + replytoid = request.args.get("replytoid", None) query_db( "insert into song_comments (songid, userid, replytoid, created, content) values (?, ?, ?, ?, ?)", args=[songid, userid, replytoid, timestamp, content]) @@ -607,6 +607,7 @@ class Song: comments = query_db("select * from song_comments inner join users on song_comments.userid == users.userid where songid = ?", [self.songid]) # Top-level comments song_comments = sorted([dict(c) for c in comments if c["replytoid"] is None], key=lambda c: c["created"]) + song_comments = list(reversed(song_comments)) # Replies (can only reply to top-level) for comment in song_comments: comment["replies"] = sorted([c for c in comments if c["replytoid"] == comment["commentid"]], key=lambda c: c["created"]) diff --git a/static/styles.css b/static/styles.css index 3745edb..e6a7de8 100644 --- a/static/styles.css +++ b/static/styles.css @@ -215,6 +215,31 @@ div.song-tags { margin: 10px; } +div.song-comments { + margin: 10px; +} + +div.top-level-comment { + margin-top: 10px; + padding: 10px; + box-shadow: 0px 0px 5px 0px; + border-radius: 10px; +} + +div.reply-comment { + margin-top: 10px; + margin-bottom: 10px; + padding: 10px; + box-shadow: 0px 0px 5px 0px; + border-radius: 10px; +} + +div.comment-button-container { + display: flex; + gap: 10px; + margin-top: 10px; +} + [hidden] { display: none !important; } diff --git a/templates/song-list.html b/templates/song-list.html index 4809f9f..206bbf8 100644 --- a/templates/song-list.html +++ b/templates/song-list.html @@ -65,22 +65,70 @@
- Comments: + Comments:
Add a Comment {% for comment in song.get_comments() %}
- {{ comment['username'] }} -

{{ comment['content'] }}

+ + {{ comment['username'] }}: + {{ comment['content'] }} + + {% if session['userid'] == comment['userid'] or session['userid'] == song.userid %} +
+ {% endif %} + + + {% if session['userid'] == comment['userid'] %} + + Edit + + {% endif %} + + + {% if session['userid'] == comment['userid'] or session['userid'] == song.userid %} + + Delete + + {% endif %} + + {% if session['userid'] == comment['userid'] or session['userid'] == song.userid %} +
+ {% endif %} {% for reply in comment['replies'] %}
- {{ reply['username'] }} -

{{ reply['content'] }}

+ + {{ reply['username'] }}: + {{ reply['content'] }} + + {% if session['userid'] == reply['userid'] or session['userid'] == song.userid %} +
+ {% endif %} + + + {% if session['userid'] == reply['userid'] %} + + Edit + + {% endif %} + + + {% if session['userid'] == reply['userid'] or session['userid'] == song.userid %} + + Delete + + {% endif %} + + {% if session['userid'] == reply['userid'] or session['userid'] == song.userid %} +
+ {% endif %}
{% endfor %} - Reply +
+ Reply +
{% endfor %}