2023-10-27 16:04:58 +02:00
|
|
|
import { useParams } from "@solidjs/router";
|
2024-02-27 03:54:55 +01:00
|
|
|
import { For, JSXElement, Show, Suspense, createResource } from "solid-js";
|
2023-11-15 07:29:59 +01:00
|
|
|
|
2023-11-22 15:29:27 +01:00
|
|
|
import { loadSpinner } from "../Util/Icons";
|
2024-02-27 03:54:55 +01:00
|
|
|
import { getComments, getPost } from "../Util/api";
|
2023-11-15 07:29:59 +01:00
|
|
|
import { PostSegment } from "./Posts";
|
2023-10-27 16:04:58 +02:00
|
|
|
|
2023-11-13 12:00:46 +01:00
|
|
|
export function SinglePost(): JSXElement {
|
2023-10-27 16:04:58 +02:00
|
|
|
const params = useParams();
|
|
|
|
const [post] = createResource(params.postid, getPost);
|
2024-02-27 03:54:55 +01:00
|
|
|
const [comments] = createResource(params.postid, () =>
|
|
|
|
getComments(params.postid, 0, 10)
|
|
|
|
);
|
2023-10-27 16:04:58 +02:00
|
|
|
|
|
|
|
return (
|
2023-11-13 12:10:40 +01:00
|
|
|
<Suspense fallback={loadSpinner()}>
|
2023-11-15 07:29:59 +01:00
|
|
|
<Show when={post()}>
|
|
|
|
<PostSegment post={post()!} />
|
2024-02-27 03:54:55 +01:00
|
|
|
<For each={comments()!}>
|
|
|
|
{(comment) => (
|
|
|
|
// TODO: This should be a separate component
|
|
|
|
<div class="comment">
|
|
|
|
<p>{comment.content}</p>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</For>
|
2023-11-15 07:29:59 +01:00
|
|
|
</Show>
|
2023-10-27 16:04:58 +02:00
|
|
|
</Suspense>
|
|
|
|
);
|
|
|
|
}
|