source: reactapp/src/Pages/University.js@ 9bf1f8d

main
Last change on this file since 9bf1f8d was 9bf1f8d, checked in by viktor <viktor@…>, 22 months ago

prefinal

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