Update use-pagination.ts

This commit is contained in:
syuilo
2025-04-28 20:20:48 +09:00
parent d3bc92daff
commit 1b77f0d2b2
+10 -21
View File
@@ -3,7 +3,7 @@
* SPDX-License-Identifier: AGPL-3.0-only * SPDX-License-Identifier: AGPL-3.0-only
*/ */
import { computed, isRef, nextTick, onActivated, onBeforeMount, onBeforeUnmount, onDeactivated, onUnmounted, ref, watch } from 'vue'; import { computed, isRef, ref, watch } from 'vue';
import * as Misskey from 'misskey-js'; import * as Misskey from 'misskey-js';
import type { ComputedRef, Ref, ShallowRef } from 'vue'; import type { ComputedRef, Ref, ShallowRef } from 'vue';
import { misskeyApi } from '@/utility/misskey-api.js'; import { misskeyApi } from '@/utility/misskey-api.js';
@@ -162,35 +162,23 @@ export function usePagination<T>(props: {
}); });
}; };
/** function trim() {
* 新着アイテムをitemsの先頭に追加し、MAX_ITEMSを適用する if (items.value.size >= MAX_ITEMS) canFetchMore.value = true;
* @param newItems 新しいアイテムの配列 items.value = new Map([...items.value].slice(0, MAX_ITEMS));
*/
function unshiftItems(newItems: MisskeyEntity[]) {
const length = newItems.length + items.value.size;
items.value = new Map([...arrayToEntries(newItems), ...items.value].slice(0, MAX_ITEMS));
if (length >= MAX_ITEMS) canFetchMore.value = true;
} }
/** function unshiftItems(newItems: MisskeyEntity[]) {
* 古いアイテムをitemsの末尾に追加し、MAX_ITEMSを適用する items.value = new Map([...arrayToEntries(newItems), ...items.value]);
* @param oldItems 古いアイテムの配列 }
*/
function concatItems(oldItems: MisskeyEntity[]) {
const length = oldItems.length + items.value.size;
items.value = new Map([...items.value, ...arrayToEntries(oldItems)].slice(0, MAX_ITEMS));
if (length >= MAX_ITEMS) canFetchMore.value = true; function concatItems(oldItems: MisskeyEntity[]) {
items.value = new Map([...items.value, ...arrayToEntries(oldItems)]);
} }
function prepend(item: MisskeyEntity) { function prepend(item: MisskeyEntity) {
unshiftItems([item]); unshiftItems([item]);
} }
/*
* アイテムを末尾に追加する(使うの?)
*/
const appendItem = (item: MisskeyEntity): void => { const appendItem = (item: MisskeyEntity): void => {
items.value.set(item.id, item); items.value.set(item.id, item);
}; };
@@ -215,6 +203,7 @@ export function usePagination<T>(props: {
fetchMoreAhead, fetchMoreAhead,
unshiftItems, unshiftItems,
prepend, prepend,
trim,
error, error,
}; };
} }