enhance(frontend): improve modlog pagination

This commit is contained in:
syuilo 2025-06-28 21:18:36 +09:00
parent b8e8f3ad25
commit 3c5ed0ffbb
4 changed files with 144 additions and 74 deletions

View File

@ -6,25 +6,7 @@ SPDX-License-Identifier: AGPL-3.0-only
<template>
<component :is="prefer.s.enablePullToRefresh && pullToRefresh ? MkPullToRefresh : 'div'" :refresher="() => paginator.reload()" @contextmenu.prevent.stop="onContextmenu">
<div>
<div v-if="props.withControl" :class="$style.controls">
<div :class="$style.control">
<MkSelect v-model="order" :class="$style.order" :items="[{ label: i18n.ts._order.newest, value: 'newest' }, { label: i18n.ts._order.oldest, value: 'oldest' }]">
<template #prefix><i class="ti ti-arrows-sort"></i></template>
</MkSelect>
<!-- TODO -->
<!-- <MkButton v-tooltip="i18n.ts.search" iconOnly transparent rounded @click="setSearchQuery"><i class="ti ti-search"></i></MkButton> -->
<MkButton v-tooltip="i18n.ts.dateAndTime" iconOnly transparent rounded :active="date != null" @click="date = date == null ? Date.now() : null"><i class="ti ti-calendar-clock"></i></MkButton>
<MkButton v-tooltip="i18n.ts.reload" iconOnly transparent rounded @click="paginator.reload()"><i class="ti ti-refresh"></i></MkButton>
</div>
<MkInput
v-if="date != null"
type="date"
:modelValue="formatDateTimeString(new Date(date), 'yyyy-MM-dd')"
@update:modelValue="date = new Date($event).getTime()"
>
</MkInput>
</div>
<MkPaginationControl v-if="props.withControl" v-model:order="order" v-model:date="date" style="margin-bottom: 10px" @reload="paginator.reload()"/>
<!-- :css="prefer.s.animation" にしたいけどバグる(おそらくvueのバグ) https://github.com/misskey-dev/misskey/issues/16078 -->
<Transition
@ -72,10 +54,8 @@ import { i18n } from '@/i18n.js';
import { prefer } from '@/preferences.js';
import { usePagination } from '@/composables/use-pagination.js';
import MkPullToRefresh from '@/components/MkPullToRefresh.vue';
import MkSelect from '@/components/MkSelect.vue';
import MkInput from '@/components/MkInput.vue';
import MkPaginationControl from '@/components/MkPaginationControl.vue';
import * as os from '@/os.js';
import { formatDateTimeString } from '@/utility/format-time-string.js';
type Paginator = ReturnType<typeof usePagination<T['endpoint']>>;
@ -141,24 +121,6 @@ defineExpose({
opacity: 0;
}
.controls {
display: flex;
flex-direction: column;
gap: 8px;
margin-bottom: 10px;
}
.control {
display: flex;
align-items: center;
gap: 4px;
}
.order {
flex: 1;
margin-right: 6px;
}
.more {
margin-left: auto;
margin-right: auto;

View File

@ -0,0 +1,83 @@
<!--
SPDX-FileCopyrightText: syuilo and misskey-project
SPDX-License-Identifier: AGPL-3.0-only
-->
<template>
<div :class="$style.root">
<div :class="$style.control">
<MkSelect v-model="order" :class="$style.order" :items="[{ label: i18n.ts._order.newest, value: 'newest' }, { label: i18n.ts._order.oldest, value: 'oldest' }]">
<template #prefix><i class="ti ti-arrows-sort"></i></template>
</MkSelect>
<MkButton v-if="canSearch" v-tooltip="i18n.ts.search" iconOnly transparent rounded :active="search" @click="search = !search"><i class="ti ti-search"></i></MkButton>
<MkButton v-if="canFilter" v-tooltip="i18n.ts.filter" iconOnly transparent rounded :active="filterOpened" @click="filterOpened = !filterOpened"><i class="ti ti-filter"></i></MkButton>
<MkButton v-tooltip="i18n.ts.dateAndTime" iconOnly transparent rounded :active="date != null" @click="date = date == null ? Date.now() : null"><i class="ti ti-calendar-clock"></i></MkButton>
<MkButton v-tooltip="i18n.ts.reload" iconOnly transparent rounded @click="emit('reload')"><i class="ti ti-refresh"></i></MkButton>
</div>
<MkInput
v-if="date != null"
type="date"
:modelValue="formatDateTimeString(new Date(date), 'yyyy-MM-dd')"
@update:modelValue="date = new Date($event).getTime()"
>
</MkInput>
<slot v-if="filterOpened"></slot>
</div>
</template>
<script lang="ts" setup generic="T extends PagingCtx">
import { ref, watch } from 'vue';
import type { PagingCtx } from '@/composables/use-pagination.js';
import MkButton from '@/components/MkButton.vue';
import { i18n } from '@/i18n.js';
import MkSelect from '@/components/MkSelect.vue';
import MkInput from '@/components/MkInput.vue';
import { formatDateTimeString } from '@/utility/format-time-string.js';
const props = withDefaults(defineProps<{
canSearch?: boolean;
canFilter?: boolean;
filterOpened?: boolean;
}>(), {
canSearch: false,
canFilter: false,
filterOpened: false,
});
const emit = defineEmits<{
(ev: 'reload'): void;
}>();
const search = ref(false);
const filterOpened = ref(props.filterOpened);
const order = defineModel<'newest' | 'oldest'>('order', {
default: 'newest',
});
const date = defineModel<number | null>('date', {
default: null,
});
</script>
<style lang="scss" module>
.root {
display: flex;
flex-direction: column;
gap: 8px;
margin-bottom: 10px;
}
.control {
display: flex;
align-items: center;
gap: 4px;
}
.order {
flex: 1;
margin-right: 6px;
}
</style>

View File

@ -277,6 +277,14 @@ export function usePagination<Endpoint extends keyof Misskey.Endpoints, T extend
reload();
}
function updateCtxPartial(ctx: Partial<PagingCtx<Endpoint>>) {
props.ctx = {
...props.ctx,
...ctx,
};
reload();
}
if (props.autoInit !== false) {
onMounted(() => {
init();
@ -303,5 +311,6 @@ export function usePagination<Endpoint extends keyof Misskey.Endpoints, T extend
releaseQueue,
error,
updateCtx,
updateCtxPartial,
};
}

View File

@ -7,17 +7,19 @@ 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>
<component :is="prefer.s.enablePullToRefresh ? MkPullToRefresh : 'div'" :refresher="() => paginator.reload()">
<MkTl :events="timeline" groupBy="d">
<template #left="{ event }">
<div>
@ -30,6 +32,7 @@ SPDX-License-Identifier: AGPL-3.0-only
</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([]);
watch([type, moderatorId], async () => {
const res = await misskeyApi('admin/show-moderation-logs', {
const paginator = usePagination({
ctx: {
endpoint: 'admin/show-moderation-logs',
limit: 20,
canFetchDetection: 'limit',
params: computed(() => ({
type: type.value,
userId: moderatorId.value === '' ? null : moderatorId.value,
})),
},
});
timeline.value = res.map(x => ({
watch([order, date], () => {
paginator.updateCtxPartial({
order: order.value,
initialDirection: order.value === 'oldest' ? 'newer' : 'older',
initialDate: date.value,
});
}, { 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>