diff --git a/bun.lockb b/bun.lockb index 6592e57e..93edb82e 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/package.json b/package.json index 5072bf19..fcfdc9cd 100644 --- a/package.json +++ b/package.json @@ -40,6 +40,7 @@ "svelte": "latest", "svelte-check": "^3.0.1", "svelte-hero-icons": "^5.0.0", + "svelte-infinite-scroll": "^2.0.1", "svelte-tiny-virtual-list": "^2.0.5", "sveltekit-i18n": "^2.4.2", "tailwindcss": "^3.3.3", diff --git a/src/lib/components/lemmy/post/PostFeed.svelte b/src/lib/components/lemmy/post/PostFeed.svelte index 9bda3040..6d2ad026 100644 --- a/src/lib/components/lemmy/post/PostFeed.svelte +++ b/src/lib/components/lemmy/post/PostFeed.svelte @@ -98,7 +98,7 @@ {:else} - {#each combinedPosts as post, index (post.post.id)} + {#each combinedPosts as post, index} {#if !($userSettings.hidePosts.deleted && post.post.deleted) && !($userSettings.hidePosts.removed && post.post.removed)}
  • diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index cbc17fb2..d08fc4bd 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -1,26 +1,37 @@
    @@ -34,7 +45,13 @@
    - + + +
    + +
    + +
    (undefined) export async function load({ url, fetch }) { const cursor = url.searchParams.get('cursor') as string | undefined @@ -18,14 +21,22 @@ export async function load({ url, fetch }) { const listingType: ListingType = (url.searchParams.get('type') as ListingType) || settings.defaultSort.feed - const posts = await getClient(undefined, fetch).getPosts({ - limit: 20, - page: page, - sort: sort, - type_: listingType, - page_cursor: cursor, - show_hidden: settings.posts.showHidden, - }) + const cached = get(_posts) + + const posts = + cached && url.searchParams.toString() == cached.params.toString() + ? cached.data + : await getClient(undefined, fetch).getPosts({ + limit: 20, + page: page, + sort: sort, + type_: listingType, + page_cursor: cursor, + show_hidden: settings.posts.showHidden, + }) + + if (!(cached && url.searchParams.toString() == cached.params.toString())) + _posts.set({ data: posts, params: url.searchParams }) try { return { diff --git a/src/routes/post/[instance]/[id=integer]/+page.ts b/src/routes/post/[instance]/[id=integer]/+page.ts index dc884fac..5c677460 100644 --- a/src/routes/post/[instance]/[id=integer]/+page.ts +++ b/src/routes/post/[instance]/[id=integer]/+page.ts @@ -6,6 +6,7 @@ import { getClient } from '$lib/lemmy.js' import { awaitIfServer } from '$lib/promise.js' import { SSR_ENABLED, userSettings } from '$lib/settings.js' import { error } from '@sveltejs/kit' +import type { GetComments } from 'lemmy-js-client' import { get } from 'svelte/store' export async function load({ params, url, fetch }) { @@ -36,7 +37,7 @@ export async function load({ params, url, fetch }) { const sort = get(userSettings)?.defaultSort?.comments ?? 'Hot' - const commentParams: any = { + const commentParams: GetComments = { post_id: Number(params.id), type_: 'All', limit: 50, @@ -47,10 +48,10 @@ export async function load({ params, url, fetch }) { parent_id: parentId, } + const comments = getClient(params.instance, fetch).getComments(commentParams) const post = await getClient(params.instance.toLowerCase(), fetch).getPost({ id: Number(params.id), }) - const comments = getClient(params.instance, fetch).getComments(commentParams) return { thread: {