UI to let people change comment sort order

This commit is contained in:
rimu 2024-01-07 22:28:13 +13:00
parent 6846902480
commit 7ad2781eb5
2 changed files with 16 additions and 3 deletions

View file

@ -29,8 +29,10 @@ def show_post(post_id: int):
if community.banned:
abort(404)
sort = request.args.get('sort', 'top')
# If nothing has changed since their last visit, return HTTP 304
current_etag = f"{post.id}_{hash(post.last_active)}"
current_etag = f"{post.id}{sort}_{hash(post.last_active)}"
if current_user.is_anonymous and request_etag_matches(current_etag):
return return_304(current_etag)
@ -165,7 +167,7 @@ def show_post(post_id: int):
return redirect(url_for('activitypub.post_ap', post_id=post_id)) # redirect to current page to avoid refresh resubmitting the form
else:
replies = post_replies(post.id, 'top')
replies = post_replies(post.id, sort)
form.notify_author.data = True
og_image = post.image.source_url if post.image_id else None

View file

@ -44,8 +44,19 @@
<p>{{ _('Comments are disabled.') }}</p>
{% endif %}
{% if replies %}
<div class="row post_replies">
<div id="post_replies" class="row">
<div class="col">
<div class="btn-group mt-1 mb-2">
<a href="?sort=hot#submit" title="{{ _('Sort by magic') }}" class="btn btn-sm {{ 'btn-primary' if request.args.get('sort', '') == '' or request.args.get('sort', '') == 'hot' else 'btn-outline-secondary' }}" rel="nofollow">
{{ _('Hot') }}
</a>
<a href="?sort=top#submit" title="{{ _('Comments with the most upvotes') }}" class="btn btn-sm {{ 'btn-primary' if request.args.get('sort', '') == 'top' else 'btn-outline-secondary' }}" rel="nofollow">
{{ _('Top') }}
</a>
<a href="?sort=new#submit" title="{{ _('Show newest first') }}" class="btn btn-sm {{ 'btn-primary' if request.args.get('sort', '') == 'new' else 'btn-outline-secondary' }}" rel="nofollow">
{{ _('New') }}
</a>
</div>
{% macro render_comment(comment) %}
<div id="comment_{{ comment['comment'].id }}" class="comment {% if comment['comment'].score <= -10 %}low_score{% endif %}
{% if comment['comment'].author.id == post.author.id %}original_poster{% endif %}">