Comments & Updated caching
This commit is contained in:
@@ -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
|
||||
};
|
||||
|
||||
@@ -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
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user