Draft implementation of comments

This commit is contained in:
Imbus 2024-02-27 03:54:55 +01:00
parent 62f3e0d72f
commit fafce18907
2 changed files with 38 additions and 2 deletions

View file

@ -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<Post[]> {
const res = await fetch("/api/posts");
const data = await res.json();
@ -44,6 +56,19 @@ export async function createPost(post: NewPost): Promise<void> {
});
}
// Gets the comments for a specific post
export async function getComments(
postId: string,
limit: number,
offset: number
): Promise<PublicComment[]> {
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,