import React, { useState, useEffect } from "react"; import { useParams, Outlet } from "react-router-dom"; import JSOG from "jsog"; import { ProfessorCard, ProfessorCardName, ProfessorCardSeparator, ProfessorCardDetails, } from "../Components/Styled/ProfessorCard.style"; import { EntityUl, EntityLi, EntityParam, EntityTypeSelector, } from "../Components/Styled/EntityList.style"; import SubjectsAccordion from "../Components/SubjectsAccordion"; import { CurrentPageNav } from "../Components/Styled/Main.style"; import LoadingSpinner from "../Components/Styled/LoadingSpinner.style"; const Faculty = () => { let params = useParams(); const [professors, setProfessors] = useState(null); const [studyProgrammes, setStudyProgrammes] = useState(null); const [professorOpinionCount, setProfessorOpinionCount] = useState(null); const [loadedProfessors, setLoadedProfessors] = useState(false); const [loadedStudyProgrammes, setLoadedStudyProgrammes] = useState(false); const [loadedProfessorOpinionCount, setLoadedProfessorOpinionCount] = useState(false); const [fetchError, setFetchError] = useState(false); const [entityType, setEntityType] = useState(0); useEffect(() => { const fetchProfessors = async () => { try { const response = await fetch(`http://192.168.1.254:8080/public/professors?facultyId=${params.facultyId}`); let cyclicGraph = await response.json(); let jsogStructure = JSOG.encode(cyclicGraph); cyclicGraph = JSOG.decode(jsogStructure); setProfessors(cyclicGraph); setLoadedProfessors(true); } catch (error) { setFetchError(true); } }; const fetchStudyProgrammes = async () => { try { const response2 = await fetch(`http://192.168.1.254:8080/public/study_programmes?facultyId=${params.facultyId}`); let cyclicGraph2 = await response2.json(); let jsogStructure2 = JSOG.encode(cyclicGraph2); cyclicGraph2 = JSOG.decode(jsogStructure2); setStudyProgrammes(cyclicGraph2); setLoadedStudyProgrammes(true); } catch (error) { setFetchError(true); } }; const fetchProfessorOpinionCount = async () => { try { const response3 = await fetch(`http://192.168.1.254:8080/public/faculty/${params.facultyId}/opinionCountForEachProfessor`); let cyclicGraph3 = await response3.json(); let jsogStructure3 = JSOG.encode(cyclicGraph3); cyclicGraph3 = JSOG.decode(jsogStructure3); setProfessorOpinionCount(cyclicGraph3); setLoadedProfessorOpinionCount(true); } catch (error) { setFetchError(true); } } fetchProfessors(); fetchStudyProgrammes(); fetchProfessorOpinionCount(); }, [params.facultyId]); return loadedProfessors && professors.length !== 0 ? ( entityType === 0 ? ( <> »{" "} {professors[0].faculty.university.universityName} {" "} » {professors[0].faculty.facultyName} {professors[0].faculty.facultyName} {professors[0].faculty.university.universityName}
Прикажи професори setEntityType(1)} > Прикажи предмети
{professors.map((professor, idx) => { let totalPosts = loadedProfessorOpinionCount ? parseInt(professorOpinionCount[idx].split(",")[1]) : 0; return ( {professor.professorName} {totalPosts !== 1 ? ( totalPosts !== 0 ? ( {totalPosts} {" "} мислења ) : ( {totalPosts} {" "} мислења ) ) : ( {totalPosts}{" "} мислење )} ); })}
) : ( loadedStudyProgrammes && ( <> »{" "} {professors[0].faculty.university.universityName} {" "} » {professors[0].faculty.facultyName} {professors[0].faculty.facultyName} {professors[0].faculty.university.universityName}
setEntityType(0)} > Прикажи професори Прикажи предмети
{studyProgrammes.map((studyProgramme) => { return ( ); })}
) ) ) : !fetchError && !loadedProfessors ? (
) : (

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

); }; export default Faculty;