Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 22 additions & 5 deletions src/lib/feature/post/feed/VirtualFeed.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script lang="ts">
import { browser } from '$app/environment'
import { client } from '$lib/api/client.svelte'
import { client, site } from '$lib/api/client.svelte'
import type { GetPosts, PostView } from '$lib/api/types'
import { errorMessage } from '$lib/app/error'
import { t } from '$lib/app/i18n'
Expand Down Expand Up @@ -48,7 +48,8 @@

let error = $state()
let loading = $state(false)
let hasMore = $state(true)
let hasMore = $state(false)
let feedKey = $state('')

const abortLoad = new AbortController()
let seenIds = new SvelteSet<number>(posts.map((post) => post.post.id))
Expand All @@ -70,7 +71,7 @@

error = null

hasMore = newPosts.posts.length != 0
hasMore = !!newPosts.next_page

params.page_cursor = newPosts.next_page

Expand Down Expand Up @@ -148,6 +149,21 @@
}
})

$effect(() => {
const limit = params?.limit ?? 20
const nextKey = JSON.stringify({
...params,
page_cursor: undefined,
page: undefined,
})

if (nextKey !== feedKey) {
feedKey = nextKey
seenIds = new SvelteSet<number>(posts.map((post) => post.post.id))
hasMore = posts.length >= limit
}
})

let initialOffset = $derived(listEl?.offsetTop)

onDestroy(() => {
Expand Down Expand Up @@ -233,7 +249,7 @@
{$t('message.retry')}
</Button>
</Material>
{:else if hasMore}
{:else if loading}
<div class="w-full h-32 grid place-items-center">
<Spinner width={24} />
</div>
Expand All @@ -243,7 +259,8 @@
{$t('routes.frontpage.endFeed', {
community_name:
params.community_name ??
'Lemmy. There are no more posts. You saw them all.',
site.data?.site_view?.site?.name ??
'Lemmy. There are no more posts. You saw them all', // TODO: This should be translated
})}
{#snippet action()}
<Button color="tertiary" icon={ChevronDoubleUp}>
Expand Down