pleroma-fe/src/components/notifications/notifications.js

62 lines
1.6 KiB
JavaScript
Raw Normal View History

import Notification from '../notification/notification.vue'
import notificationsFetcher from '../../services/notifications_fetcher/notifications_fetcher.service.js'
import {
notificationsFromStore,
visibleNotificationsFromStore,
unseenNotificationsFromStore
} from '../../services/notification_utils/notification_utils.js'
2016-11-28 05:44:56 +11:00
const Notifications = {
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: {
notifications () {
return notificationsFromStore(this.$store)
},
2018-08-21 03:45:54 +10:00
error () {
return this.$store.state.statuses.notifications.error
},
unseenNotifications () {
return unseenNotificationsFromStore(this.$store)
},
2016-11-28 05:44:56 +11:00
visibleNotifications () {
return visibleNotificationsFromStore(this.$store)
},
unseenCount () {
return this.unseenNotifications.length
}
},
components: {
Notification
},
watch: {
unseenCount (count) {
if (count > 0) {
this.$store.dispatch('setPageTitle', `(${count})`)
} else {
this.$store.dispatch('setPageTitle', '')
}
}
},
methods: {
markAsSeen () {
this.$store.dispatch('markNotificationsAsSeen', this.visibleNotifications)
},
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