contribution sort control in sidebar
This commit is contained in:
@@ -171,6 +171,7 @@ $news_items = $stmt->fetchAll();
|
||||
<select id="list-sort" class="form-input list-sort-select" onchange="updateContributionsList()">
|
||||
<option value="date-desc">Neueste zuerst</option>
|
||||
<option value="date-asc">Älteste zuerst</option>
|
||||
<option value="category">Nach Kategorie</option>
|
||||
<option value="likes">Meiste Bewertungen</option>
|
||||
<option value="comments">Meiste Kommentare</option>
|
||||
</select>
|
||||
|
||||
@@ -832,10 +832,15 @@ function updateContributionsList() {
|
||||
// Sorts by selected Option
|
||||
var sortBy = document.getElementById('list-sort') ? document.getElementById('list-sort').value : 'date-desc';
|
||||
filtered.sort(function (a, b) {
|
||||
if (sortBy === 'date-desc') return new Date(b.properties.created_at) - new Date(a.properties.created_at);
|
||||
if (sortBy === 'date-asc') return new Date(a.properties.created_at) - new Date(b.properties.created_at);
|
||||
if (sortBy === 'likes') return b.properties.likes_count - a.properties.likes_count;
|
||||
if (sortBy === 'comments') return (b.properties.comment_count || 0) - (a.properties.comment_count || 0);
|
||||
if (sortBy === 'date-desc') return new Date(b.properties.created_at) - new Date(a.properties.created_at);
|
||||
if (sortBy === 'date-asc') return new Date(a.properties.created_at) - new Date(b.properties.created_at);
|
||||
if (sortBy === 'likes') return b.properties.likes_count - a.properties.likes_count;
|
||||
if (sortBy === 'comments') return (b.properties.comment_count || 0) - (a.properties.comment_count || 0);
|
||||
if (sortBy === 'category') {
|
||||
var catA = (CATEGORIES[a.properties.category] || CATEGORIES.other).label;
|
||||
var catB = (CATEGORIES[b.properties.category] || CATEGORIES.other).label;
|
||||
return catA.localeCompare(catB);
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user