source: reactapp/src/Pages/Professor.js@ d654c74

main
Last change on this file since d654c74 was 0df6b9e, checked in by Viktor <mlviktor23@…>, 2 years ago

styled searchbar

  • Property mode set to 100644
File size: 2.1 KB
Line 
1import React, { useEffect, useState } from "react";
2import { Outlet, useParams } from "react-router-dom";
3import JSOG from "jsog";
4import OpinionTree from "../Components/OpinionTree";
5
6import {
7 ProfessorCard,
8 ProfessorCardDetails,
9 ProfessorCardName,
10 ProfessorCardSeparator,
11} from "../Components/ProfessorCard.style";
12
13function Professor(props) {
14 let params = useParams();
15
16 let [professor, setProfessor] = useState(null);
17 let [loaded, setLoaded] = useState(null);
18
19 useEffect(() => {
20 const url = `http://192.168.0.17:8080/public/professor/${params.professorId}`;
21
22 const fetchData = async () => {
23 try {
24 const response = await fetch(url);
25 var cyclicGraph = await response.json();
26 var jsogStructure = JSOG.encode(cyclicGraph); // has { '@ref': 'ID' } links instead of cycles
27 cyclicGraph = JSOG.decode(jsogStructure);
28 setProfessor(cyclicGraph);
29 setLoaded(true);
30 } catch (error) {
31 console.log("Error", error);
32 }
33 };
34
35 fetchData();
36 }, []);
37
38 if (loaded) {
39 return (
40 <div>
41 <ProfessorCard>
42 <ProfessorCardName>{professor.professorName}</ProfessorCardName>
43 <ProfessorCardSeparator />
44 <div style={{ marginTop: "10px" }}>
45 <ProfessorCardDetails fontSize="20px">
46 {professor.faculty.facultyName}
47 </ProfessorCardDetails>
48 <ProfessorCardDetails fontSize="15px">
49 {professor.faculty.university.universityName}
50 </ProfessorCardDetails>
51 </div>
52 </ProfessorCard>
53 <h3 style={{ marginBottom: "10px" }}>
54 {professor.relatedOpinions.length}{" "}
55 {professor.relatedOpinions.length !== 1 ? "мислења" : "мислење"}
56 </h3>
57 <div className="opinionTree">
58 <OpinionTree professor={professor} />
59 </div>
60 <Outlet />
61 </div>
62 );
63 } else {
64 return (
65 <div>
66 <p style={{ marginTop: "140px" }}>се вчитува...</p>
67 <Outlet />
68 </div>
69 );
70 }
71}
72
73export default Professor;
Note: See TracBrowser for help on using the repository browser.