import { OpinionCard, OpinionCardContent, OpinionCardContentTime, OpinionCardContentTitle, OpinionReplyCard, OpinionReplyCardContent, OpinionReplyCardContentTime, StyledFontAwesomeIcon, } 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 handleLike = () => { if (auth) { return; } else { navigate("/login"); } }; const handleDislike = () => { if (auth) { return; } else { navigate("/login"); } }; const handleReply = () => { if (auth) { setReplyModalDisplay("block"); } 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.19:8080/secure/professor/${professor.professorId}/replyToOpinion/${postId}`, { method: "post", data: { 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}

{dateConverter( new Date(child.timePosted).toString().slice(4, -43) )} {auth && userLoaded && user.user.id !== child.author.id && ( <> )}
{child.children.map((childOfChild) => displayChildPosts( childOfChild, child.author.username, replyIndent + 30 ) )}
); } return (
{professor.relatedOpinions.map((opinion) => { if (!renderedOpinionIds.includes(opinion.postId)) { postCount = renderedOpinionIds.push(opinion.postId); return (
×

Реплика на {opinion.author.username}

handleReplySubmit(e, opinion.postId)}> РЕПЛИЦИРАЈ

{opinion.author.username} напишал

{opinion.title}

{opinion.content}

{dateConverter( new Date(opinion.timePosted).toString().slice(4, -43) )} {auth && userLoaded && user.user.id !== opinion.author.id && ( <> )}
{opinion.children.map((child) => displayChildPosts(child, opinion.author.username, 30) )}
); } })}
); } export default OpinionTree;