Ignore:
Timestamp:
01/20/23 22:57:18 (20 months ago)
Author:
viktor <viktor@…>
Branches:
main
Children:
8dffe02
Parents:
4abf55a
Message:

prefinal

File:
1 edited

Legend:

Unmodified
Added
Removed
  • reactapp/src/Pages/Faculty.js

    r4abf55a r9bf1f8d  
    2020const Faculty = () => {
    2121  let params = useParams();
     22
     23  const [professors, setProfessors] = useState(null);
     24  const [studyProgrammes, setStudyProgrammes] = useState(null);
     25  const [professorOpinionCount, setProfessorOpinionCount] = useState(null);
    2226  const [loadedProfessors, setLoadedProfessors] = useState(false);
    2327  const [loadedStudyProgrammes, setLoadedStudyProgrammes] = useState(false);
    24   const [professors, setProfessors] = useState(null);
    25   const [studyProgrammes, setStudyProgrammes] = useState(null);
     28  const [loadedProfessorOpinionCount, setLoadedProfessorOpinionCount] = useState(false);
     29
    2630  const [fetchError, setFetchError] = useState(false);
    2731  const [entityType, setEntityType] = useState(0);
    2832
    2933  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 () => {
    3435      try {
    35         const response = await fetch(urlProfessors);
     36        const response = await fetch(`http://192.168.1.254:8080/public/professors?facultyId=${params.facultyId}`);
    3637        let cyclicGraph = await response.json();
    3738        let jsogStructure = JSOG.encode(cyclicGraph);
     
    4445    };
    4546
    46     const fetchDataStudyProgrammes = async () => {
     47    const fetchStudyProgrammes = async () => {
    4748      try {
    48         const response2 = await fetch(urlStudyProgrammes);
     49        const response2 = await fetch(`http://192.168.1.254:8080/public/study_programmes?facultyId=${params.facultyId}`);
    4950        let cyclicGraph2 = await response2.json();
    5051        let jsogStructure2 = JSOG.encode(cyclicGraph2);
     
    5758    };
    5859
    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();
    6176  }, [params.facultyId]);
    6277
    63   return loadedProfessors && professors.length != 0 ? (
     78  return loadedProfessors && professors.length !== 0 ? (
    6479    entityType === 0 ? (
    6580      <>
     
    106121        </div>
    107122        <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;
    111125            return (
    112126              <EntityUl key={professor.professorId}>
     
    215229                  key={studyProgramme.studyProgrammeId}
    216230                  title={studyProgramme}
    217                   content={studyProgramme.subjects}
    218231                ></SubjectsAccordion>
    219232              );
Note: See TracChangeset for help on using the changeset viewer.