2023-10-27 16:04:58 +02:00
|
|
|
import { useParams } from "@solidjs/router";
|
2024-03-11 22:05:49 +01:00
|
|
|
import {
|
|
|
|
JSXElement,
|
|
|
|
Show,
|
|
|
|
Suspense,
|
|
|
|
createResource,
|
|
|
|
useContext,
|
|
|
|
} from "solid-js";
|
|
|
|
|
2024-03-08 10:04:35 +01:00
|
|
|
import { LoginContext } from "../Context/GlobalState";
|
2023-11-22 15:29:27 +01:00
|
|
|
import { loadSpinner } from "../Util/Icons";
|
2024-03-06 00:48:19 +01:00
|
|
|
import { getPost } from "../Util/api";
|
|
|
|
import { CommentSection } from "./CommentSection";
|
|
|
|
import { NewCommentInputArea } from "./NewComment";
|
2024-03-11 22:05:49 +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-03-08 10:04:35 +01:00
|
|
|
const login_ctx = useContext(LoginContext)!; // Assuming login context is always available
|
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-03-08 10:04:35 +01:00
|
|
|
<Show when={login_ctx.loggedIn()}>
|
2024-03-12 17:59:28 +01:00
|
|
|
<NewCommentInputArea parentCommentId={null} parentPostId={parseInt(params.postid)} />
|
2024-03-08 10:04:35 +01:00
|
|
|
</Show>
|
2024-03-06 08:10:42 +01:00
|
|
|
<CommentSection postId={params.postid} />
|
2023-11-15 07:29:59 +01:00
|
|
|
</Show>
|
2023-10-27 16:04:58 +02:00
|
|
|
</Suspense>
|
|
|
|
);
|
|
|
|
}
|