From 3c5ed0ffbba9783bcc2437a588aa3cbc808a33da Mon Sep 17 00:00:00 2001
From: syuilo <4439005+syuilo@users.noreply.github.com>
Date: Sat, 28 Jun 2025 21:18:36 +0900
Subject: enhance(frontend): improve modlog pagination

---
 packages/frontend/src/pages/admin/modlog.vue | 84 +++++++++++++++++-----------
 1 file changed, 50 insertions(+), 34 deletions(-)

(limited to 'packages/frontend/src/pages/admin/modlog.vue')

diff --git a/packages/frontend/src/pages/admin/modlog.vue b/packages/frontend/src/pages/admin/modlog.vue
index 9ccc1cb0a0..9c1c1d0cc2 100644
--- a/packages/frontend/src/pages/admin/modlog.vue
+++ b/packages/frontend/src/pages/admin/modlog.vue
@@ -7,29 +7,32 @@ SPDX-License-Identifier: AGPL-3.0-only
 <PageWithHeader :actions="headerActions" :tabs="headerTabs">
 	<div class="_spacer" style="--MI_SPACER-w: 900px;">
 		<div class="_gaps">
-			<div style="display: flex; gap: var(--MI-margin); flex-wrap: wrap;">
+			<MkPaginationControl v-model:order="order" v-model:date="date" canFilter @reload="paginator.reload()">
 				<MkSelect v-model="type" style="margin: 0; flex: 1;">
 					<template #label>{{ i18n.ts.type }}</template>
 					<option :value="null">{{ i18n.ts.all }}</option>
 					<option v-for="t in Misskey.moderationLogTypes" :key="t" :value="t">{{ i18n.ts._moderationLogTypes[t] ?? t }}</option>
 				</MkSelect>
+
 				<MkInput v-model="moderatorId" style="margin: 0; flex: 1;">
 					<template #label>{{ i18n.ts.moderator }}(ID)</template>
 				</MkInput>
-			</div>
+			</MkPaginationControl>
 
-			<MkTl :events="timeline" groupBy="d">
-				<template #left="{ event }">
-					<div>
-						<MkAvatar :user="event.user" style="width: 26px; height: 26px;"/>
-					</div>
-				</template>
-				<template #right="{ event, timestamp, delta }">
-					<div style="margin: 4px 0;">
-						<XModLog :key="event.id" :log="event"/>
-					</div>
-				</template>
-			</MkTl>
+			<component :is="prefer.s.enablePullToRefresh ? MkPullToRefresh : 'div'" :refresher="() => paginator.reload()">
+				<MkTl :events="timeline" groupBy="d">
+					<template #left="{ event }">
+						<div>
+							<MkAvatar :user="event.user" style="width: 26px; height: 26px;"/>
+						</div>
+					</template>
+					<template #right="{ event, timestamp, delta }">
+						<div style="margin: 4px 0;">
+							<XModLog :key="event.id" :log="event"/>
+						</div>
+					</template>
+				</MkTl>
+			</component>
 
 			<MkButton primary rounded style="margin: 0 auto;" @click="fetchMore">{{ i18n.ts.loadMore }}</MkButton>
 		</div>
@@ -46,39 +49,51 @@ import MkInput from '@/components/MkInput.vue';
 import MkTl from '@/components/MkTl.vue';
 import { i18n } from '@/i18n.js';
 import { definePage } from '@/page.js';
-import { misskeyApi } from '@/utility/misskey-api.js';
+import { prefer } from '@/preferences.js';
+import { usePagination } from '@/composables/use-pagination.js';
+import MkPullToRefresh from '@/components/MkPullToRefresh.vue';
 import MkButton from '@/components/MkButton.vue';
+import MkPaginationControl from '@/components/MkPaginationControl.vue';
 
+const order = ref<'newest' | 'oldest'>('newest');
+const date = ref<number | null>(null);
 const type = ref<string | null>(null);
 const moderatorId = ref('');
 
-const timeline = ref([]);
+const paginator = usePagination({
+	ctx: {
+		endpoint: 'admin/show-moderation-logs',
+		limit: 20,
+		canFetchDetection: 'limit',
+		params: computed(() => ({
+			type: type.value,
+			userId: moderatorId.value === '' ? null : moderatorId.value,
+		})),
+	},
+});
 
-watch([type, moderatorId], async () => {
-	const res = await misskeyApi('admin/show-moderation-logs', {
-		type: type.value,
-		userId: moderatorId.value === '' ? null : moderatorId.value,
+watch([order, date], () => {
+	paginator.updateCtxPartial({
+		order: order.value,
+		initialDirection: order.value === 'oldest' ? 'newer' : 'older',
+		initialDate: date.value,
 	});
-	timeline.value = res.map(x => ({
+}, { immediate: false });
+
+const timeline = computed(() => {
+	return paginator.items.value.map(x => ({
 		id: x.id,
 		timestamp: x.createdAt,
 		data: x,
 	}));
-}, { immediate: true });
+});
 
 function fetchMore() {
-	const last = timeline.value[timeline.value.length - 1];
-	misskeyApi('admin/show-moderation-logs', {
-		type: type.value,
-		userId: moderatorId.value === '' ? null : moderatorId.value,
-		untilId: last.id,
-	}).then(res => {
-		timeline.value.push(...res.map(x => ({
-			id: x.id,
-			timestamp: x.createdAt,
-			data: x,
-		})));
-	});
+	if (order.value === 'oldest') {
+		paginator.fetchNewer();
+	} else {
+		paginator.fetchOlder();
+	}
 }
 
 const headerActions = computed(() => []);
@@ -90,3 +105,4 @@ definePage(() => ({
 	icon: 'ti ti-list-search',
 }));
 </script>
+
-- 
cgit v1.2.3-freya

