diff --git a/app/(authorized)/layout.tsx b/app/(authorized)/layout.tsx index dd2be7e..a6939f2 100644 --- a/app/(authorized)/layout.tsx +++ b/app/(authorized)/layout.tsx @@ -7,6 +7,7 @@ import NavMenu from "@/components/NavMenu"; import DemoModeControls from "@/components/DemoModeControls"; import { validateRequest } from "@/lib/auth"; import { redirect } from "next/navigation"; +import SessionToContextProvider from "@/components/SessionToContextProvider"; const inter = Inter({ subsets: ["latin"] }); @@ -29,7 +30,7 @@ export default async function RootLayout({ className={classNames(inter.className, "container mt-4 default-layout")} > - <> + {process.env.NODE_ENV === "development" && (
@@ -41,7 +42,7 @@ export default async function RootLayout({
{children}
- +
diff --git a/app/(authorized)/loading.tsx b/app/(authorized)/loading.tsx index dd12c41..50a2530 100644 --- a/app/(authorized)/loading.tsx +++ b/app/(authorized)/loading.tsx @@ -1,6 +1,6 @@ import Image from "next/image"; -const PageLoadingIndicator = () => { +export default function Loading() { return (
{
); -}; - -export default PageLoadingIndicator; +} diff --git a/app/(authorized)/page.tsx b/app/(authorized)/page.tsx index 7da90c2..ebc7d31 100644 --- a/app/(authorized)/page.tsx +++ b/app/(authorized)/page.tsx @@ -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 ; - } - return ; + return ( + }> + {globalState.viewAs === "instructor" ? ( + + ) : ( + + )} + + ); } diff --git a/app/(authorized)/providers.tsx b/app/(authorized)/providers.tsx index ed68d28..cb1e482 100644 --- a/app/(authorized)/providers.tsx +++ b/app/(authorized)/providers.tsx @@ -3,7 +3,7 @@ import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; import { ReactQueryDevtools } from "@tanstack/react-query-devtools"; import { useState } from "react"; import { ReactQueryStreamedHydration } from "@tanstack/react-query-next-experimental"; -import { Provider as JotaiProvider } from "jotai"; +import { GlobalContextProvider } from "@/state/globalContext"; export function Providers(props: { children: React.ReactNode }) { const [queryClient] = useState( @@ -20,13 +20,13 @@ export function Providers(props: { children: React.ReactNode }) { ); return ( - - - - {props.children} - - - - + + + + {props.children} + + + + ); } diff --git a/app/(authorized)/raw-data/page.tsx b/app/(authorized)/raw-data/page.tsx index e1fa37e..ad21bb1 100644 --- a/app/(authorized)/raw-data/page.tsx +++ b/app/(authorized)/raw-data/page.tsx @@ -1,6 +1,7 @@ import PageHeader from "@/components/PageHeader"; import GenericPageContainer from "@/components/GenericPageContainer"; import RawDataTable from "@/components/RawDataTable"; +import { getCourseRawData } from "@/lib/analytics-functions"; export default function RawDataView() { return ( @@ -9,7 +10,7 @@ export default function RawDataView() { title="Raw Data View" subtitle="Browse all available analytics/performance data for your course." /> - + ); } diff --git a/components/CourseSettings/StudentPermissions.tsx b/components/CourseSettings/StudentPermissions.tsx index cf721fe..bbc0789 100644 --- a/components/CourseSettings/StudentPermissions.tsx +++ b/components/CourseSettings/StudentPermissions.tsx @@ -1,10 +1,10 @@ "use client"; -import { GlobalState, globalStateAtom } from "@/state/globalState"; -import { useAtom } from "jotai"; +import { GlobalState } from "@/lib/types"; import React, { useState } from "react"; import { Button, Form, ListGroup, Toast } from "react-bootstrap"; import ToastContainer from "../ToastContainer"; import { Controller, useForm } from "react-hook-form"; +import { useGlobalContext } from "@/state/globalContext"; interface StudentPermissionsProps { saveData: ( @@ -16,7 +16,7 @@ interface StudentPermissionsProps { const StudentPermissions: React.FC = ({ saveData, }) => { - const [globalState, setGlobalState] = useAtom(globalStateAtom); + const [globalState, setGlobalState] = useGlobalContext(); const [saveError, setSaveError] = useState(null); const [showSuccess, setShowSuccess] = useState(false); const [loading, setLoading] = useState(false); diff --git a/components/DemoModeControls.tsx b/components/DemoModeControls.tsx index c16b0ce..0ae205b 100644 --- a/components/DemoModeControls.tsx +++ b/components/DemoModeControls.tsx @@ -1,18 +1,15 @@ -'use client' -import { globalStateAtom } from "@/state/globalState"; +"use client"; +import { useGlobalContext } from "@/state/globalContext"; import { capitalizeFirstLetter } from "@/utils/text-helpers"; -import { useAtom } from "jotai"; -import { useState } from "react"; const DemoModeControls = () => { - const [globalState, setGlobalState] = useAtom(globalStateAtom); - // const [courseId, setCourseId] = useState(globalState.adaptId); + const [globalState, setGlobalState] = useGlobalContext(); return (

- Viewing as: + (Demo Mode) Viewing as: {capitalizeFirstLetter(globalState.viewAs)}