import { Button, Modal, ToggleSwitch, Label, Textarea } from "flowbite-react"; import { CommentsComment } from "./Comments.Comment"; import { useState } from "react"; import { ENDPOINTS } from "#/api/config"; export const CommentsAddModal = (props: { isOpen: boolean; setIsOpen: any; release_id: number; isReply?: boolean; parentComment?: any; parentProfile?: any; token: string; setShouldRender?: any; setCommentSend?: any; }) => { const [message, setMessage] = useState( props.isReply ? `${props.parentProfile.login}, ` : "" ); const [isSpoiler, setIsSpoiler] = useState(false); const [isSending, setIsSending] = useState(false); function _sendComment(e) { e.preventDefault(); const re = /\n/gi; const data = { message: message.replace(re, "\r\n").trim(), parentCommentId: !props.parentComment ? null : props.parentComment.id, replyToProfileId: !props.parentProfile ? null : props.parentProfile.id, spoiler: isSpoiler, }; async function _send() { const res = await fetch( `${ENDPOINTS.release.info}/comment/add/${props.release_id}?token=${props.token}`, { method: "POST", body: JSON.stringify(data), } ); if (props.isReply && props.setShouldRender && props.setCommentSend) { props.setShouldRender(true); props.setCommentSend(true); } setMessage(props.isReply ? `${props.parentProfile.login}, ` : ""); setIsSpoiler(false); props.setIsOpen(false); setIsSending(false); } if (props.token && message.trim() != "") { setIsSending(true); _send(); } } return ( props.setIsOpen(false)} >

{props.isReply ? "Ответ на комментарий" : "Оставить комментарий"}

{props.isReply && (
)}
_sendComment(e)}>