2018-04-10 03:44:37 +10:00
|
|
|
import Notification from '../notification/notification.vue'
|
2018-08-12 21:14:34 +10:00
|
|
|
import notificationsFetcher from '../../services/notifications_fetcher/notifications_fetcher.service.js'
|
2018-12-29 06:39:54 +11:00
|
|
|
import {
|
|
|
|
notificationsFromStore,
|
|
|
|
visibleNotificationsFromStore,
|
|
|
|
unseenNotificationsFromStore
|
|
|
|
} from '../../services/notification_utils/notification_utils.js'
|
2016-11-28 05:44:56 +11:00
|
|
|
|
|
|
|
const Notifications = {
|
2018-08-12 21:14:34 +10:00
|
|
|
created () {
|
|
|
|
const store = this.$store
|
|
|
|
const credentials = store.state.users.currentUser.credentials
|
|
|
|
|
|
|
|
notificationsFetcher.startFetching({ store, credentials })
|
2016-11-28 05:44:56 +11:00
|
|
|
},
|
|
|
|
computed: {
|
2017-02-19 06:42:00 +11:00
|
|
|
notifications () {
|
2018-12-29 06:39:54 +11:00
|
|
|
return notificationsFromStore(this.$store)
|
2017-02-19 06:42:00 +11:00
|
|
|
},
|
2018-08-21 03:45:54 +10:00
|
|
|
error () {
|
|
|
|
return this.$store.state.statuses.notifications.error
|
|
|
|
},
|
2017-02-19 06:42:00 +11:00
|
|
|
unseenNotifications () {
|
2018-12-29 06:39:54 +11:00
|
|
|
return unseenNotificationsFromStore(this.$store)
|
2017-02-19 06:42:00 +11:00
|
|
|
},
|
2016-11-28 05:44:56 +11:00
|
|
|
visibleNotifications () {
|
2018-12-29 06:39:54 +11:00
|
|
|
return visibleNotificationsFromStore(this.$store)
|
2017-02-19 06:42:00 +11:00
|
|
|
},
|
|
|
|
unseenCount () {
|
|
|
|
return this.unseenNotifications.length
|
|
|
|
}
|
|
|
|
},
|
2017-05-31 18:47:18 +10:00
|
|
|
components: {
|
2018-04-10 03:44:37 +10:00
|
|
|
Notification
|
2017-05-31 18:47:18 +10:00
|
|
|
},
|
2017-02-19 06:42:00 +11:00
|
|
|
watch: {
|
|
|
|
unseenCount (count) {
|
2017-02-19 22:19:47 +11:00
|
|
|
if (count > 0) {
|
|
|
|
this.$store.dispatch('setPageTitle', `(${count})`)
|
|
|
|
} else {
|
|
|
|
this.$store.dispatch('setPageTitle', '')
|
|
|
|
}
|
2017-02-19 06:42:00 +11:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
markAsSeen () {
|
2018-12-02 21:36:11 +11:00
|
|
|
this.$store.dispatch('markNotificationsAsSeen', this.visibleNotifications)
|
2018-08-12 21:14:34 +10:00
|
|
|
},
|
|
|
|
fetchOlderNotifications () {
|
|
|
|
const store = this.$store
|
|
|
|
const credentials = store.state.users.currentUser.credentials
|
|
|
|
notificationsFetcher.fetchAndUpdate({
|
|
|
|
store,
|
|
|
|
credentials,
|
|
|
|
older: true
|
|
|
|
})
|
2016-11-28 05:44:56 +11:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default Notifications
|