source: reactapp/src/Pages/Faculty.js@ 8d83180

main
Last change on this file since 8d83180 was 8d83180, checked in by unknown <mlviktor23@…>, 21 months ago

forums/page nav

  • Property mode set to 100644
File size: 7.9 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 EntityTypeSelector,
15} from "../Components/Styled/EntityList.style";
16import SubjectsAccordion from "../Components/SubjectsAccordion";
17import { CurrentPageNav } from "../Components/Styled/Main.style";
18
19const Faculty = () => {
20 let params = useParams();
21 const [loadedProfessors, setLoadedProfessors] = useState(false);
22 const [loadedStudyProgrammes, setLoadedStudyProgrammes] = useState(false);
23 const [professors, setProfessors] = useState(null);
24 const [studyProgrammes, setStudyProgrammes] = useState(null);
25 const [fetchError, setFetchError] = useState(false);
26 const [entityType, setEntityType] = useState(0);
27
28 useEffect(() => {
29 const urlProfessors = `http://192.168.0.17:8080/public/professors?facultyId=${params.facultyId}`;
30 const urlStudyProgrammes = `http://192.168.0.17:8080/public/study_programmes?facultyId=${params.facultyId}`;
31
32 const fetchDataProfessors = async () => {
33 try {
34 const response = await fetch(urlProfessors);
35 let cyclicGraph = await response.json();
36 let jsogStructure = JSOG.encode(cyclicGraph);
37 cyclicGraph = JSOG.decode(jsogStructure);
38 setProfessors(cyclicGraph);
39 setLoadedProfessors(true);
40 } catch (error) {
41 setFetchError(true);
42 }
43 };
44
45 const fetchDataStudyProgrammes = async () => {
46 try {
47 const response2 = await fetch(urlStudyProgrammes);
48 let cyclicGraph2 = await response2.json();
49 let jsogStructure2 = JSOG.encode(cyclicGraph2);
50 cyclicGraph2 = JSOG.decode(jsogStructure2);
51 setStudyProgrammes(cyclicGraph2);
52 setLoadedStudyProgrammes(true);
53 } catch (error) {
54 setFetchError(true);
55 }
56 };
57
58 fetchDataProfessors();
59 fetchDataStudyProgrammes();
60 }, [params.facultyId]);
61
62 return loadedProfessors ? (
63 entityType === 0 ? (
64 <>
65 <CurrentPageNav>
66 &#187;{" "}
67 <a
68 href={
69 "/university/" + professors[0].faculty.university.universityId
70 }
71 >
72 {professors[0].faculty.university.universityName}
73 </a>{" "}
74 &#187; <a href="#">{professors[0].faculty.facultyName}</a>
75 </CurrentPageNav>
76 <ProfessorCard>
77 <ProfessorCardName>
78 {professors[0].faculty.facultyName}
79 </ProfessorCardName>
80 <ProfessorCardSeparator />
81 <ProfessorCardDetails fontSize="20px">
82 {professors[0].faculty.university.universityName}
83 </ProfessorCardDetails>
84 </ProfessorCard>
85 <div style={{ display: "flex" }}>
86 <EntityTypeSelector
87 backgroundcolor="rgba(0, 102, 204, 1)"
88 color="white"
89 boxshadow="none"
90 boxshadowhover="none"
91 opacityhover="0.6"
92 cursor="auto"
93 >
94 Прикажи професори
95 </EntityTypeSelector>
96 <EntityTypeSelector
97 boxshadow="2px 2px 5px #aaaaaa"
98 cursor="pointer"
99 boxshadowhover="2px 2px 10px #aaaaaa"
100 opacityhover="1"
101 onClick={() => setEntityType(1)}
102 >
103 Прикажи предмети
104 </EntityTypeSelector>
105 </div>
106 <div key={params.facultyId}>
107 {professors.map((professor) => {
108 let totalPosts = professor.relatedOpinions.length;
109
110 return (
111 <EntityUl key={professor.professorId}>
112 <EntityLi bgcolor="cornsilk">
113 <a href={"/professor/" + professor.professorId}>
114 {professor.professorName}
115 </a>
116 <EntityParam>
117 {totalPosts !== 1 ? (
118 totalPosts !== 0 ? (
119 <span
120 style={{
121 fontWeight: "normal",
122 opacity: totalPosts === 0 ? "0.5" : "1",
123 }}
124 >
125 <span
126 style={{
127 fontWeight: "bold",
128 opacity: totalPosts === 0 ? "0.5" : "1",
129 }}
130 >
131 {totalPosts}
132 </span>{" "}
133 мислења
134 </span>
135 ) : (
136 <span
137 style={{
138 fontWeight: "normal",
139 opacity: totalPosts === 0 ? "0.5" : "1",
140 }}
141 >
142 <span
143 style={{
144 fontWeight: "bold",
145 opacity: totalPosts === 0 ? "0.5" : "1",
146 }}
147 >
148 {totalPosts}
149 </span>{" "}
150 мислења
151 </span>
152 )
153 ) : (
154 <span style={{ fontWeight: "normal" }}>
155 <span style={{ fontWeight: "bold" }}>{totalPosts}</span>{" "}
156 мислење
157 </span>
158 )}
159 </EntityParam>
160 </EntityLi>
161 </EntityUl>
162 );
163 })}
164 </div>
165 </>
166 ) : (
167 loadedStudyProgrammes && (
168 <>
169 <CurrentPageNav>
170 <a
171 href={
172 "/university/" + professors[0].faculty.university.universityId
173 }
174 >
175 {professors[0].faculty.university.universityName}
176 </a>{" "}
177 / <a href="#">{professors[0].faculty.facultyName}</a>
178 </CurrentPageNav>
179 <ProfessorCard>
180 <ProfessorCardName>
181 {professors[0].faculty.facultyName}
182 </ProfessorCardName>
183 <ProfessorCardSeparator />
184 <ProfessorCardDetails fontSize="20px">
185 {professors[0].faculty.university.universityName}
186 </ProfessorCardDetails>
187 </ProfessorCard>
188 <div style={{ display: "flex" }}>
189 <EntityTypeSelector
190 boxshadow="2px 2px 5px #aaaaaa"
191 cursor="pointer"
192 boxshadowhover="2px 2px 10px #aaaaaa"
193 opacityhover="1"
194 onClick={() => setEntityType(0)}
195 >
196 Прикажи професори
197 </EntityTypeSelector>
198 <EntityTypeSelector
199 backgroundcolor="rgba(0, 102, 204, 1)"
200 color="white"
201 boxshadow="none"
202 boxshadowhover="none"
203 opacityhover="0.6"
204 cursor="auto"
205 >
206 Прикажи предмети
207 </EntityTypeSelector>
208 </div>
209 <div key={params.facultyId}>
210 {studyProgrammes.map((studyProgramme) => {
211 return (
212 <SubjectsAccordion
213 key={studyProgramme.studyProgrammeId}
214 title={studyProgramme}
215 content={studyProgramme.subjects}
216 ></SubjectsAccordion>
217 );
218 })}
219 </div>
220 </>
221 )
222 )
223 ) : !fetchError ? (
224 <div>
225 <p style={{ marginTop: "140px" }}>се вчитува...</p>
226 <Outlet />
227 </div>
228 ) : (
229 <div style={{ marginTop: "140px" }}>
230 <h1 style={{ textAlign: "center" }}>Страницата не е пронајдена.</h1>
231 </div>
232 );
233};
234
235export default Faculty;
Note: See TracBrowser for help on using the repository browser.