feat(FontVirtualList): move logic related to loading next batch of fonts to the FontVirtualContainer

This commit is contained in:
Ilia Mashkov
2026-02-15 22:56:37 +03:00
parent bc56265717
commit c2d0992015
2 changed files with 40 additions and 58 deletions

View File

@@ -24,38 +24,6 @@ let innerHeight = $state(0);
// Is the component above the middle of the viewport?
let isAboveMiddle = $state(false);
const isLoading = $derived(
unifiedFontStore.isFetching || unifiedFontStore.isLoading,
);
/**
* Load more fonts by moving to the next page
*/
function loadMore() {
if (
!unifiedFontStore.pagination.hasMore
|| unifiedFontStore.isFetching
) {
return;
}
unifiedFontStore.nextPage();
}
/**
* Handle scroll near bottom - auto-load next page
*
* Triggered by VirtualList when the user scrolls within 5 items of the end
* of the loaded items. Only fetches if there are more pages available.
*/
function handleNearBottom(_lastVisibleIndex: number) {
const { hasMore } = unifiedFontStore.pagination;
// VirtualList already checks if we're near the bottom of loaded items
if (hasMore && !unifiedFontStore.isFetching) {
loadMore();
}
}
/**
* Calculate display range for pagination info
*/
@@ -83,13 +51,9 @@ const checkPosition = throttle(() => {
<div bind:this={wrapper}>
<FontVirtualList
items={unifiedFontStore.fonts}
total={unifiedFontStore.pagination.total}
onNearBottom={handleNearBottom}
itemHeight={220}
useWindowScroll={true}
weight={controlManager.weight}
{isLoading}
>
{#snippet children({
item: font,