fix: reactivity issue causing comment tree to rebuild

This commit is contained in:
Xyphyn committed 2023-08-19 15:43:56 -07:00
1 parent 79221e2e53
commit fee08ed7ed
2 files changed
+50 -50

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "photon-lemmy", "name": "photon-lemmy",
"version": "0.9.11", "version": "0.9.12",
"private": true, "private": true,
"scripts": { "scripts": {
"dev": "vite dev", "dev": "vite dev",
@@ -26,17 +26,21 @@
export let data export let data
let post = data.post
onMount(async () => { onMount(async () => {
if (!data.post.post_view.read && $profile?.jwt) { if (!post.post_view.read && $profile?.jwt) {
getClient().markPostAsRead({ getClient().markPostAsRead({
auth: $profile.jwt, auth: $profile.jwt,
read: true, read: true,
post_id: data.post.post_view.post.id, post_id: post.post_view.post.id,
}) })
} }
}) })
afterNavigate(async () => { afterNavigate(async () => {
// reactivity hack
post = data.post
if ( if (
$page.params.instance.toLowerCase() != $instance.toLowerCase() && $page.params.instance.toLowerCase() != $instance.toLowerCase() &&
$profile?.jwt $profile?.jwt
@@ -49,7 +53,7 @@
try { try {
const res = await getClient().resolveObject({ const res = await getClient().resolveObject({
auth: $profile.jwt, auth: $profile.jwt,
q: data.post.post_view.post.ap_id, q: post.post_view.post.ap_id,
}) })
if (res.post) { if (res.post) {
@@ -76,7 +80,7 @@
page: 1, page: 1,
limit: 25, limit: 25,
type_: 'All', type_: 'All',
post_id: data.post.post_view.post.id, post_id: post.post_view.post.id,
sort: commentSort, sort: commentSort,
max_depth: 3, max_depth: 3,
}) })
@@ -84,14 +88,14 @@
</script> </script>
<svelte:head> <svelte:head>
<title>{data.post.post_view.post.name}</title> <title>{post.post_view.post.name}</title>
<meta property="og:title" content={data.post.post_view.post.name} /> <meta property="og:title" content={post.post_view.post.name} />
<meta property="og:url" content={$page.url.toString()} /> <meta property="og:url" content={$page.url.toString()} />
{#if isImage(data.post.post_view.post.url)} {#if isImage(post.post_view.post.url)}
<meta property="og:image" content={data.post.post_view.post.url} /> <meta property="og:image" content={post.post_view.post.url} />
{/if} {/if}
{#if data.post.post_view.post.body} {#if post.post_view.post.body}
<meta property="og:description" content={data.post.post_view.post.body} /> <meta property="og:description" content={post.post_view.post.body} />
{/if} {/if}
</svelte:head> </svelte:head>
@@ -113,56 +117,56 @@
{/if} {/if}
<PostMeta <PostMeta
community={data.post.post_view.community} community={post.post_view.community}
user={data.post.post_view.creator} user={post.post_view.creator}
upvotes={data.post.post_view.counts.upvotes} upvotes={post.post_view.counts.upvotes}
downvotes={data.post.post_view.counts.downvotes} downvotes={post.post_view.counts.downvotes}
deleted={data.post.post_view.post.deleted} deleted={post.post_view.post.deleted}
removed={data.post.post_view.post.removed} removed={post.post_view.post.removed}
locked={data.post.post_view.post.locked} locked={post.post_view.post.locked}
featured={data.post.post_view.post.featured_community || featured={post.post_view.post.featured_community ||
data.post.post_view.post.featured_local} post.post_view.post.featured_local}
nsfw={data.post.post_view.post.nsfw} nsfw={post.post_view.post.nsfw}
published={new Date(data.post.post_view.post.published + 'Z')} published={new Date(post.post_view.post.published + 'Z')}
saved={data.post.post_view.saved} saved={post.post_view.saved}
/> />
<h1 class="font-bold text-lg">{data.post.post_view.post.name}</h1> <h1 class="font-bold text-lg">{post.post_view.post.name}</h1>
{#if isImage(data.post.post_view.post.url)} {#if isImage(post.post_view.post.url)}
<img <img
src={data.post.post_view.post.url} src={post.post_view.post.url}
alt={data.post.post_view.post.name} alt={post.post_view.post.name}
class="rounded-md max-w-screen max-h-[80svh] mx-auto" class="rounded-md max-w-screen max-h-[80svh] mx-auto"
/> />
{:else if isVideo(data.post.post_view.post.url)} {:else if isVideo(post.post_view.post.url)}
<!-- svelte-ignore a11y-media-has-caption --> <!-- svelte-ignore a11y-media-has-caption -->
<video class="rounded-md max-w-screen max-h-[80svh] mx-auto" controls> <video class="rounded-md max-w-screen max-h-[80svh] mx-auto" controls>
<source src={data.post.post_view.post.url} /> <source src={post.post_view.post.url} />
</video> </video>
{:else if data.post.post_view.post.url && !data.post.post_view.post.thumbnail_url} {:else if post.post_view.post.url && !post.post_view.post.thumbnail_url}
<a <a
href={data.post.post_view.post.url} href={post.post_view.post.url}
class="max-w-full overflow-hidden overflow-ellipsis whitespace-nowrap text-sky-400 hover:underline text-xs" class="max-w-full overflow-hidden overflow-ellipsis whitespace-nowrap text-sky-400 hover:underline text-xs"
> >
{data.post.post_view.post.url} {post.post_view.post.url}
</a> </a>
{:else if data.post.post_view.post.thumbnail_url && data.post.post_view.post.url} {:else if post.post_view.post.thumbnail_url && post.post_view.post.url}
<PostLink <PostLink
thumbnail_url={data.post.post_view.post.thumbnail_url} thumbnail_url={post.post_view.post.thumbnail_url}
url={data.post.post_view.post.url} url={post.post_view.post.url}
nsfw={data.post.post_view.post.nsfw} nsfw={post.post_view.post.nsfw}
/> />
{/if} {/if}
{#if data.post.post_view.post.body} {#if post.post_view.post.body}
<div <div
class="bg-slate-100 border border-slate-200 dark:border-zinc-800 class="bg-slate-100 border border-slate-200 dark:border-zinc-800
dark:bg-zinc-900 p-2 text-sm rounded-md leading-[22px]" dark:bg-zinc-900 p-2 text-sm rounded-md leading-[22px]"
> >
<Markdown source={data.post.post_view.post.body} /> <Markdown source={post.post_view.post.body} />
</div> </div>
{/if} {/if}
<div class="w-full relative"> <div class="w-full relative">
<PostActions <PostActions
bind:post={data.post.post_view} bind:post={post.post_view}
on:edit={() => on:edit={() =>
toast({ toast({
content: 'The post was edited successfully.', content: 'The post was edited successfully.',
@@ -170,15 +174,15 @@
})} })}
/> />
</div> </div>
{#if data.post.cross_posts?.length > 0} {#if post.cross_posts?.length > 0}
<div class="text-sm font-bold mt-2"> <div class="text-sm font-bold mt-2">
<SectionTitle class="text-inherit dark:text-inherit"> <SectionTitle class="text-inherit dark:text-inherit">
Crossposts <span class="text-slate-600 dark:text-zinc-400 text-xs ml-1"> Crossposts <span class="text-slate-600 dark:text-zinc-400 text-xs ml-1">
{data.post.cross_posts.length} {post.cross_posts.length}
</span> </span>
</SectionTitle> </SectionTitle>
<div class="divide-y divide-slate-200 dark:divide-zinc-800 flex flex-col"> <div class="divide-y divide-slate-200 dark:divide-zinc-800 flex flex-col">
{#each data.post.cross_posts as crosspost} {#each post.cross_posts as crosspost}
<div class="py-2.5 flex flex-col gap-1"> <div class="py-2.5 flex flex-col gap-1">
<span class="text-xs flex flex-col pointer-events-none"> <span class="text-xs flex flex-col pointer-events-none">
<CommunityLink <CommunityLink
@@ -202,7 +206,7 @@
<div class="mt-4 flex flex-col gap-2"> <div class="mt-4 flex flex-col gap-2">
<div class="font-bold text-lg"> <div class="font-bold text-lg">
Comments <span class="text-sm font-normal ml-2 opacity-80"> Comments <span class="text-sm font-normal ml-2 opacity-80">
{data.post.post_view.counts.comments} {post.post_view.counts.comments}
</span> </span>
</div> </div>
<MultiSelect <MultiSelect
@@ -223,13 +227,13 @@
{:then comments} {:then comments}
{#if $profile?.user} {#if $profile?.user}
<CommentForm <CommentForm
postId={data.post.post_view.post.id} postId={post.post_view.post.id}
on:comment={(comment) => on:comment={(comment) =>
(comments.comments = [ (comments.comments = [
comment.detail.comment_view, comment.detail.comment_view,
...comments.comments, ...comments.comments,
])} ])}
locked={data.post.post_view.post.locked || locked={post.post_view.post.locked ||
$page.params.instance.toLowerCase() != $instance.toLowerCase()} $page.params.instance.toLowerCase() != $instance.toLowerCase()}
/> />
{/if} {/if}
@@ -238,11 +242,7 @@
<Spinner width={36} /> <Spinner width={36} />
</div> </div>
{:then comments} {:then comments}
<Comments <Comments post={post.post_view.post} nodes={comments} isParent={true} />
post={data.post.post_view.post}
nodes={comments}
isParent={true}
/>
{/await} {/await}
{:catch} {:catch}
<div class="bg-red-500/10 border border-red-500 rounded-md p-4"> <div class="bg-red-500/10 border border-red-500 rounded-md p-4">