From 21064b3d240c4a72301111920bb6b72bee54fb3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20Hn=C3=A1t?= Date: Thu, 3 Nov 2022 16:55:45 +0100 Subject: [PATCH] maybe working sort --- dashboard_static/js/code.js | 5 ++++- dashboard_static/js/events.js | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/dashboard_static/js/code.js b/dashboard_static/js/code.js index df51121..faa2d2a 100644 --- a/dashboard_static/js/code.js +++ b/dashboard_static/js/code.js @@ -93,6 +93,7 @@ function searchForWords(searchWords, tweets){ } function sortTweets(tweets, sort){ + console.log(sort) if(typeof sort.sortby == 'undefined'){ return tweets } @@ -121,10 +122,12 @@ function sortTweets(tweets, sort){ tweets.sort(function(a,b){return a.reply_count-b.reply_count}) } } - if (sort.sortby == "date"){ + if (sort.sortby == "time"){ if(sort.order == 'asc'){ + console.log("asc") tweets.sort(function(a,b){return Date(b.created_at)-Date(a.reply_count)}) } else{ + console.log("desc") tweets.sort(function(a,b){return Date(a.created_at)-Date(b.reply_count)}) } } diff --git a/dashboard_static/js/events.js b/dashboard_static/js/events.js index 42f5928..50d0ea4 100644 --- a/dashboard_static/js/events.js +++ b/dashboard_static/js/events.js @@ -78,7 +78,7 @@ $(window).on("filter", function() { tweets = window.sessionStorage.getItem('tweets'); tweets = JSON.parse(tweets); tweets = filterTweets(tweets, filters.blockedWords, filters.searchedWords.concat(filters.sports), filters.sorted, filters.order); - tweets = sortTweets(tweets, [filters.sorted, filters.order]); + tweets = sortTweets(tweets, {"sortby":filters.sorted, "order":filters.order}); var displayTweets = tweets.reverse().slice(0, 20).reverse(); if(tweetCell(displayTweets[0]) != lastTweet){ parent.replaceChildren();