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