|
|
@@ -10,20 +10,29 @@ import { ClassroomProvider, useClassroomContext } from "./components/Classroom/C
|
|
|
import { ToastContainer } from 'react-toastify';
|
|
|
|
|
|
const RoleSelection = () => {
|
|
|
- const { setRole } = useClassroomContext();
|
|
|
+ const { setRole, login } = useClassroomContext();
|
|
|
+ const { user } = useAuth();
|
|
|
+ const chooseRole = (role: Role) => {
|
|
|
+ if(!user) return;
|
|
|
+
|
|
|
+ setRole(role);
|
|
|
+ login(user.id.toString(), role);
|
|
|
+ }
|
|
|
|
|
|
return (
|
|
|
<div className="flex flex-col items-center justify-center h-full">
|
|
|
<h2 className="text-2xl font-bold mb-8">请选择您的角色</h2>
|
|
|
<div className="flex space-x-4">
|
|
|
<button
|
|
|
- onClick={() => setRole(Role.Teacher)}
|
|
|
+ type="button"
|
|
|
+ onClick={() => chooseRole(Role.Teacher)}
|
|
|
className="px-6 py-3 bg-blue-500 text-white rounded-lg hover:bg-blue-600 transition-colors"
|
|
|
>
|
|
|
我是老师
|
|
|
</button>
|
|
|
<button
|
|
|
- onClick={() => setRole(Role.Student)}
|
|
|
+ type="button"
|
|
|
+ onClick={() => chooseRole(Role.Student)}
|
|
|
className="px-6 py-3 bg-green-500 text-white rounded-lg hover:bg-green-600 transition-colors"
|
|
|
>
|
|
|
我是学生
|
|
|
@@ -115,7 +124,7 @@ const Classroom = () => {
|
|
|
|
|
|
if (isAuthenticated && user && !isLoggedIn && role && classId) {
|
|
|
(async () => {
|
|
|
- await login(user.id.toString());
|
|
|
+ await login(user.id.toString(), role);
|
|
|
await joinClass(classId);
|
|
|
})()
|
|
|
|