impr: fetch post data from feeds to display page instantly

This commit is contained in:
James Xylight committed 2025-08-05 12:41:40 -07:00
1 parent 172da3b025
commit ea5124df77
4 files changed
+297 -223

No files matched your search

@@ -20,7 +20,7 @@
import { settings } from '$lib/settings.svelte.js'
import { isImage } from '$lib/ui/image.js'
import { Button, toast } from 'mono-svelte'
import { onMount } from 'svelte'
import { onMount, untrack } from 'svelte'
import {
ArrowLeft,
ArrowRight,
@@ -32,6 +32,7 @@
import { fly } from 'svelte/transition'
import CommentProvider from './CommentProvider.svelte'
import { ReactiveState } from '$lib/promise.svelte'
import { postFeeds } from '$lib/lemmy/postfeed.svelte'
let { data } = $props()
@@ -54,6 +55,21 @@
})
})
$effect(() => {
data.post.value.meta.then(
res => (data.post.value.post_view = res.post_view),
)
})
$effect(() => {
if (data.cachedFeed && data.post.value.post_view) {
untrack(() => {
const { id, index } = data.cachedFeed!
postFeeds.value[id].data.posts.posts[index] = data.post.value.post_view
})
}
})
let loading = $state(false)
async function reloadComments() {
@@ -117,7 +133,7 @@
<PostMeta
community={data.post.value.post_view.community}
user={data.post.value.post_view.creator}
subscribed={data.post.value.community_view.subscribed}
subscribed="NotSubscribed"
badges={{
deleted: data.post.value.post_view.post.deleted,
removed: data.post.value.post_view.post.removed,
@@ -171,34 +187,36 @@
})}
/>
</div>
{#if data.post.value.cross_posts?.length > 0}
{@const crossposts = data.post.value.cross_posts}
<Expandable
class="text-base mt-2 w-full cursor-pointer"
open={crossposts?.length <= 3}
>
{#snippet title()}
<div
class="flex items-center gap-1 w-full text-left text-base font-normal"
>
<span class="font-bold">{crossposts.length}</span>
{$t('routes.post.crosspostCount')}
<hr
class="flex-1 inline-block w-full border-slate-200 dark:border-zinc-800 mx-3"
/>
</div>
{/snippet}
<div
class="divide-y! divide-slate-200 dark:divide-zinc-800 flex flex-col"
{#await data.post.value.meta then meta}
{@const crossposts = meta.cross_posts}
{#if crossposts?.length > 0}
<Expandable
class="text-base mt-2 w-full cursor-pointer"
open={crossposts?.length <= 3}
>
{#key crossposts}
{#each crossposts as crosspost (crosspost.post.id)}
<Post view="compact" post={crosspost} />
{/each}
{/key}
</div>
</Expandable>
{/if}
{#snippet title()}
<div
class="flex items-center gap-1 w-full text-left text-base font-normal"
>
<span class="font-bold">{crossposts.length}</span>
{$t('routes.post.crosspostCount')}
<hr
class="flex-1 inline-block w-full border-slate-200 dark:border-zinc-800 mx-3"
/>
</div>
{/snippet}
<div
class="divide-y! divide-slate-200 dark:divide-zinc-800 flex flex-col"
>
{#key crossposts}
{#each crossposts as crosspost (crosspost.post.id)}
<Post view="compact" post={crosspost} />
{/each}
{/key}
</div>
</Expandable>
{/if}
{/await}
</article>
{#if data.thread.value.showContext || data.thread.value.singleThread}
<div
@@ -266,7 +284,7 @@
{@const comments = new ReactiveState(passedComments)}
<CommentProvider
comments={comments.value}
post={data.post.value}
post={data.post.value.post_view}
focus={data.thread.value.focus}
onupdate={reloadComments}
bind:sort={data.commentSort.value}