Refactor of dateOfCreation, Addition of edited check in frontend, Endpoint added for engagement on posts

This commit is contained in:
Hollgy 2024-03-12 18:57:14 +01:00
parent f9ef90e61f
commit cedb469105
2 changed files with 17 additions and 1 deletions

View file

@ -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 (
<div class="card compact w-full flex-grow border-b-2 border-b-primary bg-base-200 text-base-content transition-all hover:bg-base-300">
<div class="card-body md:mx-6">
<h3>
{post.createdAt ?? "No Creation Date"}
{dateOfCreation}
</h3>
<Show when={isEdited}>
<p>This post has been edited</p>
</Show>
<p class="break-words text-base-content md:pt-2">
{post.content}
</p>

View file

@ -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<void> {
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,