import { useNavigate } from "@solidjs/router";
import { JSXElement, Show, createSignal, useContext } from "solid-js";
import { LoginContext } from "../Context/GlobalState";
import { NewComment, createComment } from "../Util/api";
/** 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 {number} props.parentPostId The id of the post that the comment is a reply to.
* @returns {JSXElement} A JSXElement that contains a textarea and a submit button.
*/
interface NewCommentInputAreaProps {
parentPostId: number;
parentCommentId: number | null;
}
export function NewCommentInputArea(
props: NewCommentInputAreaProps
): JSXElement {
const [content, setContent] = createSignal("");
const [waiting, setWaiting] = createSignal(false);
const login_ctx = useContext(LoginContext)!;
const nav = useNavigate();
const sendComment = (): void => {
setWaiting(true);
const response = createComment({
content: content(),
user_token: login_ctx.token(),
parent_post_id: props.parentPostId,
parent_comment_id: props.parentCommentId,
} as NewComment);
if (response) {
response.then(() => {
setWaiting(false);
setContent("");
nav("/post/" + props.parentPostId);
});
}
};
return (