import { OpinionCard, OpinionCardContent, OpinionCardContentTime, OpinionCardContentTitle, OpinionReplyCard, OpinionReplyCardContent, OpinionReplyCardContentTime, StyledFontAwesomeIcon, VoteCount, } from "./Styled/OpinionCard.style"; import { solid } from "@fortawesome/fontawesome-svg-core/import.macro"; import { dateConverter } from "../Util/dateConverter"; import AuthApi from "../api/AuthApi"; import { useNavigate } from "react-router-dom"; import { useContext, useState } from "react"; import { Modal, ModalContent, ModalClose, ModalHeader, ModalBody, ModalTextarea, ModalFooter, } from "../Components/Styled/Modal.style"; import axios from "../api/axios"; function OpinionTree({ professor, user, userLoaded }) { var renderedOpinionIds = []; var postCount; // za da ne go pokazuva ispod postot let navigate = useNavigate(); const { auth, setAuth } = useContext(AuthApi); let [replyModalDisplay, setReplyModalDisplay] = useState("none"); const [replyContent, setReplyContent] = useState(""); const [postForModal, setPostForModal] = useState(null); const handleLike = async (post) => { if ( auth && userLoaded && !post.likes.some((e) => e.id === user.user.id) && !post.dislikes.some((e) => e.id === user.user.id) ) { const response = await axios( `http://192.168.0.17:8080/secure/professor/${professor.professorId}/upvoteOpinion/${post.postId}`, { method: "get", withCredentials: true, } ); window.location.reload(false); } else { return; } }; const handleDislike = async (post) => { if ( auth && auth && userLoaded && !post.likes.some((e) => e.id === user.user.id) && !post.dislikes.some((e) => e.id === user.user.id) ) { const response = await axios( `http://192.168.0.17:8080/secure/professor/${professor.professorId}/downvoteOpinion/${post.postId}`, { method: "get", withCredentials: true, } ); window.location.reload(false); } else { return; } }; const handleReply = (opinion) => { if (auth) { setReplyModalDisplay("block"); setPostForModal(opinion); } else { navigate("/login"); } }; const handleModalCloseClick = () => { setReplyModalDisplay("none"); }; const handleContentChange = (e) => { setReplyContent(e.target.value); }; const handleReplySubmit = async (e, postId) => { e.preventDefault(); const response = await axios( `http://192.168.0.17:8080/secure/professor/${professor.professorId}/replyToOpinion/${postId}`, { method: "post", body: { content: replyContent, }, withCredentials: true, } ); window.location.reload(false); //console.log(response); }; function displayChildPosts(child, parentPostAuthorUsername, replyIndent) { if (child == null) return; postCount = renderedOpinionIds.push(child.postId); return (
{child.author.username} му реплицирал на{" "} {parentPostAuthorUsername}
{child.content}
{opinion.author.username} напишал
{opinion.content}