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') }}
|
2024-01-25 15:34:22 +08:00
|
|
|
<a class="ml-auto cursor-pointer text-sm font-normal" :href="this.preferencesUrl" :title="i18n.t('nav.settings')">
|
2024-01-15 09:03:18 +08:00
|
|
|
{{ i18n.t('nav.settings') }}
|
|
|
|
</a>
|
2023-03-24 17:42:37 +08:00
|
|
|
</div>
|
|
|
|
<hr>
|
2024-01-15 23:09:19 +08:00
|
|
|
<perfect-scrollbar @wheel="preventPropagation" 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>
|
|
|
|
|
2024-01-04 23:34:36 +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,
|
2024-01-16 09:20:00 +08:00
|
|
|
unseenNotificationsCount: Number,
|
|
|
|
preferencesUrl: String
|
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
|
2024-01-04 23:34:36 +08:00
|
|
|
};
|
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() {
|
2024-01-04 23:34:36 +08:00
|
|
|
const 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();
|
|
|
|
}
|
2024-01-04 23:34:36 +08:00
|
|
|
});
|
2023-04-07 19:59:06 +08:00
|
|
|
},
|
2023-11-24 22:32:32 +08:00
|
|
|
beforeUnmount() {
|
2024-01-06 01:58:12 +08:00
|
|
|
document.body.style.overflow = 'auto';
|
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() {
|
2024-01-04 23:34:36 +08:00
|
|
|
return this.notifications.filter((n) => n.attributes.today);
|
2023-03-24 17:42:37 +08:00
|
|
|
},
|
|
|
|
olderNotifications() {
|
2024-01-04 23:34:36 +08:00
|
|
|
return this.notifications.filter((n) => !n.attributes.today);
|
2023-04-06 20:57:00 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
2024-01-15 23:09:19 +08:00
|
|
|
preventPropagation(e) {
|
|
|
|
e.stopPropagation();
|
|
|
|
e.preventDefault();
|
|
|
|
},
|
2023-04-06 20:57:00 +08:00
|
|
|
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)
|
2024-01-04 23:34:36 +08:00
|
|
|
.then((response) => {
|
2023-10-17 18:02:55 +08:00
|
|
|
this.notifications = this.notifications.concat(response.data.data);
|
|
|
|
this.nextPageUrl = response.data.links.next;
|
|
|
|
this.loadingPage = false;
|
2023-12-12 16:57:06 +08:00
|
|
|
this.$emit('update:unseenNotificationsCount');
|
2023-10-17 18:02:55 +08:00
|
|
|
})
|
2024-01-04 23:34:36 +08:00
|
|
|
.catch((error) => {
|
2023-10-17 18:02:55 +08:00
|
|
|
this.loadingPage = false;
|
|
|
|
});
|
2023-03-24 17:42:37 +08:00
|
|
|
}
|
|
|
|
}
|
2024-01-04 23:34:36 +08:00
|
|
|
};
|
2023-03-24 17:42:37 +08:00
|
|
|
</script>
|