Changeset 9bf1f8d for reactapp/src/Pages/Faculty.js
- Timestamp:
- 01/20/23 22:57:18 (20 months ago)
- Branches:
- main
- Children:
- 8dffe02
- Parents:
- 4abf55a
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
reactapp/src/Pages/Faculty.js
r4abf55a r9bf1f8d 20 20 const Faculty = () => { 21 21 let params = useParams(); 22 23 const [professors, setProfessors] = useState(null); 24 const [studyProgrammes, setStudyProgrammes] = useState(null); 25 const [professorOpinionCount, setProfessorOpinionCount] = useState(null); 22 26 const [loadedProfessors, setLoadedProfessors] = useState(false); 23 27 const [loadedStudyProgrammes, setLoadedStudyProgrammes] = useState(false); 24 const [ professors, setProfessors] = useState(null);25 const [studyProgrammes, setStudyProgrammes] = useState(null); 28 const [loadedProfessorOpinionCount, setLoadedProfessorOpinionCount] = useState(false); 29 26 30 const [fetchError, setFetchError] = useState(false); 27 31 const [entityType, setEntityType] = useState(0); 28 32 29 33 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 const fetchProfessors = async () => { 34 35 try { 35 const response = await fetch( urlProfessors);36 const response = await fetch(`http://192.168.1.254:8080/public/professors?facultyId=${params.facultyId}`); 36 37 let cyclicGraph = await response.json(); 37 38 let jsogStructure = JSOG.encode(cyclicGraph); … … 44 45 }; 45 46 46 const fetch DataStudyProgrammes = async () => {47 const fetchStudyProgrammes = async () => { 47 48 try { 48 const response2 = await fetch( urlStudyProgrammes);49 const response2 = await fetch(`http://192.168.1.254:8080/public/study_programmes?facultyId=${params.facultyId}`); 49 50 let cyclicGraph2 = await response2.json(); 50 51 let jsogStructure2 = JSOG.encode(cyclicGraph2); … … 57 58 }; 58 59 59 fetchDataProfessors(); 60 fetchDataStudyProgrammes(); 60 const fetchProfessorOpinionCount = async () => { 61 try { 62 const response3 = await fetch(`http://192.168.1.254:8080/public/faculty/${params.facultyId}/opinionCountForEachProfessor`); 63 let cyclicGraph3 = await response3.json(); 64 let jsogStructure3 = JSOG.encode(cyclicGraph3); 65 cyclicGraph3 = JSOG.decode(jsogStructure3); 66 setProfessorOpinionCount(cyclicGraph3); 67 setLoadedProfessorOpinionCount(true); 68 } catch (error) { 69 setFetchError(true); 70 } 71 } 72 73 fetchProfessors(); 74 fetchStudyProgrammes(); 75 fetchProfessorOpinionCount(); 61 76 }, [params.facultyId]); 62 77 63 return loadedProfessors && professors.length != 0 ? (78 return loadedProfessors && professors.length !== 0 ? ( 64 79 entityType === 0 ? ( 65 80 <> … … 106 121 </div> 107 122 <div key={params.facultyId}> 108 {professors.map((professor) => { 109 let totalPosts = professor.relatedOpinions.length; 110 123 {professors.map((professor, idx) => { 124 let totalPosts = loadedProfessorOpinionCount ? parseInt(professorOpinionCount[idx].split(",")[1]) : 0; 111 125 return ( 112 126 <EntityUl key={professor.professorId}> … … 215 229 key={studyProgramme.studyProgrammeId} 216 230 title={studyProgramme} 217 content={studyProgramme.subjects}218 231 ></SubjectsAccordion> 219 232 );
Note:
See TracChangeset
for help on using the changeset viewer.