mirror of
https://github.com/IT4Change/Ocelot-Social.git
synced 2025-12-13 07:45:56 +00:00
Reduce complexity of notifications watcher
- Co-authored-by: @Tirokk <wolle.huss@pjannto.com>
This commit is contained in:
parent
7727707d49
commit
99dafcda64
@ -84,7 +84,7 @@ describe('NotificationMenu.vue', () => {
|
||||
read: true,
|
||||
post: {
|
||||
id: 'post-3',
|
||||
title: 'red post title',
|
||||
title: 'read post title',
|
||||
contentExcerpt: 'this is yet another post content',
|
||||
author: {
|
||||
id: 'john-1',
|
||||
@ -98,7 +98,7 @@ describe('NotificationMenu.vue', () => {
|
||||
}
|
||||
})
|
||||
|
||||
it('displays the unread number of notifications', () => {
|
||||
it('displays the number of unread notifications', () => {
|
||||
wrapper = Wrapper()
|
||||
expect(wrapper.find('ds-button-stub').text()).toEqual('2')
|
||||
})
|
||||
|
||||
@ -50,32 +50,20 @@ export default {
|
||||
},
|
||||
watch: {
|
||||
notifications: {
|
||||
immediate: true,
|
||||
handler(lastQueriedNotifications) {
|
||||
if (lastQueriedNotifications && lastQueriedNotifications.length > 0) {
|
||||
// set this to be empty to get always called if a query comes with results from the backend
|
||||
// has the sideeffect the handler is encouraged to be called again, but only once with no effect, because of the if above
|
||||
this.notifications = []
|
||||
|
||||
let oldNotifications = this.displayedNotifications
|
||||
const equalNotification = this.equalNotification // because we can not use 'this.equalNotification' in callback
|
||||
|
||||
// add all the new notifications to the oldNotifications at top of the list
|
||||
lastQueriedNotifications.forEach(updatedListNotification => {
|
||||
const sameNotification = oldNotifications.find(function(oldListNotification) {
|
||||
return equalNotification(oldListNotification, updatedListNotification)
|
||||
const sameNotification = this.displayedNotifications.find(oldListNotification => {
|
||||
return this.equalNotification(oldListNotification, updatedListNotification)
|
||||
})
|
||||
if (sameNotification === undefined) {
|
||||
oldNotifications.unshift(updatedListNotification)
|
||||
}
|
||||
if (!sameNotification) this.displayedNotifications.unshift(updatedListNotification)
|
||||
})
|
||||
|
||||
this.displayedNotifications = oldNotifications
|
||||
}
|
||||
},
|
||||
deep: true,
|
||||
immediate: true,
|
||||
},
|
||||
},
|
||||
|
||||
methods: {
|
||||
async updateNotifications() {
|
||||
try {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user