feat(SampleList): move font list display into widget layer
This commit is contained in:
1
src/widgets/SampleList/index.ts
Normal file
1
src/widgets/SampleList/index.ts
Normal file
@@ -0,0 +1 @@
|
|||||||
|
export { SampleList } from './ui';
|
||||||
66
src/widgets/SampleList/ui/SampleList/SampleList.svelte
Normal file
66
src/widgets/SampleList/ui/SampleList/SampleList.svelte
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
<!--
|
||||||
|
Component: SampleList
|
||||||
|
Renders a list of fonts in a virtualized list to improve performance.
|
||||||
|
Includes pagination with auto-loading when scrolling near the bottom.
|
||||||
|
-->
|
||||||
|
<script lang="ts">
|
||||||
|
import {
|
||||||
|
FontListItem,
|
||||||
|
FontVirtualList,
|
||||||
|
unifiedFontStore,
|
||||||
|
} from '$entities/Font';
|
||||||
|
import { FontSampler } from '$features/DisplayFont';
|
||||||
|
|
||||||
|
let text = $state('The quick brown fox jumps over the lazy dog...');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
||||||
|
*/
|
||||||
|
const displayRange = $derived.by(() => {
|
||||||
|
const { offset, limit, total } = unifiedFontStore.pagination;
|
||||||
|
const loadedCount = Math.min(offset + limit, total);
|
||||||
|
return `Showing ${loadedCount} of ${total} fonts`;
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{#if unifiedFontStore.isFetching || unifiedFontStore.isLoading}
|
||||||
|
<span class="ml-2 text-xs text-muted-foreground/70">(Loading...)</span>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
<FontVirtualList
|
||||||
|
items={unifiedFontStore.fonts}
|
||||||
|
total={unifiedFontStore.pagination.total}
|
||||||
|
onNearBottom={handleNearBottom}
|
||||||
|
itemHeight={280}
|
||||||
|
>
|
||||||
|
{#snippet children({ item: font, isVisible, proximity, index })}
|
||||||
|
<FontListItem {font} {isVisible} {proximity}>
|
||||||
|
<FontSampler font={font} bind:text index={index} />
|
||||||
|
</FontListItem>
|
||||||
|
{/snippet}
|
||||||
|
</FontVirtualList>
|
||||||
3
src/widgets/SampleList/ui/index.ts
Normal file
3
src/widgets/SampleList/ui/index.ts
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
import SampleList from './SampleList/SampleList.svelte';
|
||||||
|
|
||||||
|
export { SampleList };
|
||||||
Reference in New Issue
Block a user