2026-01-18 15:55:07 +03:00
|
|
|
<!--
|
|
|
|
|
Component: SuggestedFonts
|
|
|
|
|
Renders a list of suggested fonts in a virtualized list to improve performance.
|
2026-01-30 19:21:47 +03:00
|
|
|
Includes pagination with auto-loading when scrolling near the bottom.
|
2026-01-18 15:55:07 +03:00
|
|
|
-->
|
2026-01-18 14:56:25 +03:00
|
|
|
<script lang="ts">
|
|
|
|
|
import {
|
|
|
|
|
FontListItem,
|
|
|
|
|
FontVirtualList,
|
2026-01-29 14:43:07 +03:00
|
|
|
unifiedFontStore,
|
2026-01-18 14:56:25 +03:00
|
|
|
} from '$entities/Font';
|
2026-01-30 19:21:47 +03:00
|
|
|
import { cn } from '$shared/shadcn/utils/shadcn-utils';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Load more fonts by moving to the next page
|
|
|
|
|
*/
|
|
|
|
|
function loadMore() {
|
2026-01-31 11:48:14 +03:00
|
|
|
if (
|
|
|
|
|
!unifiedFontStore.pagination.hasMore
|
|
|
|
|
|| unifiedFontStore.isFetching
|
|
|
|
|
) {
|
2026-01-30 19:21:47 +03:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
unifiedFontStore.nextPage();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Handle scroll near bottom - auto-load next page
|
|
|
|
|
*
|
2026-01-31 11:48:14 +03:00
|
|
|
* 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.
|
2026-01-30 19:21:47 +03:00
|
|
|
*/
|
2026-01-31 11:48:14 +03:00
|
|
|
function handleNearBottom(_lastVisibleIndex: number) {
|
|
|
|
|
const { hasMore } = unifiedFontStore.pagination;
|
2026-01-30 19:21:47 +03:00
|
|
|
|
2026-01-31 11:48:14 +03:00
|
|
|
// VirtualList already checks if we're near the bottom of loaded items
|
|
|
|
|
if (hasMore && !unifiedFontStore.isFetching) {
|
2026-01-30 19:21:47 +03:00
|
|
|
loadMore();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Calculate display range for pagination info
|
|
|
|
|
*/
|
|
|
|
|
const displayRange = $derived.by(() => {
|
|
|
|
|
const { offset, limit, total } = unifiedFontStore.pagination;
|
|
|
|
|
const loadedCount = Math.min(offset + limit, total);
|
|
|
|
|
return `Showing ${loadedCount} of ${total} fonts`;
|
|
|
|
|
});
|
2026-01-18 14:56:25 +03:00
|
|
|
</script>
|
|
|
|
|
|
2026-01-31 11:48:14 +03:00
|
|
|
{#if unifiedFontStore.isFetching || unifiedFontStore.isLoading}
|
|
|
|
|
<span class="ml-2 text-xs text-muted-foreground/70">(Loading...)</span>
|
2026-01-30 19:21:47 +03:00
|
|
|
{/if}
|
|
|
|
|
|
|
|
|
|
<FontVirtualList
|
|
|
|
|
items={unifiedFontStore.fonts}
|
|
|
|
|
total={unifiedFontStore.pagination.total}
|
|
|
|
|
onNearBottom={handleNearBottom}
|
|
|
|
|
>
|
2026-01-22 15:40:17 +03:00
|
|
|
{#snippet children({ item: font, isVisible, proximity })}
|
|
|
|
|
<FontListItem {font} {isVisible} {proximity} />
|
2026-01-18 14:56:25 +03:00
|
|
|
{/snippet}
|
|
|
|
|
</FontVirtualList>
|