2024-03-24 22:39:25 +01:00
|
|
|
import {
|
|
|
|
JSXElement,
|
|
|
|
Show,
|
|
|
|
createEffect,
|
|
|
|
createSignal,
|
|
|
|
splitProps,
|
|
|
|
} from "solid-js";
|
2024-03-23 00:10:42 +01:00
|
|
|
|
2024-03-12 19:51:41 +01:00
|
|
|
import { Post } from "../Util/api";
|
2024-03-22 22:38:18 +01:00
|
|
|
import CommentsButton from "./Buttons/CommentsButton";
|
2024-03-22 20:39:34 +01:00
|
|
|
import EngagementButton from "./Buttons/Engegament";
|
|
|
|
import RemovePostButton from "./Buttons/RemovePostButton";
|
2024-03-19 15:23:12 +01:00
|
|
|
import ReportButton from "./Buttons/Report";
|
|
|
|
import ToPostButton from "./Buttons/ToPost";
|
2024-03-12 19:51:41 +01:00
|
|
|
|
2024-03-22 20:39:34 +01:00
|
|
|
export function PostSegment(props: { post: Post }): JSXElement {
|
2024-03-24 21:40:57 +01:00
|
|
|
const [local] = splitProps(props, ["post"]);
|
2024-03-24 22:39:25 +01:00
|
|
|
const [updatedAt, setUpdatedAt] = createSignal<string>("");
|
|
|
|
const [createdAt, setCreatedAT] = createSignal<string>("");
|
|
|
|
const [edited, setEdited] = createSignal<boolean>(false);
|
|
|
|
|
|
|
|
createEffect((): void => {
|
|
|
|
setUpdatedAt(new Date(local.post.createdAt).toDateString());
|
|
|
|
setCreatedAT(new Date(local.post.updatedAt).toDateString());
|
|
|
|
setEdited(updatedAt() === createdAt());
|
|
|
|
});
|
2024-03-12 19:51:41 +01:00
|
|
|
|
|
|
|
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">
|
2024-03-19 15:23:12 +01:00
|
|
|
<div class="flex flex-row justify-between">
|
2024-03-24 22:39:25 +01:00
|
|
|
<p class="text-xs">{createdAt()}</p>
|
2024-03-22 11:45:52 +01:00
|
|
|
<details class="dropdown">
|
2024-03-22 22:58:41 +01:00
|
|
|
<summary class="btn btn-sm">...</summary>
|
2024-03-22 20:39:34 +01:00
|
|
|
<ul class="w-26 menu dropdown-content z-[1] rounded-box bg-base-100 p-2 shadow">
|
2024-03-22 11:45:52 +01:00
|
|
|
<li>
|
|
|
|
<ReportButton />
|
|
|
|
</li>
|
|
|
|
<li>
|
2024-03-24 21:40:57 +01:00
|
|
|
<RemovePostButton postId={local.post.id} />
|
2024-03-22 11:45:52 +01:00
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</details>
|
2024-03-19 15:23:12 +01:00
|
|
|
</div>
|
2024-03-24 22:39:25 +01:00
|
|
|
<Show when={edited()}>
|
2024-03-12 19:51:41 +01:00
|
|
|
<p>This post has been edited</p>
|
|
|
|
</Show>
|
2024-03-24 21:40:57 +01:00
|
|
|
<p class="my-1 text-base">{local.post.content}</p>
|
2024-03-12 19:51:41 +01:00
|
|
|
<div class="card-actions justify-between">
|
2024-03-19 15:23:12 +01:00
|
|
|
<div class="flex">
|
2024-03-24 21:40:57 +01:00
|
|
|
<EngagementButton postId={local.post.id} />
|
|
|
|
<CommentsButton postId={local.post.id} />
|
2024-03-19 15:23:12 +01:00
|
|
|
</div>
|
2024-03-24 21:40:57 +01:00
|
|
|
<ToPostButton post={local.post} />
|
2024-03-12 19:51:41 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|