Skip to content

Commit

Permalink
feat(frontend): スワイプやボタンでタイムラインを再読込する機能 (misskey-dev#12113) (#206)
Browse files Browse the repository at this point in the history
* feat(frontend): スワイプやボタンでタイムラインを再読込する機能 (misskey-dev#12113)
* tweak MkPullToRefresh
cheery-picked from 52dbab5
Co-authored-by: syuilo <Syuilotan@yahoo.co.jp>
* enhance(frontend): improve pull to refresh
cheery-picked from d0d32e8
Co-authored-by: syuilo <Syuilotan@yahoo.co.jp>
  • Loading branch information
u1-liquid authored Nov 3, 2023
1 parent c29ec98 commit ac3c6f3
Show file tree
Hide file tree
Showing 15 changed files with 429 additions and 83 deletions.
4 changes: 4 additions & 0 deletions locales/en-US.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1098,6 +1098,10 @@ expired: "Expired"
doYouAgree: "Agree?"
beSureToReadThisAsItIsImportant: "Please read this important information."
iHaveReadXCarefullyAndAgree: "I have read the text \"{x}\" and agree."
releaseToRefresh: "Release to reload"
refreshing: "Reloading"
pullDownToRefresh: "Pull down to reload"
disableStreamingTimeline: "Disable realtime update on timeline"
_initialAccountSetting:
accountCreated: "Your account was successfully created!"
letsStartAccountSetup: "For starters, let's set up your profile."
Expand Down
4 changes: 4 additions & 0 deletions locales/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1109,6 +1109,10 @@ export interface Locale {
"pastAnnouncements": string;
"youHaveUnreadAnnouncements": string;
"externalServices": string;
"releaseToRefresh": string;
"refreshing": string;
"pullDownToRefresh": string;
"disableStreamingTimeline": string;
"_announcement": {
"forExistingUsers": string;
"forExistingUsersDescription": string;
Expand Down
4 changes: 4 additions & 0 deletions locales/ja-JP.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1106,6 +1106,10 @@ currentAnnouncements: "現在のお知らせ"
pastAnnouncements: "過去のお知らせ"
youHaveUnreadAnnouncements: "未読のお知らせがあります。"
externalServices: "外部サービス"
releaseToRefresh: "離してリロード"
refreshing: "リロード中"
pullDownToRefresh: "引っ張ってリロード"
disableStreamingTimeline: "タイムラインのリアルタイム更新を無効にする"

_announcement:
forExistingUsers: "既存ユーザーのみ"
Expand Down
3 changes: 2 additions & 1 deletion packages/frontend/src/boot/main-boot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { common } from './common';
import { version, ui, lang, updateLocale } from '@/config';
import { i18n, updateI18n } from '@/i18n';
import { confirm, alert, post, popup, toast } from '@/os';
import { useStream } from '@/stream';
import { useStream, isReloading } from '@/stream';
import * as sound from '@/scripts/sound';
import { $i, refreshAccount, login, updateAccount, signout } from '@/account';
import { defaultStore, ColdDeviceStorage } from '@/store';
Expand Down Expand Up @@ -39,6 +39,7 @@ export async function mainBoot() {

let reloadDialogShowing = false;
stream.on('_disconnected_', async () => {
if (isReloading) return;
if (defaultStore.state.serverDisconnectedBehavior === 'reload') {
location.reload();
} else if (defaultStore.state.serverDisconnectedBehavior === 'dialog') {
Expand Down
53 changes: 35 additions & 18 deletions packages/frontend/src/components/MkNotifications.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,29 @@ 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 notification"/>
</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 notification"/>
</MkDateSeparatedList>
</template>
</MkPagination>
</MkPullToRefresh>
</template>

<script lang="ts" setup>
import { onUnmounted, onMounted, computed, shallowRef } from 'vue';
import { onUnmounted, onActivated, onMounted, computed, shallowRef } from 'vue';
import MkPagination, { Paging } from '@/components/MkPagination.vue';
import MkPullToRefresh from '@/components/MkPullToRefresh.vue';
import XNotification from '@/components/MkNotification.vue';
import MkDateSeparatedList from '@/components/MkDateSeparatedList.vue';
import MkNote from '@/components/MkNote.vue';
Expand All @@ -48,16 +51,24 @@ const pagination: Paging = {
})),
};

const onNotification = (notification) => {
function onNotification(notification) {
const isMuted = props.includeTypes ? !props.includeTypes.includes(notification.type) : $i.mutingNotificationTypes.includes(notification.type);
if (isMuted || document.visibilityState === 'visible') {
useStream().send('readNotification');
}

if (!isMuted) {
pagingComponent.value.prepend(notification);
pagingComponent.value?.prepend(notification);
}
};
}

function reload() {
return new Promise<void>((res) => {
pagingComponent.value?.reload().then(() => {
res();
});
});
}

let connection;

Expand All @@ -66,6 +77,12 @@ onMounted(() => {
connection.on('notification', onNotification);
});

onActivated(() => {
pagingComponent.value?.reload();
connection = useStream().useChannel('main');
connection.on('notification', onNotification);
});

onUnmounted(() => {
if (connection) connection.dispose();
});
Expand Down
2 changes: 2 additions & 0 deletions packages/frontend/src/components/MkPageWindow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ defineExpose({

<style lang="scss" module>
.root {
overscroll-behavior: none;

min-height: 100%;
background: var(--bg);

Expand Down
6 changes: 6 additions & 0 deletions packages/frontend/src/components/MkPagination.vue
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ const props = withDefaults(defineProps<{

const emit = defineEmits<{
(ev: 'queue', count: number): void;
(ev: 'status', error: boolean): void;
}>();

let rootEl = $shallowRef<HTMLElement>();
Expand Down Expand Up @@ -164,6 +165,11 @@ watch(queue, (a, b) => {
emit('queue', queue.value.length);
}, { deep: true });

watch(error, (n, o) => {
if (n === o) return;
emit('status', n);
});

async function init(): Promise<void> {
queue.value = [];
fetching.value = true;
Expand Down
Loading

0 comments on commit ac3c6f3

Please sign in to comment.