This commit is contained in:
2024-05-10 10:53:48 +03:00
parent f98583a77d
commit b9320d9529
5 changed files with 57 additions and 13 deletions
@@ -1,9 +1,15 @@
import { getCommentsForPost } from "$lib/server/db/comment";
import { getPost } from "$lib/server/db/post";
import { getIdFromName } from "$lib/util";
import { error } from "@sveltejs/kit";
/** @type {import("@sveltejs/kit").ServerLoad} */
export async function load({ params, locals }) {
const post_id = Number(params.id);
const post_id = getIdFromName(params.name);
if (post_id === null) {
error(404, `No Post of ID ${params.name}`);
}
const post = await getPost(locals.sql, post_id);
@@ -1,6 +1,8 @@
<script>
import Comment from "$comp/comment.svelte";
import { buildCommentTree } from "$lib/client/nodetree";
import { getNamedId, gotoNamedId } from "$lib/util";
import { onMount } from "svelte";
/**
* @type {{
@@ -10,18 +12,22 @@
*/
export let data;
console.log(data);
$: post = data.post;
/**
* @type {import('$types/base').CommentTreeNode[]}
*/
let commentTree;
$: commentTree = buildCommentTree(data.comments);
onMount(() => {
gotoNamedId(post.id, post.name);
})
</script>
<h1>{data.post.name}</h1>
<a href="#">{data.post.author?.name}</a>
<p>{data.post.content}</p>
<h1>{post.name}</h1>
{#if post.author}
<a href="/users/{getNamedId(post.author.id, post.author.name)}">{post.author.name}</a>
{:else}
<p>Deleted</p>
{/if}
<p>{post.content}</p>
<div>
{#each commentTree as reply}
<Comment commentNode={reply}></Comment>