import React, { useEffect, useState, useContext } from "react"; import { Outlet, useParams } from "react-router-dom"; import JSOG from "jsog"; import OpinionTree from "../Components/OpinionTree"; import { AddOpinionButton, Modal, ModalContent, ModalClose, ModalHeader, ModalBody, ModalInput, ModalTextarea, ModalFooter, } from "../Components/Styled/Modal.style"; import { ProfessorCard, ProfessorCardDetails, ProfessorCardName, ProfessorCardSeparator, } from "../Components/Styled/ProfessorCard.style"; import AuthApi from "../api/AuthApi"; import { useNavigate } from "react-router-dom"; import axios from "../api/axios"; import { CurrentPageNav } from "../Components/Styled/Main.style"; import LoadingSpinner from "../Components/Styled/LoadingSpinner.style"; function Professor() { let params = useParams(); let navigate = useNavigate(); const [professor, setProfessor] = useState(null); const [loadedProfessor, setLoadedProfessor] = useState(false); const [relatedOpinions, setRelatedOpinions] = useState(null); const [loadedRelatedOpinions, setLoadedRelatedOpinions] = useState(false); const [postModalDisplay, setPostModalDisplay] = useState("none"); const { auth, setAuth } = useContext(AuthApi); const [postContent, setPostContent] = useState(""); const [fetchError, setFetchError] = useState(false); const [errorMessage, setErrorMessage] = useState(""); useEffect(() => { Promise.all([fetch(`http://192.168.1.108:8080/public/professor/${params.professorId}`), fetch(`http://192.168.1.108:8080/public/professor/${params.professorId}/relatedOpinions`)]) .then(([resProfessor, resRelatedOpinions]) => Promise.all([resProfessor.json(), resRelatedOpinions.json()])) .then(([dataProfessor, dataRelatedOpinions]) => { let cyclicGraph1 = dataProfessor; let jsogStructure1 = JSOG.encode(cyclicGraph1); cyclicGraph1 = JSOG.decode(jsogStructure1); setProfessor(cyclicGraph1); setLoadedProfessor(true); let cyclicGraph2 = dataRelatedOpinions; let jsogStructure2 = JSOG.encode(cyclicGraph2); cyclicGraph2 = JSOG.decode(jsogStructure2); setRelatedOpinions(cyclicGraph2); setLoadedRelatedOpinions(true); }) }, []); const handleAddOpinionButtonClick = () => { if (auth) { setPostModalDisplay("block"); document.body.style.overflowY = "hidden"; } else { navigate("/login"); } }; const handleModalCloseClick = () => { setPostModalDisplay("none"); document.body.style.overflowY = "auto"; }; const handlePostSubmit = async (e) => { e.preventDefault(); if (!postContent.length < 1) { const response = await axios( `http://192.168.1.108:8080/secure/professor/${params.professorId}/addOpinion`, { method: "post", data: { content: postContent, }, withCredentials: true, } ); setErrorMessage(""); window.location.reload(); } else { setErrorMessage("Полето за содржина не смее да биде празно"); } }; const handleContentChange = (e) => { setPostContent(e.target.value); }; if (loadedProfessor) { return (
»{" "} {professor.faculty.university.universityName} {" "} »{" "} {professor.faculty.facultyName} {" "} » {professor.professorName} {professor.professorName} #{professor.professorId}
{professor.faculty.facultyName} {professor.faculty.university.universityName}

{relatedOpinions.length}{" "} {relatedOpinions.length !== 1 ? "мислења" : "мислење"}

{auth && ( Објави мислење )}
×

Мислење за {professor.professorName}

{errorMessage}

ОБЈАВИ
); } else if (!fetchError) { return (
); } else { return (

Страницата не е пронајдена.

); } } export default Professor;