diff --git a/dashboard_static/js/code.js b/dashboard_static/js/code.js index 34e1f7b..680796a 100644 --- a/dashboard_static/js/code.js +++ b/dashboard_static/js/code.js @@ -82,14 +82,13 @@ function searchForWords(searchWords, tweets){ for (let i = 0; i < tweets.length; i++) { var tweet = tweets[i] for(let i=0; i < searchWords.length; i++){ - console.log(tweet.text.toLowerCase().includes(searchWords[i].toLowerCase())) - if (!tweet.text.toLowerCase().includes(searchWords[i].toLowerCase())) { - tweets.splice(i, 1) + var text = tweet.text.toLowerCase() + var word = searchWords[i].toLowerCase() + if (text.includes(word)) { + filteredTweets.push(tweet) break } } - console.log(tweet, searchWords) - filteredTweets.push(tweet) } return filteredTweets.reverse() } diff --git a/dashboard_static/js/events.js b/dashboard_static/js/events.js index 1943c82..7ebd696 100644 --- a/dashboard_static/js/events.js +++ b/dashboard_static/js/events.js @@ -66,8 +66,8 @@ $(".logo").on("click", function() { }) $(window).on("filter", function() { - var parent = $("div.filtered") - $("div.filtered").innerHTML = "" + var parent = document.querySelector("#filtered") + parent.replaceChildren(); console.debug(filters); diff --git a/dashboard_static/lib/tweets.js b/dashboard_static/lib/tweets.js index 0f45d4a..2e99678 100644 --- a/dashboard_static/lib/tweets.js +++ b/dashboard_static/lib/tweets.js @@ -77,6 +77,7 @@ block.fn.tweets = function(config) { // register default handler for handling tweet data this.actions(function(e, tweet){ + $(window).trigger("filter"); tweets = window.sessionStorage.getItem('tweets'); tweets = JSON.parse(tweets); tweets.push(tweet); @@ -86,15 +87,8 @@ block.fn.tweets = function(config) { } window.sessionStorage.setItem('tweets', JSON.stringify(tweets)); - // remove stale tweets - // if ($list.childElementCount > options.memory) { - // console.log("Deleted") - // // delete last child element - // // $list.removeChild($list.lastChild); - // } + // remove tweets $list.replaceChildren(); - // tweets = filterTweets(tweets, filters.blockedWords, filters.searchedWords + filters.sports, filters.sorted, filters.order); - // tweets = sortTweets(tweets); var displayTweets = tweets.reverse().slice(0, options.memory).reverse(); for (i = 0; i < options.memory-1; i++){ $list.prepend(tweetCell(displayTweets[i]));