source: reactapp/src/Pages/Professor.js@ 2998dc4

main
Last change on this file since 2998dc4 was 2998dc4, checked in by unknown <mlviktor23@…>, 2 years ago

made OpinionTree display author info

  • Property mode set to 100644
File size: 1.3 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
6function Professor(props) {
7 let params = useParams();
8
9 let [professor, setProfessor] = useState(null);
10 let [loaded, setLoaded] = useState(null);
11
12 useEffect(() => {
13 const url = `http://192.168.0.17:8080/public/professor/${params.professorId}`;
14
15 const fetchData = async () => {
16 try {
17 const response = await fetch(url);
18 var cyclicGraph = await response.json();
19 var jsogStructure = JSOG.encode(cyclicGraph); // has { '@ref': 'ID' } links instead of cycles
20 cyclicGraph = JSOG.decode(jsogStructure);
21 setProfessor(cyclicGraph);
22 setLoaded(true);
23 } catch (error) {
24 console.log("Error", error);
25 }
26 };
27
28 fetchData();
29 }, []);
30
31 if (loaded) {
32 return (
33 <div>
34 <h2>{professor.professorName}</h2>
35 <h3>{professor.faculty.facultyName}</h3>
36 <h3>Мислења</h3>
37 <div className="opinionTree">
38 <OpinionTree professor={professor} />
39 </div>
40 <Outlet />
41 </div>
42 );
43 } else {
44 return (
45 <div>
46 <p>loading</p>
47 <Outlet />
48 </div>
49 );
50 }
51}
52
53export default Professor;
Note: See TracBrowser for help on using the repository browser.