|
|
@@ -2,8 +2,8 @@ import React, { useState, useEffect } from 'react';
|
|
|
import { useAuth } from './hooks.tsx';
|
|
|
import { useNavigate } from 'react-router';
|
|
|
import { Role, ClassStatus } from './components/Classroom/useClassroom.ts';
|
|
|
-import { TeacherView } from './components/Classroom/TeacherView.tsx';
|
|
|
-import { StudentView } from './components/Classroom/StudentView.tsx';
|
|
|
+// import { TeacherView } from './components/Classroom/TeacherView.tsx';
|
|
|
+// import { StudentView } from './components/Classroom/StudentView.tsx';
|
|
|
import { ClassroomLayout } from './components/Classroom/ClassroomLayout.tsx';
|
|
|
import { AuthLayout } from './components/Classroom/AuthLayout.tsx';
|
|
|
import { ClassroomProvider, useClassroomContext } from "./components/Classroom/ClassroomProvider.tsx";
|
|
|
@@ -11,12 +11,10 @@ import { ToastContainer } from 'react-toastify';
|
|
|
|
|
|
const RoleSelection = () => {
|
|
|
const { setRole, login } = useClassroomContext();
|
|
|
- const { user } = useAuth();
|
|
|
const chooseRole = (role: Role) => {
|
|
|
- if(!user) return;
|
|
|
|
|
|
setRole(role);
|
|
|
- login(user.id.toString(), role);
|
|
|
+ login(role);
|
|
|
}
|
|
|
|
|
|
return (
|
|
|
@@ -63,6 +61,7 @@ const JoinClassSection = () => {
|
|
|
className="flex-1 px-3 py-2 border rounded"
|
|
|
/>
|
|
|
<button
|
|
|
+ type="button"
|
|
|
onClick={handleJoinClass}
|
|
|
className="px-4 py-2 bg-blue-500 text-white rounded"
|
|
|
>
|
|
|
@@ -99,6 +98,7 @@ const CreateClassSection = () => {
|
|
|
className="flex-1 px-3 py-2 border rounded"
|
|
|
/>
|
|
|
<button
|
|
|
+ type="button"
|
|
|
onClick={handleCreateClass}
|
|
|
className="px-4 py-2 bg-green-500 text-white rounded"
|
|
|
>
|
|
|
@@ -113,23 +113,17 @@ const CreateClassSection = () => {
|
|
|
const Classroom = () => {
|
|
|
const context = useClassroomContext();
|
|
|
const { role, classStatus, isLoggedIn, login, classId, joinClass } = context;
|
|
|
- const { user, isAuthenticated } = useAuth();
|
|
|
-
|
|
|
- useEffect(() => {
|
|
|
- if(user)
|
|
|
- context.setUserId(user?.id.toString())
|
|
|
- },[ user ])
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
|
- if (isAuthenticated && user && !isLoggedIn && role && classId) {
|
|
|
+ if (!isLoggedIn && role && classId) {
|
|
|
(async () => {
|
|
|
- await login(user.id.toString(), role);
|
|
|
+ await login(role);
|
|
|
await joinClass(classId);
|
|
|
})()
|
|
|
|
|
|
}
|
|
|
- }, [isAuthenticated, user, isLoggedIn, role , classId]);
|
|
|
+ }, [isLoggedIn, role , classId]);
|
|
|
|
|
|
if (!role) {
|
|
|
return (
|
|
|
@@ -180,15 +174,17 @@ const Classroom = () => {
|
|
|
|
|
|
return (
|
|
|
<ClassroomLayout role={role}>
|
|
|
- {role === Role.Teacher ? <TeacherView /> : <StudentView />}
|
|
|
+ {/* {role === Role.Teacher ? <TeacherView /> : <StudentView />} */}
|
|
|
+ <></>
|
|
|
</ClassroomLayout>
|
|
|
);
|
|
|
};
|
|
|
|
|
|
export const ClassroomPage = () => {
|
|
|
+ const { user } = useAuth();
|
|
|
return (
|
|
|
<>
|
|
|
- <ClassroomProvider>
|
|
|
+ <ClassroomProvider user={user!}>
|
|
|
<Classroom />
|
|
|
</ClassroomProvider>
|
|
|
<ToastContainer
|