1 | import React, { useState, useEffect } from "react";
|
---|
2 | import { useParams, Outlet } from "react-router-dom";
|
---|
3 | import JSOG from "jsog";
|
---|
4 | import {
|
---|
5 | ProfessorCard,
|
---|
6 | ProfessorCardName,
|
---|
7 | ProfessorCardSeparator,
|
---|
8 | ProfessorCardDetails,
|
---|
9 | } from "../Components/Styled/ProfessorCard.style";
|
---|
10 | import {
|
---|
11 | EntityUl,
|
---|
12 | EntityLi,
|
---|
13 | EntityParam,
|
---|
14 | } from "../Components/Styled/EntityList.style";
|
---|
15 | import { CurrentPageNav } from "../Components/Styled/Main.style";
|
---|
16 | import LoadingSpinner from "../Components/Styled/LoadingSpinner.style";
|
---|
17 |
|
---|
18 | const University = () => {
|
---|
19 | let params = useParams();
|
---|
20 | const [loaded, setLoaded] = useState(false);
|
---|
21 | const [faculties, setFaculties] = useState(null);
|
---|
22 | const [fetchError, setFetchError] = useState(false);
|
---|
23 |
|
---|
24 | useEffect(() => {
|
---|
25 | const url = `http://192.168.0.29:8080/public/faculties?universityId=${params.universityId}`;
|
---|
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 |
|
---|
42 | return loaded && !fetchError && faculties.length !== 0 ? (
|
---|
43 | <>
|
---|
44 | <CurrentPageNav>
|
---|
45 | » <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>
|
---|
77 | <EntityParam right="30px">
|
---|
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 | </>
|
---|
106 | ) : !fetchError && !loaded ? (
|
---|
107 | <div>
|
---|
108 | <LoadingSpinner style={{ marginTop: "140px" }}/>
|
---|
109 | <Outlet />
|
---|
110 | </div>
|
---|
111 | ) : (
|
---|
112 | <div style={{ marginTop: "140px" }}>
|
---|
113 | <h1 style={{ textAlign: "center" }}>Страницата не е пронајдена.</h1>
|
---|
114 | </div>
|
---|
115 | );
|
---|
116 | };
|
---|
117 |
|
---|
118 | export default University;
|
---|