From fafce18907fde5bb7ef6cc05675204f9b0b37073 Mon Sep 17 00:00:00 2001
From: Imbus <>
Date: Tue, 27 Feb 2024 03:54:55 +0100
Subject: [PATCH] Draft implementation of comments
---
client-solid/src/Components/SinglePost.tsx | 15 +++++++++++--
client-solid/src/Util/api.ts | 25 ++++++++++++++++++++++
2 files changed, 38 insertions(+), 2 deletions(-)
diff --git a/client-solid/src/Components/SinglePost.tsx b/client-solid/src/Components/SinglePost.tsx
index 285df2f..0c41de1 100644
--- a/client-solid/src/Components/SinglePost.tsx
+++ b/client-solid/src/Components/SinglePost.tsx
@@ -1,18 +1,29 @@
import { useParams } from "@solidjs/router";
-import { JSXElement, Show, Suspense, createResource } from "solid-js";
+import { For, JSXElement, Show, Suspense, createResource } from "solid-js";
import { loadSpinner } from "../Util/Icons";
-import { getPost } from "../Util/api";
+import { getComments, getPost } from "../Util/api";
import { PostSegment } from "./Posts";
export function SinglePost(): JSXElement {
const params = useParams();
const [post] = createResource(params.postid, getPost);
+ const [comments] = createResource(params.postid, () =>
+ getComments(params.postid, 0, 10)
+ );
return (
+
+ {(comment) => (
+ // TODO: This should be a separate component
+
+ )}
+
);
diff --git a/client-solid/src/Util/api.ts b/client-solid/src/Util/api.ts
index 03c759d..cd30a91 100644
--- a/client-solid/src/Util/api.ts
+++ b/client-solid/src/Util/api.ts
@@ -22,6 +22,18 @@ export interface AuthResponse {
token: string;
}
+// This is what a public comment looks like, as it arrives from the server
+export interface PublicComment {
+ id: number;
+ parent_post_id: number;
+ parent_comment_id: number | null;
+ upvotes: number;
+ downvotes: number;
+ content: string;
+ created_at: string;
+ updated_at: string;
+}
+
export async function getPosts(): Promise {
const res = await fetch("/api/posts");
const data = await res.json();
@@ -44,6 +56,19 @@ export async function createPost(post: NewPost): Promise {
});
}
+// Gets the comments for a specific post
+export async function getComments(
+ postId: string,
+ limit: number,
+ offset: number
+): Promise {
+ const res = await fetch(
+ `/api/comments?post_id=${postId}&limit=${limit}&offset=${offset}`
+ );
+ const data = await res.json();
+ return data;
+}
+
// Send the registration request to the server
export async function submitRegistration(
username: string,
{comment.content}
+