diff --git a/src/lib/promise.ts b/src/lib/promise.ts new file mode 100644 index 00000000..7a9d17e5 --- /dev/null +++ b/src/lib/promise.ts @@ -0,0 +1,11 @@ +// to allow for loading before promises are finished on the client. + +import { browser } from '$app/environment' + +type AnyFunction = (...args: any[]) => any + +export const awaitIfServer = async ( + promise: Promise +): Promise<{ + data: Promise | T +}> => ({ data: browser ? promise : await promise }) diff --git a/src/routes/post/[instance]/[id=integer]/+page.svelte b/src/routes/post/[instance]/[id=integer]/+page.svelte index b693b489..8b9c450b 100644 --- a/src/routes/post/[instance]/[id=integer]/+page.svelte +++ b/src/routes/post/[instance]/[id=integer]/+page.svelte @@ -21,7 +21,7 @@ } from 'svelte-hero-icons' import PostLink from '$lib/components/lemmy/post/PostLink.svelte' import PostMeta from '$lib/components/lemmy/post/PostMeta.svelte' - import { Material, Select, removeToast, toast } from 'mono-svelte' + import { Material, Select, Spinner, removeToast, toast } from 'mono-svelte' import type { CommentSortType } from 'lemmy-js-client' import { profile } from '$lib/auth.js' import { instance } from '$lib/instance.js' @@ -47,17 +47,17 @@ let post = data.post - onMount(async () => { - if ( - !(post.post_view.read && $userSettings.markPostsAsRead) && - $profile?.jwt - ) { - getClient().markPostAsRead({ - read: $userSettings.markPostsAsRead, - post_id: post.post_view.post.id, - }) - } - }) + // onMount(async () => { + // if ( + // !(post.post_view.read && $userSettings.markPostsAsRead) && + // $profile?.jwt + // ) { + // getClient().markPostAsRead({ + // read: $userSettings.markPostsAsRead, + // post_id: post.post_view.post.id, + // }) + // } + // }) afterNavigate(async () => { // reactivity hack @@ -109,6 +109,8 @@ $: remoteView = $page.params.instance?.toLowerCase() != $instance.toLowerCase() + + const test = 'wow' @@ -302,36 +304,48 @@ flex-wrap gap-4 sticky top-20 w-full box-border z-20 mt-4" - {#if $profile?.user} - - (data.comments.comments = [ - comment.detail.comment_view, - ...data.comments.comments, - ])} - locked={post.post_view.post.locked || - $page.params.instance.toLowerCase() != $instance.toLowerCase()} - on:focus={() => (commenting = true)} - tools={commenting} - preview={commenting} - placeholder={commenting ? undefined : $t('routes.post.addComment')} - rows={commenting ? 7 : 1} + {#await data.comments} +
+ {#each new Array(10) as empty} +
+
+
+
+
+ {/each} +
+ {:then comments} + {#if $profile?.user} + + (comments.comments = [ + comment.detail.comment_view, + ...comments.comments, + ])} + locked={post.post_view.post.locked || + $page.params.instance.toLowerCase() != $instance.toLowerCase()} + on:focus={() => (commenting = true)} + tools={commenting} + preview={commenting} + placeholder={commenting ? undefined : $t('routes.post.addComment')} + rows={commenting ? 7 : 1} + /> + {/if} + + !( + ($userSettings.hidePosts.deleted && c.comment.deleted) || + ($userSettings.hidePosts.removed && c.comment.removed) + ) + )} + isParent={true} /> - {/if} - - !( - ($userSettings.hidePosts.deleted && c.comment.deleted) || - ($userSettings.hidePosts.removed && c.comment.removed) - ) - )} - isParent={true} - /> + {/await} {#if post.post_view.counts.comments > 5} @@ -350,3 +364,9 @@ flex-wrap gap-4 sticky top-20 w-full box-border z-20 mt-4" {/if}
+ + diff --git a/src/routes/post/[instance]/[id=integer]/+page.ts b/src/routes/post/[instance]/[id=integer]/+page.ts index a572f28f..dc884fac 100644 --- a/src/routes/post/[instance]/[id=integer]/+page.ts +++ b/src/routes/post/[instance]/[id=integer]/+page.ts @@ -1,22 +1,20 @@ +import { browser } from '$app/environment' import { env } from '$env/dynamic/public' import { profile } from '$lib/auth.js' import CommunityCard from '$lib/components/lemmy/community/CommunityCard.svelte' 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 { get } from 'svelte/store' export async function load({ params, url, fetch }) { - const post = await getClient(params.instance.toLowerCase(), fetch).getPost({ - id: Number(params.id), - }) - - let max_depth = post.post_view.counts.comments > 100 ? 1 : 3 - const thread = url.searchParams.get('thread') let parentId: number | undefined let showContext: string | undefined = undefined + let max_depth = 3 + if (thread) { const split = thread.split('.') if (split.length >= 9) { @@ -49,21 +47,26 @@ export async function load({ params, url, fetch }) { parent_id: parentId, } + const post = await getClient(params.instance.toLowerCase(), fetch).getPost({ + id: Number(params.id), + }) + const comments = getClient(params.instance, fetch).getComments(commentParams) + return { thread: { showContext: showContext, - singleThread: parentId != undefined + singleThread: parentId != undefined, }, post: post, commentSort: sort, - comments: await getClient(params.instance, fetch).getComments(commentParams), - slots: { - sidebar: { - component: CommunityCard, - props: { - community_view: post.community_view, - }, - }, - }, + comments: (await awaitIfServer(comments)).data, + // slots: { + // sidebar: { + // component: CommunityCard, + // props: { + // community_view: post.community_view, + // }, + // }, + // }, } }