2018-04-09 20:44:37 +03:00
|
|
|
import Notification from '../notification/notification.vue'
|
2018-08-12 14:14:34 +03:00
|
|
|
import notificationsFetcher from '../../services/notifications_fetcher/notifications_fetcher.service.js'
|
2018-12-28 21:39:54 +02:00
|
|
|
import {
|
|
|
|
notificationsFromStore,
|
|
|
|
visibleNotificationsFromStore,
|
|
|
|
unseenNotificationsFromStore
|
|
|
|
} from '../../services/notification_utils/notification_utils.js'
|
2016-11-27 19:44:56 +01:00
|
|
|
|
|
|
|
const Notifications = {
|
2019-03-14 17:46:04 +02:00
|
|
|
props: [
|
|
|
|
'noHeading'
|
|
|
|
],
|
2019-01-29 21:04:52 +02:00
|
|
|
data () {
|
|
|
|
return {
|
|
|
|
bottomedOut: false
|
|
|
|
}
|
|
|
|
},
|
2016-11-27 19:44:56 +01:00
|
|
|
computed: {
|
2017-02-18 20:42:00 +01:00
|
|
|
notifications () {
|
2018-12-28 21:39:54 +02:00
|
|
|
return notificationsFromStore(this.$store)
|
2017-02-18 20:42:00 +01:00
|
|
|
},
|
2018-08-20 20:45:54 +03:00
|
|
|
error () {
|
|
|
|
return this.$store.state.statuses.notifications.error
|
|
|
|
},
|
2017-02-18 20:42:00 +01:00
|
|
|
unseenNotifications () {
|
2018-12-28 21:39:54 +02:00
|
|
|
return unseenNotificationsFromStore(this.$store)
|
2017-02-18 20:42:00 +01:00
|
|
|
},
|
2016-11-27 19:44:56 +01:00
|
|
|
visibleNotifications () {
|
2018-12-28 21:39:54 +02:00
|
|
|
return visibleNotificationsFromStore(this.$store)
|
2017-02-18 20:42:00 +01:00
|
|
|
},
|
|
|
|
unseenCount () {
|
|
|
|
return this.unseenNotifications.length
|
2019-01-29 21:04:52 +02:00
|
|
|
},
|
|
|
|
loading () {
|
|
|
|
return this.$store.state.statuses.notifications.loading
|
2017-02-18 20:42:00 +01:00
|
|
|
}
|
|
|
|
},
|
2017-05-31 11:47:18 +03:00
|
|
|
components: {
|
2018-04-09 20:44:37 +03:00
|
|
|
Notification
|
2017-05-31 11:47:18 +03:00
|
|
|
},
|
2017-02-18 20:42:00 +01:00
|
|
|
watch: {
|
|
|
|
unseenCount (count) {
|
2017-02-19 12:19:47 +01:00
|
|
|
if (count > 0) {
|
|
|
|
this.$store.dispatch('setPageTitle', `(${count})`)
|
|
|
|
} else {
|
|
|
|
this.$store.dispatch('setPageTitle', '')
|
|
|
|
}
|
2017-02-18 20:42:00 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
markAsSeen () {
|
2019-03-12 17:16:57 -04:00
|
|
|
this.$store.dispatch('markNotificationsAsSeen')
|
|
|
|
},
|
2018-08-12 14:14:34 +03:00
|
|
|
fetchOlderNotifications () {
|
2019-05-03 07:52:22 -04:00
|
|
|
if (this.loading) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-08-12 14:14:34 +03:00
|
|
|
const store = this.$store
|
|
|
|
const credentials = store.state.users.currentUser.credentials
|
2019-01-29 21:04:52 +02:00
|
|
|
store.commit('setNotificationsLoading', { value: true })
|
2018-08-12 14:14:34 +03:00
|
|
|
notificationsFetcher.fetchAndUpdate({
|
|
|
|
store,
|
|
|
|
credentials,
|
|
|
|
older: true
|
2019-01-29 21:04:52 +02:00
|
|
|
}).then(notifs => {
|
|
|
|
store.commit('setNotificationsLoading', { value: false })
|
|
|
|
if (notifs.length === 0) {
|
|
|
|
this.bottomedOut = true
|
|
|
|
}
|
2018-08-12 14:14:34 +03:00
|
|
|
})
|
2016-11-27 19:44:56 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default Notifications
|