-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a2f57b6
commit 5870147
Showing
26 changed files
with
243 additions
and
200 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,20 @@ | ||
"use client"; | ||
import InstructorDashboard from "@/components/InstructorDashboard"; | ||
import StudentDashboard from "@/components/StudentDashboard"; | ||
import { IUser_Raw } from "@/lib/models/user"; | ||
import { globalStateAtom } from "@/state/globalState"; | ||
import axios from "axios"; | ||
import { useAtom } from "jotai"; | ||
import { useEffect } from "react"; | ||
import { Suspense } from "react"; | ||
import Loading from "./loading"; | ||
import { useGlobalContext } from "@/state/globalContext"; | ||
|
||
export default function Dashboard() { | ||
const [globalState, setGlobalState] = useAtom(globalStateAtom); | ||
const [globalState] = useGlobalContext(); | ||
|
||
useEffect(() => { | ||
async function fetchData() { | ||
const res = await axios.get("/api/auth/session"); | ||
if (!res.data?.user) return; | ||
updateStateFromSession(res.data.user); | ||
} | ||
fetchData(); | ||
}, []); | ||
|
||
function updateStateFromSession(userData: IUser_Raw) { | ||
setGlobalState((prev) => ({ | ||
...prev, | ||
role: userData?.role, | ||
viewAs: userData?.role, | ||
courseID: userData?.courses[0] || "", | ||
})); | ||
} | ||
|
||
if (globalState.viewAs === "instructor") { | ||
return <InstructorDashboard course_id={globalState.courseID} />; | ||
} | ||
return <StudentDashboard course_id={globalState.courseID} />; | ||
return ( | ||
<Suspense fallback={<Loading />}> | ||
{globalState.viewAs === "instructor" ? ( | ||
<InstructorDashboard course_id={globalState.courseID} /> | ||
) : ( | ||
<StudentDashboard course_id={globalState?.courseID ?? ""} /> | ||
)} | ||
</Suspense> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.