source: reactapp/src/Pages/University.js@ 3b6962d

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

moderation/reporting api in spring boot

  • Property mode set to 100644
File size: 3.7 KB
Line 
1import React, { useState, useEffect } from "react";
2import { useParams, Outlet } from "react-router-dom";
3import JSOG from "jsog";
4import {
5 ProfessorCard,
6 ProfessorCardName,
7 ProfessorCardSeparator,
8 ProfessorCardDetails,
9} from "../Components/Styled/ProfessorCard.style";
10import {
11 EntityUl,
12 EntityLi,
13 EntityParam,
14} from "../Components/Styled/EntityList.style";
15import { CurrentPageNav } from "../Components/Styled/Main.style";
16
17const University = () => {
18 let params = useParams();
19 const [loaded, setLoaded] = useState(false);
20 const [faculties, setFaculties] = useState(null);
21 const [fetchError, setFetchError] = useState(false);
22
23 useEffect(() => {
24 const url = `http://192.168.0.19:8080/public/faculties?universityId=${params.universityId}`;
25
26 const fetchData = async () => {
27 try {
28 const response = await fetch(url);
29 var cyclicGraph = await response.json();
30 var jsogStructure = JSOG.encode(cyclicGraph);
31 cyclicGraph = JSOG.decode(jsogStructure);
32 setFaculties(cyclicGraph);
33 setLoaded(true);
34 } catch (error) {
35 setFetchError(true);
36 }
37 };
38 fetchData();
39 }, [params.universityId]);
40
41 return loaded && !fetchError && faculties.length !== 0 ? (
42 <>
43 <CurrentPageNav>
44 &#187; <a href="#">{faculties[0].university.universityName}</a>
45 </CurrentPageNav>
46 <ProfessorCard>
47 <ProfessorCardName>
48 {faculties[0].university.universityName}
49 </ProfessorCardName>
50 <ProfessorCardSeparator />
51 <ProfessorCardDetails fontSize="20px">
52 {faculties[0].university.city.cityName}
53 </ProfessorCardDetails>
54 </ProfessorCard>
55 <div key={params.universityId}>
56 {faculties.map((faculty) => {
57 let totalPosts = 0;
58 let totalSections = 0;
59 faculty.professors.map((professor) => {
60 totalPosts += professor.relatedOpinions.length;
61 totalSections++;
62 });
63 faculty.studyProgrammes.map((studyProgramme) => {
64 studyProgramme.subjects.map((subject) => {
65 totalPosts += subject.threads.length;
66 totalSections++;
67 });
68 });
69
70 return (
71 <EntityUl key={faculty.facultyId}>
72 <EntityLi bgcolor="cornsilk">
73 <a href={"/faculty/" + faculty.facultyId}>
74 {faculty.facultyName}
75 </a>
76 <EntityParam right="30px">
77 {totalSections}{" "}
78 {totalSections !== 1 ? (
79 <span style={{ fontWeight: "normal" }}>секции,</span>
80 ) : (
81 <span style={{ fontWeight: "normal" }}>секција</span>
82 )}
83 <span style={{ opacity: totalPosts === 0 ? "0.5" : "1" }}>
84 {totalPosts}
85 </span>{" "}
86 {totalPosts !== 1 ? (
87 <span
88 style={{
89 fontWeight: "normal",
90 opacity: totalPosts === 0 ? "0.5" : "1",
91 }}
92 >
93 мислења
94 </span>
95 ) : (
96 <span style={{ fontWeight: "normal" }}>мислење</span>
97 )}
98 </EntityParam>
99 </EntityLi>
100 </EntityUl>
101 );
102 })}
103 </div>
104 </>
105 ) : !fetchError && !loaded ? (
106 <div>
107 <p style={{ marginTop: "140px" }}>се вчитува...</p>
108 <Outlet />
109 </div>
110 ) : (
111 <div style={{ marginTop: "140px" }}>
112 <h1 style={{ textAlign: "center" }}>Страницата не е пронајдена.</h1>
113 </div>
114 );
115};
116
117export default University;
Note: See TracBrowser for help on using the repository browser.