Aevann 2024-04-20 20:13:34 +02:00
parent 94ea55b507
commit cadf2de31e
10 changed files with 18 additions and 10 deletions

View File

@ -438,6 +438,7 @@ POST_SORTS = COMMENT_SORTS | {
"subscriptions": "bell",
"saves": "save"
}
COMMENT_SORTS = COMMENT_SORTS | {"saves": "save"}
################################################################################
### COLUMN INFO

View File

@ -47,6 +47,8 @@ def sort_objects(sort, objects, cls):
return objects.outerjoin(Subscription, Subscription.post_id == cls.id).group_by(cls.id).order_by(func.count(Subscription.post_id).desc(), cls.created_utc.desc())
elif sort == "saves" and cls.__name__ == "Post":
return objects.outerjoin(SaveRelationship, SaveRelationship.post_id == cls.id).group_by(cls.id).order_by(func.count(SaveRelationship.post_id).desc(), cls.created_utc.desc())
elif sort == "saves" and cls.__name__ == "Comment":
return objects.outerjoin(CommentSaveRelationship, CommentSaveRelationship.comment_id == cls.id).group_by(cls.id).order_by(func.count(CommentSaveRelationship.comment_id).desc(), cls.created_utc.desc())
elif sort == "new":
return objects.order_by(cls.created_utc.desc())
elif sort == "old":

View File

@ -86,7 +86,7 @@
</form>
{{- macros.time_filter_buttons() -}}
{{- macros.sorting_buttons(POST_SORTS, True) -}}
{{- macros.sorting_buttons(POST_SORTS, True, True) -}}
</div>
{% endblock %}
</div>

View File

@ -8,7 +8,7 @@
<div class="d-flex justify-content-between align-items-center mt-1 mb-2">
<div class="d-flex px-2 align-items-center mt-4">
{{- macros.time_filter_buttons() -}}
{{- macros.sorting_buttons(COMMENT_SORTS) -}}
{{- macros.sorting_buttons(COMMENT_SORTS, True) -}}
</div>
</div>

View File

@ -330,7 +330,7 @@
<div class="row border-md-0 comment-section pb-3">
<div class="col border-top">
<div class="comments-count py-3">
{{- macros.sorting_buttons(COMMENT_SORTS, True) -}}
{{- macros.sorting_buttons(COMMENT_SORTS, False, True) -}}
</div>
{{macros.comment_reply_box(p.fullname, 'comment-reply-' + p.fullname, subwrapper_css_classes='mb-3', enable_cancel_button=false)}}

View File

@ -49,7 +49,7 @@
</div>
<div class="comments-count py-3">
{{- macros.sorting_buttons(COMMENT_SORTS, True) -}}
{{- macros.sorting_buttons(COMMENT_SORTS, False, True) -}}
</div>
<div class="comment-section">

View File

@ -105,9 +105,9 @@
<div class="mt-3 d-flex align-items-center fl-r">
{{- macros.time_filter_buttons() -}}
{% if "/posts" in request.path %}
{{- macros.sorting_buttons(POST_SORTS) -}}
{{- macros.sorting_buttons(POST_SORTS, True) -}}
{% else %}
{{- macros.sorting_buttons(COMMENT_SORTS) -}}
{{- macros.sorting_buttons(COMMENT_SORTS, True) -}}
{% endif %}
</div>
{% endif %}

View File

@ -66,7 +66,7 @@
<p>Change the default sorting for comments.</p>
<div class="input-group">
<select autocomplete="off" id='defaultsortingcomments' class="form-control setting_select" data-nonce="{{g.nonce}}" form="profile-settings" name="defaultsortingcomments">
{% for entry in COMMENT_SORTS.keys() %}
{% for entry in COMMENT_SORTS.keys() - ['saves'] %}
<option value="{{entry}}"{{' selected' if v.defaultsortingcomments == entry}}>{{entry}}</option>
{% endfor %}
</select>

View File

@ -32,9 +32,9 @@
<div class="d-flex align-items-center">
{{- macros.time_filter_buttons() -}}
{% if "/posts" in request.path %}
{{- macros.sorting_buttons(POST_SORTS) -}}
{{- macros.sorting_buttons(POST_SORTS, True) -}}
{% else %}
{{- macros.sorting_buttons(COMMENT_SORTS) -}}
{{- macros.sorting_buttons(COMMENT_SORTS, True) -}}
{% endif %}
</div>
</div>

View File

@ -400,7 +400,7 @@
</div>
{% endmacro %}
{% macro sorting_buttons(sorts, hot_allowed) %}
{% macro sorting_buttons(sorts, saves_allowed, hot_allowed) %}
<div class="dropdown dropdown-actions">
<button type="button" class="btn btn-secondary dropdown-toggle" id="dropdownMenuButton2" data-bs-toggle="dropdown">
<i class="fas fa-{{sorts[sort]}} mr-1"></i>
@ -408,6 +408,11 @@
</button>
<div class="dropdown-menu" x-placement="bottom-start" style="position: absolute; will-change: transform; top: 0px; left: 0px">
{% set sorts = sorts.items()|list %}
{% if not saves_allowed %}
{% set sorts = sorts[:-1] %}
{% endif %}
{% if not hot_allowed %}
{% set sorts = sorts[1:] %}
{% endif %}