Refactor: Better PostMetric API and Rendering
This commit is contained in:
@@ -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,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>
|
||||
|
||||
Reference in New Issue
Block a user