Merge branch 'dev' of git.silversoft.se:Imbus/FrostByte into dev

This commit is contained in:
Imbus 2024-03-12 17:27:04 +01:00
commit 2b12a83aa8
7 changed files with 49 additions and 19 deletions

View file

@ -1,8 +1,12 @@
import { JSXElement } from "solid-js"; import { JSXElement } from "solid-js";
import { ReplyIcon } from "../Util/Icons";
import { EngagementIcon } from "../Util/Icons"; import { EngagementIcon } from "../Util/Icons";
import { PublicComment } from "../Util/api"; import { PublicComment } from "../Util/api";
import { NewCommentInputArea } from "./NewComment";
interface CommentProps {
comment: PublicComment;
}
/** /**
* Comment is a component that displays a single comment. * Comment is a component that displays a single comment.
@ -10,9 +14,9 @@ import { PublicComment } from "../Util/api";
* @param {string} props.postId The id of the post that the comment is a reply to. * @param {string} props.postId The id of the post that the comment is a reply to.
* @returns {JSXElement} A JSXElement of a comment * @returns {JSXElement} A JSXElement of a comment
*/ */
export function Comment({ comment }: { comment: PublicComment }): JSXElement { export function Comment({ comment }: CommentProps): JSXElement {
return ( return (
<div class="flex min-w-full flex-col rounded-lg border-b-secondary border-b-2 bg-base-300 px-5 py-3 text-base-content transition-all hover:bg-base-300 "> <div class="flex min-w-full flex-col rounded-lg border-b-2 border-b-secondary bg-base-300 px-5 py-3 text-base-content transition-all hover:bg-base-300 ">
<div class="flex flex-row"> <div class="flex flex-row">
<div class="pb-2 text-xs text-gray-500">{comment.created_at}</div> <div class="pb-2 text-xs text-gray-500">{comment.created_at}</div>
</div> </div>
@ -23,10 +27,27 @@ export function Comment({ comment }: { comment: PublicComment }): JSXElement {
{/* Placeholder icon, tbd */} {/* Placeholder icon, tbd */}
<EngagementIcon /> <EngagementIcon />
</div> </div>
<div class="btn self-end"> <section>
<ReplyIcon /> <ul class="timeline timeline-vertical">
</div> <li>
<div class="timeline-start">{comment.created_at}</div>
<div class="divider timeline-middle">:</div>
<div class="timeline-end timeline-box">{comment.content}</div>
<hr />
</li>
<li>
<div class="timeline-end">{comment.created_at}</div>
<div class="timeline-middle">:</div>
<div class="timeline-start timeline-box">{comment.content}</div>
<hr />
</li>
</ul>
</section>
</div> </div>
<NewCommentInputArea
parentCommentId={comment.parent_comment_id}
parentPostId={comment.parent_post_id}
/>
</div> </div>
); );
} }

View file

@ -10,9 +10,7 @@ import { Comment } from "./Comment";
* @returns {JSXElement} A JSXElement that contains a collection of comments. * @returns {JSXElement} A JSXElement that contains a collection of comments.
*/ */
export function CommentSection({ postId }: { postId: string }): JSXElement { export function CommentSection({ postId }: { postId: string }): JSXElement {
const [comments] = createResource(postId, () => const [comments] = createResource(postId, () => getComments(postId, 10, 0));
getComments(postId, 10, 0)
);
return ( return (
<For each={comments()!}>{(comment) => <Comment comment={comment} />}</For> <For each={comments()!}>{(comment) => <Comment comment={comment} />}</For>

View file

@ -4,6 +4,11 @@ import { JSXElement, Show, createSignal, useContext } from "solid-js";
import { LoginContext } from "../Context/GlobalState"; import { LoginContext } from "../Context/GlobalState";
import { NewComment, createComment } from "../Util/api"; import { NewComment, createComment } from "../Util/api";
interface NewCommentInputAreaProps {
parentPostId: number;
parentCommentId: number | null;
}
/** NewCommentInputArea is a component that allows users to submit a comment on a **post or comment**. /** NewCommentInputArea is a component that allows users to submit a comment on a **post or comment**.
* @param {Object} props The properties for the NewCommentInputArea component. * @param {Object} props The properties for the NewCommentInputArea component.
* @param {number} props.parentPostId The id of the post that the comment is a reply to. * @param {number} props.parentPostId The id of the post that the comment is a reply to.
@ -11,9 +16,8 @@ import { NewComment, createComment } from "../Util/api";
*/ */
export function NewCommentInputArea({ export function NewCommentInputArea({
parentPostId, parentPostId,
}: { parentCommentId,
parentPostId: number; }: NewCommentInputAreaProps): JSXElement {
}): JSXElement {
const [content, setContent] = createSignal(""); const [content, setContent] = createSignal("");
const [waiting, setWaiting] = createSignal(false); const [waiting, setWaiting] = createSignal(false);
@ -29,6 +33,7 @@ export function NewCommentInputArea({
content: content(), content: content(),
user_token: login_ctx.token(), user_token: login_ctx.token(),
parent_post_id: parentPostId, parent_post_id: parentPostId,
parent_comment_id: parentCommentId,
} as NewComment); } as NewComment);
if (response) { if (response) {

View file

@ -1,11 +1,18 @@
import { useParams } from "@solidjs/router"; import { useParams } from "@solidjs/router";
import { JSXElement, Show, Suspense, createResource, useContext } from "solid-js"; import {
JSXElement,
Show,
Suspense,
createResource,
useContext,
} from "solid-js";
import { LoginContext } from "../Context/GlobalState"; import { LoginContext } from "../Context/GlobalState";
import { loadSpinner } from "../Util/Icons"; import { loadSpinner } from "../Util/Icons";
import { getPost } from "../Util/api"; import { getPost } from "../Util/api";
import { CommentSection } from "./CommentSection"; import { CommentSection } from "./CommentSection";
import { PostSegment } from "./Posts";
import { NewCommentInputArea } from "./NewComment"; import { NewCommentInputArea } from "./NewComment";
import { PostSegment } from "./Posts";
export function SinglePost(): JSXElement { export function SinglePost(): JSXElement {
const params = useParams(); const params = useParams();

View file

@ -3,8 +3,6 @@ import { JSXElement } from "solid-js";
// MainContainer is the main container for the page. // MainContainer is the main container for the page.
export function PageContainer(props: { children: JSXElement }): JSXElement { export function PageContainer(props: { children: JSXElement }): JSXElement {
return ( return (
<div class="flex min-h-screen flex-col items-center"> <div class="flex min-h-screen flex-col items-center">{props.children}</div>
{props.children}
</div>
); );
} }

View file

@ -20,6 +20,7 @@ export interface NewComment {
content: string; content: string;
user_token: string; user_token: string;
parent_post_id: number; parent_post_id: number;
parent_comment_id?: number;
} }
export interface Comment extends NewComment { export interface Comment extends NewComment {