summaryrefslogtreecommitdiff
path: root/packages/frontend/src/components/MkNotifications.vue
diff options
context:
space:
mode:
authorsyuilo <Syuilotan@yahoo.co.jp>2023-11-02 18:07:42 +0900
committersyuilo <Syuilotan@yahoo.co.jp>2023-11-02 18:07:42 +0900
commitd0d32e88466cef53a0d4429cce1ce4b9cb97d5b1 (patch)
treec7c0e00d02e656b019de6731bb5238173571ce56 /packages/frontend/src/components/MkNotifications.vue
parent2023.11.0-beta.8 (diff)
downloadmisskey-d0d32e88466cef53a0d4429cce1ce4b9cb97d5b1.tar.gz
misskey-d0d32e88466cef53a0d4429cce1ce4b9cb97d5b1.tar.bz2
misskey-d0d32e88466cef53a0d4429cce1ce4b9cb97d5b1.zip
enhance(frontend): improve pull to refresh
Diffstat (limited to 'packages/frontend/src/components/MkNotifications.vue')
-rw-r--r--packages/frontend/src/components/MkNotifications.vue51
1 files changed, 34 insertions, 17 deletions
diff --git a/packages/frontend/src/components/MkNotifications.vue b/packages/frontend/src/components/MkNotifications.vue
index 8d99e440e1..77e66f0165 100644
--- a/packages/frontend/src/components/MkNotifications.vue
+++ b/packages/frontend/src/components/MkNotifications.vue
@@ -4,25 +4,27 @@ SPDX-License-Identifier: AGPL-3.0-only
-->
<template>
-<MkPagination ref="pagingComponent" :pagination="pagination">
- <template #empty>
- <div class="_fullinfo">
- <img :src="infoImageUrl" class="_ghost"/>
- <div>{{ i18n.ts.noNotifications }}</div>
- </div>
- </template>
+<MkPullToRefresh :refresher="() => reload()">
+ <MkPagination ref="pagingComponent" :pagination="pagination">
+ <template #empty>
+ <div class="_fullinfo">
+ <img :src="infoImageUrl" class="_ghost"/>
+ <div>{{ i18n.ts.noNotifications }}</div>
+ </div>
+ </template>
- <template #default="{ items: notifications }">
- <MkDateSeparatedList v-slot="{ item: notification }" :class="$style.list" :items="notifications" :noGap="true">
- <MkNote v-if="['reply', 'quote', 'mention'].includes(notification.type)" :key="notification.id" :note="notification.note"/>
- <XNotification v-else :key="notification.id" :notification="notification" :withTime="true" :full="true" class="_panel"/>
- </MkDateSeparatedList>
- </template>
-</MkPagination>
+ <template #default="{ items: notifications }">
+ <MkDateSeparatedList v-slot="{ item: notification }" :class="$style.list" :items="notifications" :noGap="true">
+ <MkNote v-if="['reply', 'quote', 'mention'].includes(notification.type)" :key="notification.id" :note="notification.note"/>
+ <XNotification v-else :key="notification.id" :notification="notification" :withTime="true" :full="true" class="_panel"/>
+ </MkDateSeparatedList>
+ </template>
+ </MkPagination>
+</MkPullToRefresh>
</template>
<script lang="ts" setup>
-import { onUnmounted, onDeactivated, onMounted, computed, shallowRef } from 'vue';
+import { onUnmounted, onDeactivated, onMounted, computed, shallowRef, onActivated } from 'vue';
import MkPagination, { Paging } from '@/components/MkPagination.vue';
import XNotification from '@/components/MkNotification.vue';
import MkDateSeparatedList from '@/components/MkDateSeparatedList.vue';
@@ -33,6 +35,7 @@ import { i18n } from '@/i18n.js';
import { notificationTypes } from '@/const.js';
import { infoImageUrl } from '@/instance.js';
import { defaultStore } from '@/store.js';
+import MkPullToRefresh from '@/components/MkPullToRefresh.vue';
const props = defineProps<{
excludeTypes?: typeof notificationTypes[number][];
@@ -54,7 +57,7 @@ const pagination: Paging = defaultStore.state.useGroupedNotifications ? {
})),
};
-const onNotification = (notification) => {
+function onNotification(notification) {
const isMuted = props.excludeTypes ? props.excludeTypes.includes(notification.type) : false;
if (isMuted || document.visibilityState === 'visible') {
useStream().send('readNotification');
@@ -63,7 +66,15 @@ const onNotification = (notification) => {
if (!isMuted) {
pagingComponent.value.prepend(notification);
}
-};
+}
+
+function reload() {
+ return new Promise<void>((res) => {
+ pagingComponent.value?.reload().then(() => {
+ res();
+ });
+ });
+}
let connection;
@@ -72,6 +83,12 @@ onMounted(() => {
connection.on('notification', onNotification);
});
+onActivated(() => {
+ pagingComponent.value?.reload();
+ connection = useStream().useChannel('main');
+ connection.on('notification', onNotification);
+});
+
onUnmounted(() => {
if (connection) connection.dispose();
});