2023-03-24 17:42:37 +08:00
|
|
|
<template>
|
|
|
|
<div class="sci--navigation--notificaitons-flyout">
|
|
|
|
<div class="sci--navigation--notificaitons-flyout-title">
|
|
|
|
{{ i18n.t('nav.notifications.title') }}
|
2023-06-08 23:33:50 +08:00
|
|
|
<i class="sn-icon sn-icon-close" @click="$emit('close')"></i>
|
2023-03-24 17:42:37 +08:00
|
|
|
</div>
|
|
|
|
<div class="sci--navigation--notificaitons-flyout-tabs">
|
|
|
|
<div class="sci--navigation--notificaitons-flyout-tab"
|
2023-04-12 17:14:53 +08:00
|
|
|
:data-unseen="unseenNotificationsCount"
|
2023-04-06 20:57:00 +08:00
|
|
|
@click="setActiveTab('all')"
|
2023-04-12 17:14:53 +08:00
|
|
|
:class="{'active': activeTab == 'all', 'has-unseen': unseenNotificationsCount > 0}">
|
2023-03-24 17:42:37 +08:00
|
|
|
{{ i18n.t('nav.notifications.all') }}
|
|
|
|
</div>
|
|
|
|
<div class="sci--navigation--notificaitons-flyout-tab"
|
2023-04-06 20:57:00 +08:00
|
|
|
@click="setActiveTab('message')"
|
2023-03-24 17:42:37 +08:00
|
|
|
:class="{'active': activeTab == 'message'}">
|
|
|
|
{{ i18n.t('nav.notifications.message') }}
|
|
|
|
</div>
|
|
|
|
<div class="sci--navigation--notificaitons-flyout-tab"
|
2023-04-06 20:57:00 +08:00
|
|
|
@click="setActiveTab('system')"
|
2023-03-24 17:42:37 +08:00
|
|
|
:class="{'active': activeTab == 'system'}">
|
|
|
|
{{ i18n.t('nav.notifications.system') }}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<hr>
|
2023-04-07 19:59:06 +08:00
|
|
|
<perfect-scrollbar ref="scrollContainer" class="sci--navigation--notificaitons-flyout-notifications">
|
2023-03-24 17:42:37 +08:00
|
|
|
<div class="sci-navigation--notificaitons-flyout-subtitle" v-if="todayNotifications.length" >
|
|
|
|
{{ i18n.t('nav.notifications.today') }}
|
|
|
|
</div>
|
2023-04-06 20:57:00 +08:00
|
|
|
<NotificationItem v-for="notification in todayNotifications" :key="notification.type_of + '-' + notification.id" :notification="notification" />
|
2023-03-24 17:42:37 +08:00
|
|
|
<div class="sci-navigation--notificaitons-flyout-subtitle" v-if="olderNotifications.length" >
|
|
|
|
{{ i18n.t('nav.notifications.older') }}
|
|
|
|
</div>
|
2023-04-06 20:57:00 +08:00
|
|
|
<NotificationItem v-for="notification in olderNotifications" :key="notification.type_of + '-' + notification.id" :notification="notification" />
|
2023-04-07 19:59:06 +08:00
|
|
|
<div class="next-page-loader">
|
|
|
|
<img src="/images/medium/loading.svg" v-if="loadingPage"/>
|
|
|
|
</div>
|
|
|
|
</perfect-scrollbar>
|
2023-03-24 17:42:37 +08:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
2023-03-30 19:27:10 +08:00
|
|
|
import NotificationItem from './notification_item.vue'
|
2023-03-24 17:42:37 +08:00
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'NotificationsFlyout',
|
|
|
|
components: {
|
|
|
|
NotificationItem
|
|
|
|
},
|
|
|
|
props: {
|
2023-04-12 17:14:53 +08:00
|
|
|
notificationsUrl: String,
|
|
|
|
unseenNotificationsCount: Number
|
2023-03-24 17:42:37 +08:00
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
notifications: [],
|
|
|
|
activeTab: 'all',
|
2023-04-07 19:59:06 +08:00
|
|
|
nextPage: 1,
|
|
|
|
scrollBar: null,
|
|
|
|
loadingPage: false
|
2023-03-24 17:42:37 +08:00
|
|
|
}
|
|
|
|
},
|
2023-04-06 20:57:00 +08:00
|
|
|
created() {
|
|
|
|
this.loadNotifications();
|
2023-03-24 17:42:37 +08:00
|
|
|
},
|
2023-04-07 19:59:06 +08:00
|
|
|
mounted() {
|
|
|
|
let container = this.$refs.scrollContainer.$el
|
|
|
|
container.addEventListener('ps-y-reach-end', (e) => {
|
|
|
|
this.loadNotifications();
|
|
|
|
})
|
|
|
|
},
|
2023-03-24 17:42:37 +08:00
|
|
|
computed: {
|
|
|
|
filteredNotifications() {
|
2023-04-06 20:57:00 +08:00
|
|
|
this.loadNotifications();
|
2023-03-24 17:42:37 +08:00
|
|
|
},
|
|
|
|
todayNotifications() {
|
2023-04-14 20:46:57 +08:00
|
|
|
return this.notifications.filter(n => n.today);
|
2023-03-24 17:42:37 +08:00
|
|
|
},
|
|
|
|
olderNotifications() {
|
2023-04-14 20:46:57 +08:00
|
|
|
return this.notifications.filter(n => !n.today);
|
2023-04-06 20:57:00 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
setActiveTab(selection) {
|
|
|
|
this.activeTab = selection;
|
2023-04-12 17:14:53 +08:00
|
|
|
this.nextPage = 1;
|
|
|
|
this.notifications = [];
|
2023-04-06 20:57:00 +08:00
|
|
|
this.loadNotifications();
|
|
|
|
},
|
|
|
|
loadNotifications() {
|
2023-04-07 19:59:06 +08:00
|
|
|
if (this.nextPage == null || this.loadingPage) return;
|
|
|
|
|
|
|
|
this.loadingPage = true;
|
|
|
|
$.getJSON(this.notificationsUrl, { type: this.activeTab, page: this.nextPage }, (result) => {
|
|
|
|
this.notifications = this.notifications.concat(result.notifications);
|
|
|
|
this.nextPage = result.next_page;
|
|
|
|
this.loadingPage = false;
|
2023-04-17 21:23:52 +08:00
|
|
|
this.$emit('update:unseenNotificationsCount');
|
2023-04-06 20:57:00 +08:00
|
|
|
});
|
2023-03-24 17:42:37 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|