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>
|
|
|
|
<hr>
|
2023-04-07 19:59:06 +08:00
|
|
|
<perfect-scrollbar ref="scrollContainer" class="sci--navigation--notificaitons-flyout-notifications">
|
2023-11-10 20:02:01 +08:00
|
|
|
<div class="sci-navigation--notificaitons-flyout-subtitle" v-if="todayNotifications.length">
|
2023-03-24 17:42:37 +08:00
|
|
|
{{ i18n.t('nav.notifications.today') }}
|
|
|
|
</div>
|
2023-11-10 20:02:01 +08:00
|
|
|
<NotificationItem v-for="notification in todayNotifications" :key="notification.type_of + '-' + notification.id"
|
|
|
|
:notification="notification" />
|
|
|
|
<div class="sci-navigation--notificaitons-flyout-subtitle" v-if="olderNotifications.length">
|
2023-03-24 17:42:37 +08:00
|
|
|
{{ i18n.t('nav.notifications.older') }}
|
|
|
|
</div>
|
2023-11-10 20:02:01 +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">
|
2023-11-10 20:02:01 +08:00
|
|
|
<img src="/images/medium/loading.svg" v-if="loadingPage" />
|
2023-04-07 19:59:06 +08:00
|
|
|
</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-10-17 18:02:55 +08:00
|
|
|
import axios from '../../../packs/custom_axios.js';
|
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: [],
|
2023-10-17 18:02:55 +08:00
|
|
|
nextPageUrl: null,
|
2023-04-07 19:59:06 +08:00
|
|
|
scrollBar: null,
|
|
|
|
loadingPage: false
|
2023-03-24 17:42:37 +08:00
|
|
|
}
|
|
|
|
},
|
2023-04-06 20:57:00 +08:00
|
|
|
created() {
|
2023-10-17 18:02:55 +08:00
|
|
|
this.nextPageUrl = this.notificationsUrl;
|
2023-04-06 20:57:00 +08:00
|
|
|
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
|
2023-11-10 20:02:01 +08:00
|
|
|
|
2023-07-20 17:04:17 +08:00
|
|
|
container.addEventListener('ps-scroll-y', (e) => {
|
|
|
|
if (e.target.scrollTop + e.target.clientHeight >= e.target.scrollHeight - 20) {
|
|
|
|
this.loadNotifications();
|
|
|
|
}
|
2023-04-07 19:59:06 +08:00
|
|
|
})
|
|
|
|
},
|
2023-11-24 22:32:32 +08:00
|
|
|
beforeUnmount() {
|
|
|
|
document.body.style.overflow = 'scroll';
|
2023-11-10 20:02:01 +08:00
|
|
|
},
|
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-10-17 18:02:55 +08:00
|
|
|
return this.notifications.filter(n => n.attributes.today);
|
2023-03-24 17:42:37 +08:00
|
|
|
},
|
|
|
|
olderNotifications() {
|
2023-10-17 18:02:55 +08:00
|
|
|
return this.notifications.filter(n => !n.attributes.today);
|
2023-04-06 20:57:00 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
loadNotifications() {
|
2023-10-17 18:02:55 +08:00
|
|
|
if (this.nextPageUrl == null || this.loadingPage) return;
|
2023-04-07 19:59:06 +08:00
|
|
|
|
|
|
|
this.loadingPage = true;
|
2023-10-17 18:02:55 +08:00
|
|
|
|
|
|
|
axios.get(this.nextPageUrl)
|
|
|
|
.then(response => {
|
|
|
|
this.notifications = this.notifications.concat(response.data.data);
|
|
|
|
this.nextPageUrl = response.data.links.next;
|
|
|
|
this.loadingPage = false;
|
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
this.loadingPage = false;
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2023-03-24 17:42:37 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|