Update item counts on all feeds

This commit is contained in:
Marcus Noble 2020-11-07 16:31:38 +00:00
parent 63777e0db2
commit ef79ee4997

View File

@ -42,8 +42,8 @@
All ({{unread}}) All ({{unread}})
</div> </div>
<div v-for="feed in feeds" :class="{strong: unreadCount(feed), 'alert': true, 'alert-success': selectedFeed == feed.FeedURL }" :data-feed="feed.FeedURL" v-on:click="loadFeed(feed.ID)"> <div v-for="feed in feeds" :class="{strong: unreadCounts[feed.ID], 'alert': true, 'alert-success': selectedFeed == feed.FeedURL }" :data-feed="feed.FeedURL" v-on:click="loadFeed(feed.ID)">
{{feed.Title}} ({{unreadCount(feed)}}) {{feed.Title}} ({{unreadCounts[feed.ID]}})
</div> </div>
<div class="menu"> <div class="menu">
@ -124,6 +124,13 @@
}, },
unread() { unread() {
return this.items.filter(item => !item.Read).length; return this.items.filter(item => !item.Read).length;
},
unreadCounts() {
return this.items.filter(item => !item.Read).reduce((acc, item) => {
if (!acc[item.FeedID]) acc[item.FeedID] = 0;
acc[item.FeedID]++;
return acc;
}, {})
} }
}, },
methods: { methods: {
@ -136,9 +143,6 @@
document.body.classList.toggle('dark'); document.body.classList.toggle('dark');
document.body.classList.toggle('dark-grey'); document.body.classList.toggle('dark-grey');
}, },
unreadCount(feed) {
return this.items.filter(item => item.FeedID == feed.ID).length;
},
loadFeed(feed) { loadFeed(feed) {
this.selectedItem = undefined; this.selectedItem = undefined;
this.selectedFeed = feed; this.selectedFeed = feed;