refactor(frontend): improve pagination implementation

This commit is contained in:
syuilo
2025-06-29 15:11:25 +09:00
parent 8bc822d829
commit f1deb89e34
68 changed files with 1067 additions and 1138 deletions

View File

@@ -9,7 +9,7 @@ SPDX-License-Identifier: AGPL-3.0-only
<div v-if="tab === 'explore'">
<MkFoldableSection class="_margin">
<template #header><i class="ti ti-clock"></i>{{ i18n.ts.recentPosts }}</template>
<MkPagination v-slot="{items}" :pagination="recentPostsPagination" :disableAutoLoad="true">
<MkPagination v-slot="{items}" :paginator="recentPostsPaginator">
<div :class="$style.items">
<MkGalleryPostPreview v-for="post in items" :key="post.id" :post="post" class="post"/>
</div>
@@ -17,7 +17,7 @@ SPDX-License-Identifier: AGPL-3.0-only
</MkFoldableSection>
<MkFoldableSection class="_margin">
<template #header><i class="ti ti-comet"></i>{{ i18n.ts.popularPosts }}</template>
<MkPagination v-slot="{items}" :pagination="popularPostsPagination" :disableAutoLoad="true">
<MkPagination v-slot="{items}" :paginator="popularPostsPaginator">
<div :class="$style.items">
<MkGalleryPostPreview v-for="post in items" :key="post.id" :post="post" class="post"/>
</div>
@@ -25,7 +25,7 @@ SPDX-License-Identifier: AGPL-3.0-only
</MkFoldableSection>
</div>
<div v-else-if="tab === 'liked'">
<MkPagination v-slot="{items}" :pagination="likedPostsPagination">
<MkPagination v-slot="{items}" :paginator="likedPostsPaginator">
<div :class="$style.items">
<MkGalleryPostPreview v-for="like in items" :key="like.id" :post="like.post" class="post"/>
</div>
@@ -33,7 +33,7 @@ SPDX-License-Identifier: AGPL-3.0-only
</div>
<div v-else-if="tab === 'my'">
<MkA to="/gallery/new" class="_link" style="margin: 16px;"><i class="ti ti-plus"></i> {{ i18n.ts.postToGallery }}</MkA>
<MkPagination v-slot="{items}" :pagination="myPostsPagination">
<MkPagination v-slot="{items}" :paginator="myPostsPaginator">
<div :class="$style.items">
<MkGalleryPostPreview v-for="post in items" :key="post.id" :post="post" class="post"/>
</div>
@@ -44,13 +44,14 @@ SPDX-License-Identifier: AGPL-3.0-only
</template>
<script lang="ts" setup>
import { watch, ref, computed } from 'vue';
import { watch, ref, computed, markRaw } from 'vue';
import MkFoldableSection from '@/components/MkFoldableSection.vue';
import MkPagination from '@/components/MkPagination.vue';
import MkGalleryPostPreview from '@/components/MkGalleryPostPreview.vue';
import { definePage } from '@/page.js';
import { i18n } from '@/i18n.js';
import { useRouter } from '@/router.js';
import { Paginator } from '@/utility/paginator.js';
const router = useRouter();
@@ -59,34 +60,19 @@ const props = defineProps<{
}>();
const tab = ref('explore');
const tags = ref([]);
const tagsRef = ref();
const recentPostsPagination = {
endpoint: 'gallery/posts' as const,
const recentPostsPaginator = markRaw(new Paginator('gallery/posts', {
limit: 6,
};
const popularPostsPagination = {
endpoint: 'gallery/featured' as const,
}));
const popularPostsPaginator = markRaw(new Paginator('gallery/featured', {
noPaging: true,
};
const myPostsPagination = {
endpoint: 'i/gallery/posts' as const,
}));
const myPostsPaginator = markRaw(new Paginator('i/gallery/posts', {
limit: 5,
};
const likedPostsPagination = {
endpoint: 'i/gallery/likes' as const,
}));
const likedPostsPaginator = markRaw(new Paginator('i/gallery/likes', {
limit: 5,
};
const tagUsersPagination = computed(() => ({
endpoint: 'hashtags/users' as const,
limit: 30,
params: {
tag: props.tag,
origin: 'combined',
sort: '+follower',
},
}));
watch(() => props.tag, () => {

View File

@@ -46,7 +46,7 @@ SPDX-License-Identifier: AGPL-3.0-only
<MkContainer :max-height="300" :foldable="true" class="other">
<template #icon><i class="ti ti-clock"></i></template>
<template #header>{{ i18n.ts.recentPosts }}</template>
<MkPagination v-slot="{items}" :pagination="otherPostsPagination">
<MkPagination v-slot="{items}" :paginator="otherPostsPaginator">
<div class="sdrarzaf">
<MkGalleryPostPreview v-for="post in items" :key="post.id" :post="post" class="post"/>
</div>
@@ -62,7 +62,7 @@ SPDX-License-Identifier: AGPL-3.0-only
</template>
<script lang="ts" setup>
import { computed, watch, ref, defineAsyncComponent } from 'vue';
import { computed, watch, ref, defineAsyncComponent, markRaw } from 'vue';
import * as Misskey from 'misskey-js';
import { url } from '@@/js/config.js';
import type { MenuItem } from '@/types/menu.js';
@@ -80,6 +80,7 @@ import { $i } from '@/i.js';
import { isSupportShare } from '@/utility/navigator.js';
import { copyToClipboard } from '@/utility/copy-to-clipboard.js';
import { useRouter } from '@/router.js';
import { Paginator } from '@/utility/paginator.js';
const router = useRouter();
@@ -89,13 +90,12 @@ const props = defineProps<{
const post = ref<Misskey.entities.GalleryPost | null>(null);
const error = ref<any>(null);
const otherPostsPagination = {
endpoint: 'users/gallery/posts' as const,
const otherPostsPaginator = markRaw(new Paginator('users/gallery/posts', {
limit: 6,
params: computed(() => ({
computedParams: computed(() => ({
userId: post.value.user.id,
})),
};
}));
function fetchPost() {
post.value = null;