perf: async load posts on main page

This commit is contained in:
James Xylight committed 2025-08-29 19:23:08 -07:00
1 parent 59e99c04d8
commit 29c2e97efc
4 files changed
+81 -58

No files matched your search

+19 -15
View File
@@ -1,6 +1,6 @@
import { t } from '$lib/i18n/translations.js'
import { postFeed } from '$lib/lemmy/postfeed.svelte.js'
import { ReactiveState } from '$lib/promise.svelte.js'
import { ReactiveState, awaitIfServer } from '$lib/promise.svelte.js'
import { settings } from '$lib/settings.svelte'
import type { ListingType, SortType } from 'lemmy-js-client'
import { ChevronDoubleUp } from 'svelte-hero-icons'
@@ -13,21 +13,25 @@ export async function load({ url, fetch }) {
const listingType: ListingType =
(url.searchParams.get('type') as ListingType) || settings.defaultSort.feed
const feed = postFeed({
id: 'main',
request: {
page_cursor: cursor,
sort: sort,
type_: listingType,
limit: 20,
show_hidden: settings.posts.showHidden,
},
url: url,
fetch: fetch,
})
return {
feed: new ReactiveState(
await postFeed({
id: 'main',
request: {
page_cursor: cursor,
sort: sort,
type_: listingType,
limit: 20,
show_hidden: settings.posts.showHidden,
},
url: url,
fetch: fetch,
}),
),
feed: new ReactiveState((await awaitIfServer(feed)).data),
filters: new ReactiveState({
sort: sort,
type_: listingType,
}),
contextual: {
actions: [
{