-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathClassroom.js
More file actions
58 lines (53 loc) · 2.13 KB
/
Copy pathClassroom.js
File metadata and controls
58 lines (53 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import React, {useEffect, useState} from "react"
import {Link} from 'react-router-dom';
import {message, Tabs} from 'antd';
import "./Classroom.less"
import NavBar from "../../components/NavBar/NavBar";
import {getClassroom} from "../../Utils/requests";
import Roster from "./Roster/Roster";
import Home from "./Home/Home";
const {TabPane} = Tabs;
export default function Classroom(props) {
const [classroom, setClassroom] = useState({});
const {handleLogout, history, selectedActivity, setSelectedActivity} = props;
const path = history.location.pathname.split('/');
const classroomId = parseInt(path[path.length - 1]);
const hash = history.location.hash.split('#');
const tab = hash[1];
const viewing = parseInt(hash[2]);
useEffect(() => {
getClassroom(classroomId).then(res => {
if(res.data) {
setClassroom(res.data);
} else {
message.error(res.err);
}
});
}, [classroomId]);
console.log(classroom);
return (
<div className="container nav-padding">
<NavBar isMentor={true}/>
<div id='main-header' className='s'>
<div id='classroom'>{classroom.name}</div>
<div id='code'>Join code: {classroom.code}</div>
</div>
<Tabs
defaultActiveKey={tab ? tab : "home"}
onChange={key => history.push(`#${key}`)}
>
<TabPane tab="Home" key="home">
<Home classroomId={classroomId} history={history} selectedActivity={selectedActivity}
setSelectedActivity={setSelectedActivity} viewing={viewing}/>
</TabPane>
<TabPane tab="Roster" key="roster">
<Roster history={history} handleLogout={handleLogout} classroomId={classroomId}/>
</TabPane>
</Tabs>
<h2>Student List</h2>
<ul>
{classroom.students?.map(student => <li key={student.id}><Link to={`/students/${classroom.id}/${student.id}`}>{student.name}</Link></li>)}
</ul>
</div>
);
}