diff --git a/js/App.js b/js/App.js index 9601734..70e9dbe 100644 --- a/js/App.js +++ b/js/App.js @@ -227,46 +227,52 @@ App.prototype.validate = function(articles) { return false; }; +// Utility function to toggle feed content visibility +function toggleFeed(feedid) { + var e = document.getElementById("feed" + feedid.toString()); + if (e.style.display == "none") { + e.style.display = ""; + } else { + e.style.display = "none"; + } +} + App.prototype.populateList = function() { - // First pull all articles together from each distinct feed - var ua = this.unread_articles; - var newarts = [], byfeed = []; - while (ua.length > 0) { - article = ua[0]; + // Tabulate all articles, grouped by feed. + // Note that this.unread_articles[] can be growing even + // as our user reads, so we have to leave it alone and + // just point to the appropriate articles in situ. + const ua = this.unread_articles, ual = ua.length; + const byfeed = {}, feeds = []; + for (let x = 0; x < ual; ++x) { + const article = ua[x]; - // Next feed ID - var fid = article.feed_id; - // Here's all the articles under that ID - var feeds = - ua.filter( function(a) { return a.feed_id == fid; } ); - // Keep a list of them so it's easy to tabulate - byfeed.push(feeds); - - // Add them on to the new unread_articles, so they're - // in order. - newarts = newarts.concat(feeds); - - // Trim them off the old, unsorted article list - ua = ua.filter( function(a) { return a.feed_id != fid; } ); + // Add this article to an existing feed list, or + // or start one for this feed ID. + const fid = article.feed_id; + if (fid in byfeed) { + byfeed[fid].push(x); + } else { + byfeed[fid] = [x]; + feeds.push( {"fid": fid, "name": article.feed_title} ); + } } - // Make the reordered article list the "official" one - ua = this.unread_articles = newarts; - // Now build the article list; it's a