Comments & Updated caching

This commit is contained in:
2024-05-10 09:44:20 +03:00
parent 9983720bd1
commit 2781724f8f
11 changed files with 244 additions and 84 deletions
-2
View File
@@ -5,8 +5,6 @@ import { getPosts } from '$lib/server/db/post';
export async function load({ locals }) {
let result = await getPosts(locals.sql);
console.log(result);
return {
posts: result
};
+10 -3
View File
@@ -1,11 +1,18 @@
import { getCommentsForPost } from "$lib/server/db/comment";
import { getPost } from "$lib/server/db/post";
/** @type {import("@sveltejs/kit").ServerLoad} */
export async function load({ params, locals }) {
/** @type {import("$types/base").Post | import("$types/error").Error} */
const post = await getPost(locals.sql, Number(params.id));
const post_id = Number(params.id);
const post = await getPost(locals.sql, post_id);
const comments = await getCommentsForPost(locals.sql, post_id);
console.log(comments);
return {
post: post
post: post,
comments: comments
};
}
+18 -1
View File
@@ -1,12 +1,29 @@
<script>
import Comment from "$comp/comment.svelte";
import { buildCommentTree } from "$lib/client/nodetree";
/**
* @type {{post: import("$types/base").Post}}
* @type {{
* post: import("$types/base").Post,
* comments: import("$types/base").Result<import("$types/base").Comment>
* }}
*/
export let data;
console.log(data);
/**
* @type {import('$types/base').CommentTreeNode[]}
*/
let commentTree;
$: commentTree = buildCommentTree(data.comments);
</script>
<h1>{data.post.name}</h1>
<a href="#">{data.post.author?.name}</a>
<p>{data.post.content}</p>
<div>
{#each commentTree as reply}
<Comment commentNode={reply}></Comment>
{/each}
</div>