FrostByte/client-solid/src/Components/PostSegment.tsx

42 lines
1.4 KiB
TypeScript
Raw Normal View History

import { JSXElement, Show } from "solid-js";
import { Post } from "../Util/api";
import EngagementButton from "./Buttons/Engegament";
import ReplyButton from "./Buttons/Replies";
import ReportButton from "./Buttons/Report";
import ToPostButton from "./Buttons/ToPost";
/**
* PostSegment is used to display posts in both the main feed and the post view
*
* @param {Object} props The properties for the PostSegment component.
* @param {Post} props.post The post to display.
* @returns {JSXElement} A JSXElement of a post
*/
export function PostSegment({ post }: { post: Post }): JSXElement {
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">
<div class="flex flex-row justify-between">
<h3>{dateOfCreation}</h3>
<ReportButton />
</div>
<Show when={isEdited}>
<p>This post has been edited</p>
</Show>
<p class="break-words text-base-content md:pt-2">{post.content}</p>
<div class="card-actions justify-between">
<div class="flex">
<EngagementButton post={post} />
<ReplyButton post={post} />
</div>
<ToPostButton post={post} />
</div>
</div>
</div>
);
}