source: reactapp/src/Pages/University.js@ a5aba17

main
Last change on this file since a5aba17 was af801e3, checked in by viktor <viktor@…>, 2 years ago

finished edit/delete/displace opinion/thread from report (react); todo reporting user/opinion/thread interface, public user pages and messaging (springboot)

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