fix: offset and post flickers
This commit is contained in:
1 parent
e9c9d72693
commit
25303be2fe
1 file changed
+9
-12
@@ -23,6 +23,7 @@
|
|||||||
import {
|
import {
|
||||||
createVirtualizer,
|
createVirtualizer,
|
||||||
createWindowVirtualizer,
|
createWindowVirtualizer,
|
||||||
|
type SvelteVirtualizer,
|
||||||
} from '@tanstack/svelte-virtual'
|
} from '@tanstack/svelte-virtual'
|
||||||
import { afterNavigate, beforeNavigate } from '$app/navigation'
|
import { afterNavigate, beforeNavigate } from '$app/navigation'
|
||||||
import { combineCrossposts } from './crosspost'
|
import { combineCrossposts } from './crosspost'
|
||||||
@@ -34,6 +35,7 @@
|
|||||||
} from '$lib/lemmy/postfeed'
|
} from '$lib/lemmy/postfeed'
|
||||||
import { t } from '$lib/translations'
|
import { t } from '$lib/translations'
|
||||||
import InfiniteScroll from 'svelte-infinite-scroll'
|
import InfiniteScroll from 'svelte-infinite-scroll'
|
||||||
|
import type { Readable } from 'svelte/motion'
|
||||||
|
|
||||||
export let posts: PostView[]
|
export let posts: PostView[]
|
||||||
export let community: boolean = false
|
export let community: boolean = false
|
||||||
@@ -45,20 +47,21 @@
|
|||||||
const virtualizer = createWindowVirtualizer({
|
const virtualizer = createWindowVirtualizer({
|
||||||
count: posts.length,
|
count: posts.length,
|
||||||
estimateSize: () => 150,
|
estimateSize: () => 150,
|
||||||
|
// @ts-ignore
|
||||||
|
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)
|
||||||
virtualItemEls.forEach((el) => $virtualizer.measureElement(el))
|
virtualItemEls.forEach((el) => $virtualizer.measureElement(el))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$: $virtualizer.setOptions({
|
||||||
|
scrollMargin: virtualListEl?.offsetTop ?? 0,
|
||||||
|
count: posts.length,
|
||||||
|
})
|
||||||
|
|
||||||
afterNavigate(() => {
|
afterNavigate(() => {
|
||||||
console.log($postFeeds[feedId].lastSeen)
|
console.log($postFeeds[feedId].lastSeen)
|
||||||
$virtualizer.scrollToIndex($postFeeds[feedId].lastSeen ?? 0)
|
$virtualizer.scrollToIndex($postFeeds[feedId].lastSeen ?? 0)
|
||||||
@@ -211,12 +214,6 @@
|
|||||||
>
|
>
|
||||||
{#each items as row, index (row.index)}
|
{#each items as row, index (row.index)}
|
||||||
<li
|
<li
|
||||||
in:fly|global={{
|
|
||||||
y: -8,
|
|
||||||
duration: 300,
|
|
||||||
opacity: 0,
|
|
||||||
delay: 50 + index * 20,
|
|
||||||
}}
|
|
||||||
bind:this={virtualItemEls[index]}
|
bind:this={virtualItemEls[index]}
|
||||||
data-index={row.index}
|
data-index={row.index}
|
||||||
class="relative post-container"
|
class="relative post-container"
|
||||||
|
|||||||
Reference in new issue
Block a user