Skip to content

Commit c40eba0

Browse files
authored
Merge pull request #284 from STEM-C/revert-283-revert-282-feature/react_router_update
Revert "Revert "Refactored routes to be more like standard practice react router""
2 parents 5663cbc + 9d0a042 commit c40eba0

File tree

7 files changed

+188
-660
lines changed

7 files changed

+188
-660
lines changed

client/src/App.js

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,37 @@ const App = () => {
2828
return (
2929
<div>
3030
<Switch>
31-
<Route exact path={"/"} render={() => <Home history={history}/>}/>
32-
<Route exact path={"/about"} render={() => <About history={history}/>}/>
33-
<Route exact path={"/teacherlogin"} render={() => <TeacherLogin history={history}/>}/>
34-
<Route exact path={"/login"} render={() => <StudentLogin history={history} />}/>
35-
<PrivateRoute exact path={"/dashboard"} render={() => <Dashboard history={history}/>}/>
36-
<PrivateRoute exact path={"/student"} render={() => <Student history={history} /> } />
37-
<Route path={"/workspace"} render={() => <Workspace history={history} />}/>
38-
<Route path={"/sandbox"} render={() => <Sandbox history={history}/>} />
39-
<PrivateRoute exact path={"/day"} render={() => <Day history={history} /> } />
40-
<PrivateRoute path={"/classroom/:id"} render={() => <Classroom history={history} /> } />
41-
<Route exact path={"/ccdashboard"} render={() => <ContentCreator history={history} />}/>
42-
<Route exact path={"/unitcreator"} render={() => <UnitCreator history={history} />}/>
43-
<Route exact path={"/addblocks"} render={() => <UploadBlocks history={history} />}/>
31+
<Route exact path="/">
32+
<Home />
33+
</Route>
34+
<Route exact path="/about">
35+
<About/>
36+
</Route>
37+
<Route exact path="/teacherlogin">
38+
<TeacherLogin history={history}/>
39+
</Route>
40+
<Route exact path="/login">
41+
<StudentLogin history={history} />
42+
</Route>
43+
<PrivateRoute exact path="/dashboard" render={() => <Dashboard history={history}/>}/>
44+
<PrivateRoute exact path="/student" render={() => <Student history={history} /> } />
45+
<Route path="/workspace">
46+
<Workspace history={history} />
47+
</Route>
48+
<Route path="/sandbox">
49+
<Sandbox history={history}/>
50+
</Route>
51+
<PrivateRoute exact path="/day" render={() => <Day history={history} /> } />
52+
<PrivateRoute path="/classroom/:id" render={() => <Classroom history={history} /> } />
53+
<Route exact path="/ccdashboard">
54+
<ContentCreator history={history} />
55+
</Route>
56+
<Route exact path="/unitcreator">
57+
<UnitCreator history={history} />
58+
</Route>
59+
<Route exact path="/addblocks">
60+
<UploadBlocks history={history} />
61+
</Route>
4462

4563
<Route component={NotFound}/>
4664
</Switch>

client/src/views/Home/Home.js

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,14 @@ import Logo from "../../assets/casmm_logo.png"
44
import HomeJoin from "./HomeJoin"
55
import NavBar from "../../components/NavBar/NavBar";
66

7-
export default function Home(props) {
8-
9-
return(
10-
<div className='container nav-padding'>
11-
<NavBar />
12-
<div id='join-wrapper'>
13-
<img src={Logo} id='casmm-logo' alt='logo'/>
14-
<HomeJoin history={props.history}/>
15-
</div>
7+
const Home = () => (
8+
<div className='container nav-padding'>
9+
<NavBar />
10+
<div id='join-wrapper'>
11+
<img src={Logo} id='casmm-logo' alt='logo'/>
12+
<HomeJoin />
1613
</div>
17-
)
18-
}
14+
</div>
15+
)
16+
17+
export default Home;

client/src/views/Home/HomeJoin.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
import React, {useState} from 'react'
2+
import { useHistory } from 'react-router';
23
import {message} from 'antd'
34
import './Home.less'
45
import { getStudents } from "../../Utils/requests";
56

67
export default function HomeJoin(props) {
78
const [loading, setLoading] = useState(false);
89
const [joinCode, setJoinCode] = useState('');
9-
10+
const history = useHistory();
1011
const handleLogin = () => {
1112
setLoading(true);
1213

1314
getStudents(joinCode).then(res => {
1415
if(res.data){
1516
setLoading(false);
1617
localStorage.setItem('join-code', joinCode);
17-
props.history.push('/login');
18+
history.push('/login');
1819
} else {
1920
setLoading(false);
2021
message.error('Join failed. Please input a valid join code.');

0 commit comments

Comments
 (0)