From cedb469105ec5b3e24c6c46bb09413f60409c076 Mon Sep 17 00:00:00 2001 From: Hollgy Date: Tue, 12 Mar 2024 18:57:14 +0100 Subject: [PATCH] Refactor of dateOfCreation, Addition of edited check in frontend, Endpoint added for engagement on posts --- client-solid/src/Components/Posts.tsx | 8 +++++++- client-solid/src/Util/api.ts | 10 ++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/client-solid/src/Components/Posts.tsx b/client-solid/src/Components/Posts.tsx index a1a1f84..4f7bc6b 100644 --- a/client-solid/src/Components/Posts.tsx +++ b/client-solid/src/Components/Posts.tsx @@ -26,12 +26,18 @@ export function Posts(): JSXElement { export function PostSegment({ post } : { post: Post }): JSXElement { const nav = useNavigate(); + const dateOfCreation = new Date(post.createdAt).toDateString() + const isEdited = ! (post.createdAt == post.updatedAt) + return (

- {post.createdAt ?? "No Creation Date"} + {dateOfCreation}

+ +

This post has been edited

+

{post.content}

diff --git a/client-solid/src/Util/api.ts b/client-solid/src/Util/api.ts index 4209cc8..095bfe6 100644 --- a/client-solid/src/Util/api.ts +++ b/client-solid/src/Util/api.ts @@ -13,6 +13,7 @@ interface Votes { export interface Post extends NewPost { id: string; createdAt: string; + updatedAt: string; votes: Votes; } @@ -91,6 +92,15 @@ export async function getComments( return data; } +/** Incomplete */ +export async function engagePost( + postId: string +): Promise { + const res = await fetch(`/api/engage_post?post_id=${postId}`); + const data = await res.json(); + return data; +} + // Send the registration request to the server export async function submitRegistration( username: string,