From 963a0035e5e3f35ee790aeb3db64cb8dd32a84a4 Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Sat, 18 Feb 2017 20:42:00 +0100 Subject: Make page title dynamic, better notification handling. --- src/components/notifications/notifications.js | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'src/components/notifications/notifications.js') 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) } } } -- cgit v1.2.3-70-g09d2 From 14237cff777acee47cf060aa81823b0dc25f3afa Mon Sep 17 00:00:00 2001 From: hakui Date: Sat, 18 Feb 2017 17:33:00 -0600 Subject: clears notif number from title when marking as read --- src/components/notifications/notifications.js | 1 + 1 file changed, 1 insertion(+) (limited to 'src/components/notifications/notifications.js') diff --git a/src/components/notifications/notifications.js b/src/components/notifications/notifications.js index 7dbbf588..3f9fe3b4 100644 --- a/src/components/notifications/notifications.js +++ b/src/components/notifications/notifications.js @@ -26,6 +26,7 @@ const Notifications = { watch: { unseenCount (count) { this.$store.dispatch('setPageTitle', `(${count})`) + if (count==0) this.$store.dispatch('setPageTitle', '') } }, methods: { -- cgit v1.2.3-70-g09d2 From af913463289d27155993e1621e47ee9a57681079 Mon Sep 17 00:00:00 2001 From: hakui Date: Sat, 18 Feb 2017 17:38:56 -0600 Subject: changed to if-else to save on one line --- src/components/notifications/notifications.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/components/notifications/notifications.js') diff --git a/src/components/notifications/notifications.js b/src/components/notifications/notifications.js index 3f9fe3b4..e872a2e5 100644 --- a/src/components/notifications/notifications.js +++ b/src/components/notifications/notifications.js @@ -25,8 +25,8 @@ const Notifications = { }, watch: { unseenCount (count) { - this.$store.dispatch('setPageTitle', `(${count})`) - if (count==0) this.$store.dispatch('setPageTitle', '') + if (count>0) this.$store.dispatch('setPageTitle', `(${count})`) + else this.$store.dispatch('setPageTitle', '') } }, methods: { -- cgit v1.2.3-70-g09d2 From df3ffdd9056ef7ebe451eaed4beaeafe20257818 Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Sun, 19 Feb 2017 12:19:47 +0100 Subject: Follow style guide (https://github.com/feross/standard) --- src/components/notifications/notifications.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/components/notifications/notifications.js') diff --git a/src/components/notifications/notifications.js b/src/components/notifications/notifications.js index e872a2e5..d6a6bdb5 100644 --- a/src/components/notifications/notifications.js +++ b/src/components/notifications/notifications.js @@ -25,8 +25,11 @@ const Notifications = { }, watch: { unseenCount (count) { - if (count>0) this.$store.dispatch('setPageTitle', `(${count})`) - else this.$store.dispatch('setPageTitle', '') + if (count > 0) { + this.$store.dispatch('setPageTitle', `(${count})`) + } else { + this.$store.dispatch('setPageTitle', '') + } } }, methods: { -- cgit v1.2.3-70-g09d2 From 2933dc30a5de82469ee81720bc78c61f0db7cc4a Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Sun, 19 Feb 2017 13:37:21 +0100 Subject: Only display 10 notifications at a time, 20 is too much. --- src/components/notifications/notifications.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/components/notifications/notifications.js') diff --git a/src/components/notifications/notifications.js b/src/components/notifications/notifications.js index d6a6bdb5..c8d5e212 100644 --- a/src/components/notifications/notifications.js +++ b/src/components/notifications/notifications.js @@ -3,7 +3,7 @@ import { sortBy, take, filter } from 'lodash' const Notifications = { data () { return { - visibleNotificationCount: 20 + visibleNotificationCount: 10 } }, computed: { -- cgit v1.2.3-70-g09d2