diff options
Diffstat (limited to 'packages/frontend')
| -rw-r--r-- | packages/frontend/src/components/MkPagination.vue | 42 | ||||
| -rw-r--r-- | packages/frontend/src/components/MkPaginationControl.vue | 83 | ||||
| -rw-r--r-- | packages/frontend/src/composables/use-pagination.ts | 9 | ||||
| -rw-r--r-- | packages/frontend/src/pages/admin/modlog.vue | 84 |
4 files changed, 144 insertions, 74 deletions
diff --git a/packages/frontend/src/components/MkPagination.vue b/packages/frontend/src/components/MkPagination.vue index f069caeb44..679e8deaf5 100644 --- a/packages/frontend/src/components/MkPagination.vue +++ b/packages/frontend/src/components/MkPagination.vue @@ -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; diff --git a/packages/frontend/src/components/MkPaginationControl.vue b/packages/frontend/src/components/MkPaginationControl.vue new file mode 100644 index 0000000000..ce19005504 --- /dev/null +++ b/packages/frontend/src/components/MkPaginationControl.vue @@ -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> diff --git a/packages/frontend/src/composables/use-pagination.ts b/packages/frontend/src/composables/use-pagination.ts index 4411f163af..b3d8d36431 100644 --- a/packages/frontend/src/composables/use-pagination.ts +++ b/packages/frontend/src/composables/use-pagination.ts @@ -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, }; } 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> + |