main
Line | |
---|
1 | import React, { useEffect, useState } from "react";
|
---|
2 | import { Outlet, useParams } from "react-router-dom";
|
---|
3 | import JSOG from "jsog";
|
---|
4 | import OpinionTree from "../Components/OpinionTree";
|
---|
5 |
|
---|
6 | function 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 |
|
---|
53 | export default Professor;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.