fix: offset lazily
This commit is contained in:
1 parent
4dcbea4603
commit
7b40f90c0d
2 files changed
+15
-13
No files matched your search
@@ -37,21 +37,22 @@
|
|||||||
|
|
||||||
export let posts: PostView[]
|
export let posts: PostView[]
|
||||||
export let community: boolean = false
|
export let community: boolean = false
|
||||||
export let lastSeen: number | undefined = undefined
|
|
||||||
export let feedId: PostFeedID
|
export let feedId: PostFeedID
|
||||||
|
|
||||||
let combinedPosts = combineCrossposts(posts)
|
|
||||||
$: combinedPosts = combineCrossposts(posts)
|
|
||||||
|
|
||||||
let virtualItemEls: HTMLElement[] = []
|
let virtualItemEls: HTMLElement[] = []
|
||||||
let virtualListEl: HTMLElement | undefined = undefined
|
let virtualListEl: HTMLElement | undefined = undefined
|
||||||
|
|
||||||
$: virtualizer = createWindowVirtualizer({
|
const virtualizer = createWindowVirtualizer({
|
||||||
count: combinedPosts.length,
|
count: posts.length,
|
||||||
estimateSize: () => 0,
|
estimateSize: () => 150,
|
||||||
scrollMargin: virtualListEl?.offsetTop ?? 0,
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
$: if (posts.length)
|
||||||
|
$virtualizer.setOptions({
|
||||||
|
count: posts.length,
|
||||||
|
scrollMargin: virtualListEl?.offsetTop,
|
||||||
|
})
|
||||||
|
|
||||||
$: items = $virtualizer.getVirtualItems()
|
$: items = $virtualizer.getVirtualItems()
|
||||||
$: {
|
$: {
|
||||||
if (virtualItemEls.length)
|
if (virtualItemEls.length)
|
||||||
@@ -59,12 +60,12 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
afterNavigate(() => {
|
afterNavigate(() => {
|
||||||
|
console.log($postFeeds[feedId].lastSeen)
|
||||||
$virtualizer.scrollToIndex($postFeeds[feedId].lastSeen ?? 0)
|
$virtualizer.scrollToIndex($postFeeds[feedId].lastSeen ?? 0)
|
||||||
})
|
})
|
||||||
|
|
||||||
export let feedData: PostFeed['data']
|
export let feedData: PostFeed['data']
|
||||||
|
|
||||||
const limit = 20
|
|
||||||
let error: any = undefined
|
let error: any = undefined
|
||||||
let loading = false
|
let loading = false
|
||||||
let hasMore = true
|
let hasMore = true
|
||||||
@@ -220,15 +221,15 @@
|
|||||||
data-index={row.index}
|
data-index={row.index}
|
||||||
class="relative post-container"
|
class="relative post-container"
|
||||||
>
|
>
|
||||||
{#if combinedPosts[row.index]}
|
{#if posts[row.index]}
|
||||||
<Post
|
<Post
|
||||||
hideCommunity={community}
|
hideCommunity={community}
|
||||||
view={(combinedPosts[row.index]?.post.featured_community ||
|
view={(posts[row.index]?.post.featured_community ||
|
||||||
combinedPosts[row.index]?.post.featured_local) &&
|
posts[row.index]?.post.featured_local) &&
|
||||||
$userSettings.posts.compactFeatured
|
$userSettings.posts.compactFeatured
|
||||||
? 'compact'
|
? 'compact'
|
||||||
: $userSettings.view}
|
: $userSettings.view}
|
||||||
post={combinedPosts?.[row.index]}
|
post={posts?.[row.index]}
|
||||||
class="transition-all duration-250"
|
class="transition-all duration-250"
|
||||||
on:hide={() => {
|
on:hide={() => {
|
||||||
posts = posts.toSpliced(row.index, 1)
|
posts = posts.toSpliced(row.index, 1)
|
||||||
|
|||||||
@@ -37,6 +37,7 @@
|
|||||||
<ViewSelect />
|
<ViewSelect />
|
||||||
</div>
|
</div>
|
||||||
</header>
|
</header>
|
||||||
|
<div class="h-96">test</div>
|
||||||
|
|
||||||
<svelte:component
|
<svelte:component
|
||||||
this={browser ? VirtualFeed : PostFeed}
|
this={browser ? VirtualFeed : PostFeed}
|
||||||
|
|||||||
Reference in new issue
Block a user