summaryrefslogtreecommitdiff
path: root/packages/frontend/src/components
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
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')
-rw-r--r--packages/frontend/src/components/MkNotifications.vue51
-rw-r--r--packages/frontend/src/components/MkPullToRefresh.vue16
-rw-r--r--packages/frontend/src/components/MkTimeline.vue25
3 files changed, 56 insertions, 36 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();
});
diff --git a/packages/frontend/src/components/MkPullToRefresh.vue b/packages/frontend/src/components/MkPullToRefresh.vue
index c38d0ff6a1..f3f5660143 100644
--- a/packages/frontend/src/components/MkPullToRefresh.vue
+++ b/packages/frontend/src/components/MkPullToRefresh.vue
@@ -47,7 +47,13 @@ let scrollEl: HTMLElement | null = null;
let disabled = false;
-const emits = defineEmits<{
+const props = withDefaults(defineProps<{
+ refresher: () => Promise<void>;
+}>(), {
+ refresher: () => Promise.resolve(),
+});
+
+const emit = defineEmits<{
(ev: 'refresh'): void;
}>();
@@ -120,7 +126,12 @@ function moveEnd() {
if (isPullEnd) {
isPullEnd = false;
isRefreshing = true;
- fixOverContent().then(() => emits('refresh'));
+ fixOverContent().then(() => {
+ emit('refresh');
+ props.refresher().then(() => {
+ refreshFinished();
+ });
+ });
} else {
closeContent().then(() => isPullStart = false);
}
@@ -188,7 +199,6 @@ onUnmounted(() => {
});
defineExpose({
- refreshFinished,
setDisabled,
});
</script>
diff --git a/packages/frontend/src/components/MkTimeline.vue b/packages/frontend/src/components/MkTimeline.vue
index a2ada35f91..845c7a414c 100644
--- a/packages/frontend/src/components/MkTimeline.vue
+++ b/packages/frontend/src/components/MkTimeline.vue
@@ -4,7 +4,7 @@ SPDX-License-Identifier: AGPL-3.0-only
-->
<template>
-<MkPullToRefresh ref="prComponent" @refresh="() => reloadTimeline(true)">
+<MkPullToRefresh ref="prComponent" :refresher="() => reloadTimeline()">
<MkNotes ref="tlComponent" :noGap="!defaultStore.state.showGapBetweenNotesInTimeline" :pagination="pagination" @queue="emit('queue', $event)" @status="prComponent.setDisabled($event)"/>
</MkPullToRefresh>
</template>
@@ -196,25 +196,18 @@ const pagination = {
params: query,
};
-const reloadTimeline = (fromPR = false) => {
- tlNotesCount = 0;
+function reloadTimeline() {
+ return new Promise<void>((res) => {
+ tlNotesCount = 0;
- tlComponent.pagingComponent?.reload().then(() => {
- reloadStream();
- if (fromPR) prComponent.refreshFinished();
+ tlComponent.pagingComponent?.reload().then(() => {
+ reloadStream();
+ res();
+ });
});
-};
-
-//const pullRefresh = () => reloadTimeline(true);
+}
defineExpose({
reloadTimeline,
});
-
-/* TODO
-const timetravel = (date?: Date) => {
- this.date = date;
- this.$refs.tl.reload();
-};
-*/
</script>