Refactor: Better PostMetric API and Rendering

This commit is contained in:
2024-05-15 18:07:40 +03:00
parent 63ab10318f
commit 499fd6fa5b
13 changed files with 185 additions and 154 deletions
+7 -12
View File
@@ -1,22 +1,17 @@
import { getPosts } from '$lib/server/db/post';
import { getPostMetricsForPostId } from '$lib/server/db/postmertics';
import { getPost, getPosts } from '$lib/server/db/post';
/** @type {import('./$types').PageServerLoad} */
export async function load({ locals, url }) {
const result = await getPosts(locals.sql, undefined, 10, 0, true);
const result = await getPosts(locals.sql);
// const glance = url.searchParams.get('glance');
// const glanceID = glance ? parseInt(glance) : null
const glance = url.searchParams.get('glance');
const glanceID = glance ? parseInt(glance) : null
// let postMetrics = null;
// if (glanceID) {
// postMetrics = await getPostMetricsForPostId(glanceID);
// }
console.log(result);
const glancePost = glanceID ? await getPost(locals.sql, glanceID, { withMetrics: true }) : null;
return {
posts: result
posts: result,
glancePost: glancePost
};
}
+3 -2
View File
@@ -3,11 +3,12 @@
/**
* @type {{
* posts: import("$types/base").Post[]
* posts: import("$types/base").Post[],
* glancePost: import("$types/base").Post | null
* }}
*/
export let data;
</script>
<h1>Posts</h1>
<Postlist posts={data.posts}></Postlist>
<Postlist posts={data.posts} glancePost={data.glancePost}></Postlist>