From d539914212656ac941a29efd9a86bce3e85de446 Mon Sep 17 00:00:00 2001 From: jacktjong Date: Wed, 2 Nov 2022 11:38:17 +0100 Subject: [PATCH] Twitter Live Feed working --- dashboard_static/js/code.js | 30 +++++++++++++++++++++++++++++- template_static/lib/tweets.js | 20 +++++++++++++++++--- 2 files changed, 46 insertions(+), 4 deletions(-) diff --git a/dashboard_static/js/code.js b/dashboard_static/js/code.js index e7c5827..e6c64f5 100644 --- a/dashboard_static/js/code.js +++ b/dashboard_static/js/code.js @@ -22,9 +22,10 @@ function getCSSVariable(name) { return getComputedStyle(root).getPropertyValue(name) } -function tweetCell(tweet, parent) { +function tweetCell(tweet) { var cell = document.createElement("div"); cell.innerHTML = +<<<<<<< Updated upstream '
'+ '' + '
' + @@ -50,6 +51,33 @@ function tweetCell(tweet, parent) { '
'+ '
'; parent.append(cell); +======= + `
+ +
+
+ ${tweet.user.name} + @${tweet.user.screen_name} +
+ ${tweet.text} +
+
+ favorite + ${tweet.favorite_count} +
+
+ repeat + ${tweet.retweet_count} +
+
+ chat_bubble + ${tweet.reply_count} +
+
+
+
` + return cell +>>>>>>> Stashed changes } $(document).on('tweet', console.log(tweet)); diff --git a/template_static/lib/tweets.js b/template_static/lib/tweets.js index 3f8f77d..5fa32a5 100644 --- a/template_static/lib/tweets.js +++ b/template_static/lib/tweets.js @@ -68,18 +68,21 @@ var process_entities = function(message, entities) { block.fn.tweets = function(config) { var options = $.extend({ - memory: 20 + memory: 100 }, config); +<<<<<<< Updated upstream:template_static/lib/tweets.js // create the necessary HTML in the block container //this.$element.append('
    '); +======= +>>>>>>> Stashed changes:dashboard_static/lib/tweets.js // store list for later - var $list = this.$element.find('ol'); - + var $list = $("div.tweetcontainer"); // register default handler for handling tweet data this.actions(function(e, tweet){ +<<<<<<< Updated upstream:template_static/lib/tweets.js var $item = $('
  1. '); var $tweet = $('
    '); @@ -115,6 +118,17 @@ block.fn.tweets = function(config) { $item.append($tweet); // place new tweet in front of list +======= + tweets = window.sessionStorage.getItem('tweets'); + tweets = JSON.parse(tweets); + tweets.push(tweet); + if(tweets.length >= options.memory) { + tweets.shift(); + } + window.sessionStorage.setItem('tweets', JSON.stringify(tweets)); + + var $item = tweetCell(tweet) +>>>>>>> Stashed changes:dashboard_static/lib/tweets.js $list.prepend($item); // remove stale tweets