Followed in big parts Roberts suggestions

This commit is contained in:
Wolfgang Huß 2019-09-26 11:43:48 +02:00
parent a667d5cd85
commit 0c25b013db
2 changed files with 17 additions and 24 deletions

View File

@ -1,10 +1,12 @@
<template> <template>
<div <div
v-if="totalNotifications <= 0" v-if="totalNotificationsCount === 0"
class="notifications-menu-pointer" class="notifications-menu-pointer"
@click.prevent="updateNotifications" @click.prevent="updateNotifications"
> >
<ds-button class="notifications-menu" disabled icon="bell">{{ unreadNotifications }}</ds-button> <ds-button class="notifications-menu" disabled icon="bell">
{{ unreadNotificationsCount }}
</ds-button>
</div> </div>
<dropdown v-else class="notifications-menu" :placement="placement"> <dropdown v-else class="notifications-menu" :placement="placement">
<template slot="default" slot-scope="{ toggleMenu }"> <template slot="default" slot-scope="{ toggleMenu }">
@ -12,11 +14,11 @@
primary primary
icon="bell" icon="bell"
@click.prevent=" @click.prevent="
toggleMenu()
updateNotifications() updateNotifications()
toggleMenu()
" "
> >
{{ unreadNotifications }} {{ unreadNotificationsCount }}
</ds-button> </ds-button>
</template> </template>
<template slot="popover"> <template slot="popover">
@ -29,7 +31,7 @@
<script> <script>
import Dropdown from '~/components/Dropdown' import Dropdown from '~/components/Dropdown'
import { REFRESH_MILLISEC } from '~/constants/notifications' import { NOTIFICATIONS_POLL_INTERVAL } from '~/constants/notifications'
import { notificationQuery, markAsReadMutation } from '~/graphql/User' import { notificationQuery, markAsReadMutation } from '~/graphql/User'
import NotificationList from '../NotificationList/NotificationList' import NotificationList from '../NotificationList/NotificationList'
@ -48,22 +50,6 @@ export default {
props: { props: {
placement: { type: String }, placement: { type: String },
}, },
watch: {
notifications: {
immediate: true,
handler(lastQueriedNotifications) {
if (lastQueriedNotifications && lastQueriedNotifications.length > 0) {
lastQueriedNotifications.forEach(updatedListNotification => {
const sameNotification = this.displayedNotifications.find(oldListNotification => {
return this.equalNotification(oldListNotification, updatedListNotification)
})
if (!sameNotification) this.displayedNotifications.unshift(updatedListNotification)
})
}
},
},
},
methods: { methods: {
async updateNotifications() { async updateNotifications() {
try { try {
@ -94,10 +80,10 @@ export default {
}, },
}, },
computed: { computed: {
totalNotifications() { totalNotificationsCount() {
return (this.displayedNotifications || []).length return (this.displayedNotifications || []).length
}, },
unreadNotifications() { unreadNotificationsCount() {
let countUnread = 0 let countUnread = 0
if (this.displayedNotifications) { if (this.displayedNotifications) {
this.displayedNotifications.forEach(notification => { this.displayedNotifications.forEach(notification => {
@ -115,6 +101,13 @@ export default {
pollInterval() { pollInterval() {
return NOTIFICATIONS_POLL_INTERVAL return NOTIFICATIONS_POLL_INTERVAL
}, },
update(data) {
const newNotifications = data.notifications.filter(newN => {
return !this.displayedNotifications.find(oldN => this.equalNotification(newN, oldN))
})
this.displayedNotifications = newNotifications.concat(this.displayedNotifications)
return data.notifications
},
}, },
}, },
} }

View File

@ -1 +1 @@
export const REFRESH_MILLISEC = '60000' export const NOTIFICATIONS_POLL_INTERVAL = '60000'