github.com/quickfeed/quickfeed@v0.0.0-20240507093252-ed8ca812a09c/public/src/pages/CoursePage.tsx (about) 1 import React, { useEffect } from "react" 2 import { Redirect } from "react-router" 3 import { getCourseID, isEnrolled, isTeacher } from "../Helpers" 4 import { useActions, useAppState } from "../overmind" 5 import StudentPage from "./StudentPage" 6 import TeacherPage from "./TeacherPage" 7 8 9 /** The CoursePage component renders a Student or Teacher view 10 * depending on the active course and the user's enrollment status. */ 11 const CoursePage = (): JSX.Element => { 12 const state = useAppState() 13 const actions = useActions() 14 const courseID = getCourseID() 15 const enrollment = state.enrollmentsByCourseID[courseID.toString()] 16 17 useEffect(() => { 18 if (!state.showFavorites) { 19 actions.toggleFavorites() 20 } 21 actions.setActiveCourse(courseID) 22 }, [courseID]) 23 24 if (state.enrollmentsByCourseID[courseID.toString()] && isEnrolled(enrollment)) { 25 if (isTeacher(enrollment)) { 26 return <TeacherPage /> 27 } 28 return <StudentPage /> 29 } else { 30 return <Redirect to={"/"} /> 31 } 32 } 33 34 export default CoursePage