From 963a0035e5e3f35ee790aeb3db64cb8dd32a84a4 Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Sat, 18 Feb 2017 20:42:00 +0100 Subject: [PATCH] Make page title dynamic, better notification handling. --- src/components/notifications/notifications.js | 26 +++++++++++++++++-- .../notifications/notifications.vue | 5 ++-- src/modules/config.js | 7 +++-- src/modules/statuses.js | 7 ++++- 4 files changed, 38 insertions(+), 7 deletions(-) diff --git a/src/components/notifications/notifications.js b/src/components/notifications/notifications.js index 10f987a8..7dbbf588 100644 --- a/src/components/notifications/notifications.js +++ b/src/components/notifications/notifications.js @@ -1,4 +1,4 @@ -import { sortBy, take } from 'lodash' +import { sortBy, take, filter } from 'lodash' const Notifications = { data () { @@ -7,8 +7,30 @@ const Notifications = { } }, computed: { + notifications () { + return this.$store.state.statuses.notifications + }, + unseenNotifications () { + return filter(this.notifications, ({seen}) => !seen) + }, visibleNotifications () { - return take(sortBy(this.$store.state.statuses.notifications, ({action}) => -action.id), this.visibleNotificationCount) + // Don't know why, but sortBy([seen, -action.id]) doesn't work. + let sortedNotifications = sortBy(this.notifications, ({action}) => -action.id) + sortedNotifications = sortBy(sortedNotifications, 'seen') + return take(sortedNotifications, this.visibleNotificationCount) + }, + unseenCount () { + return this.unseenNotifications.length + } + }, + watch: { + unseenCount (count) { + this.$store.dispatch('setPageTitle', `(${count})`) + } + }, + methods: { + markAsSeen () { + this.$store.commit('markNotificationsAsSeen', this.visibleNotifications) } } } diff --git a/src/components/notifications/notifications.vue b/src/components/notifications/notifications.vue index 0846c27b..785cc019 100644 --- a/src/components/notifications/notifications.vue +++ b/src/components/notifications/notifications.vue @@ -1,13 +1,14 @@