mirror of
https://github.com/misskey-dev/misskey.git
synced 2026-05-25 08:34:13 +02:00
refactor(frontend): improve pagination implementation
This commit is contained in:
@@ -12,44 +12,38 @@ SPDX-License-Identifier: AGPL-3.0-only
|
||||
<div v-if="tab === 'my'" class="_gaps">
|
||||
<MkButton primary rounded class="add" @click="create"><i class="ti ti-plus"></i> {{ i18n.ts.add }}</MkButton>
|
||||
|
||||
<MkPagination v-slot="{ items }" ref="pagingComponent" :pagination="pagination" class="_gaps" withControl>
|
||||
<MkPagination v-slot="{ items }" :paginator="paginator" class="_gaps" withControl>
|
||||
<MkClipPreview v-for="item in items" :key="item.id" :clip="item" :noUserInfo="true"/>
|
||||
</MkPagination>
|
||||
</div>
|
||||
<div v-else-if="tab === 'favorites'" class="_gaps">
|
||||
<MkClipPreview v-for="item in favorites" :key="item.id" :clip="item"/>
|
||||
<div v-else-if="tab === 'favorites'">
|
||||
<MkPagination v-slot="{ items }" :paginator="favoritesPaginator" class="_gaps" withControl>
|
||||
<MkClipPreview v-for="item in items" :key="item.id" :clip="item" :noUserInfo="true"/>
|
||||
</MkPagination>
|
||||
</div>
|
||||
</div>
|
||||
</PageWithHeader>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { watch, ref, useTemplateRef, computed } from 'vue';
|
||||
import { watch, ref, computed, markRaw } from 'vue';
|
||||
import * as Misskey from 'misskey-js';
|
||||
import MkPagination from '@/components/MkPagination.vue';
|
||||
import MkButton from '@/components/MkButton.vue';
|
||||
import MkClipPreview from '@/components/MkClipPreview.vue';
|
||||
import * as os from '@/os.js';
|
||||
import { misskeyApi } from '@/utility/misskey-api.js';
|
||||
import { i18n } from '@/i18n.js';
|
||||
import { definePage } from '@/page.js';
|
||||
import { clipsCache } from '@/cache.js';
|
||||
|
||||
const pagination = {
|
||||
endpoint: 'clips/list' as const,
|
||||
noPaging: true,
|
||||
limit: 10,
|
||||
};
|
||||
import { Paginator } from '@/utility/paginator.js';
|
||||
|
||||
const tab = ref('my');
|
||||
|
||||
const favorites = ref<Misskey.entities.Clip[] | null>(null);
|
||||
const paginator = markRaw(new Paginator('clips/list', {
|
||||
}));
|
||||
|
||||
const pagingComponent = useTemplateRef('pagingComponent');
|
||||
|
||||
watch(tab, async () => {
|
||||
favorites.value = await misskeyApi('clips/my-favorites');
|
||||
});
|
||||
const favoritesPaginator = markRaw(new Paginator('clips/my-favorites', {
|
||||
}));
|
||||
|
||||
async function create() {
|
||||
const { canceled, result } = await os.form(i18n.ts.createNewClip, {
|
||||
@@ -76,15 +70,15 @@ async function create() {
|
||||
|
||||
clipsCache.delete();
|
||||
|
||||
pagingComponent.value?.paginator.reload();
|
||||
paginator.reload();
|
||||
}
|
||||
|
||||
function onClipCreated() {
|
||||
pagingComponent.value?.paginator.reload();
|
||||
paginator.reload();
|
||||
}
|
||||
|
||||
function onClipDeleted() {
|
||||
pagingComponent.value?.paginator.reload();
|
||||
paginator.reload();
|
||||
}
|
||||
|
||||
const headerActions = computed(() => []);
|
||||
|
||||
Reference in New Issue
Block a user