Skip to content

Commit 3e165e5

Browse files
author
john lim
committed
tutorial routes work
1 parent eb3463d commit 3e165e5

File tree

3 files changed

+32
-19
lines changed

3 files changed

+32
-19
lines changed

app/src/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import Cookies from 'js-cookie';
77
import SignIn from './components/login/SignIn.tsx';
88
import SignUp from './components/login/SignUp.tsx';
99
import Tutorial from './tutorial/Tutorial.tsx';
10-
import TutorialPage from './tutorial/TutorialPages.tsx';
10+
import TutorialPage from './tutorial/TutorialPage.tsx';
1111

1212

1313
import {
@@ -17,6 +17,7 @@ import {
1717
Switch,
1818
} from 'react-router-dom';
1919

20+
2021
const PrivateRoute = ({ component: Component, ...rest }) => (
2122
<Route
2223
{...rest}
@@ -38,7 +39,7 @@ ReactDOM.render(
3839
<Route exact path="/signup" component={SignUp} />
3940
<PrivateRoute exact path="/" component={App} />
4041
<Route exact path="/tutorial" component={Tutorial}/>
41-
<Route exact path="/tutorialPage" component={TutorialPage} />
42+
<Route exact path="/tutorialPage/:learn" component={TutorialPage} value={'test'} />
4243
</Switch>
4344
</Router>,
4445
document.getElementById('app')

app/src/tutorial/Tutorial.tsx

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import StyleIcon from '@material-ui/icons/Style';
1919
import ColorLensIcon from '@material-ui/icons/ColorLens';
2020

2121

22-
export const PageContext = createContext({ page: null, setPage: null});
22+
export const PageContext = createContext('');
2323

2424
const useStyles = makeStyles({
2525
root: {
@@ -121,12 +121,12 @@ const Tutorial: React.FC<RouteComponentProps> = () => {
121121
const cards = topics.map((topic, i) => {
122122
return (
123123
<div key={`k${i}`} className={classes.cardWrapper}>
124-
<Link to={'/tutorialPages'} style={{ textDecoration: 'none' }} >
124+
<Link to={`/tutorialPage/${topic}`} style={{ textDecoration: 'none' }} >
125125
<Card className={classes.root} variant="elevation">
126126
<CardContent>
127127
<Typography className={classes.title}>{topic}</Typography>
128128
</CardContent>
129-
<CardActions className={classes.cardActions}>
129+
<CardActions className={classes.cardActions} onClick={() => setPage(topic)}>
130130
{icons[i]}
131131
</CardActions>
132132
</Card>
@@ -136,12 +136,10 @@ const Tutorial: React.FC<RouteComponentProps> = () => {
136136
});
137137

138138
return (
139-
<PageContext.Provider value={{ page, setPage }} >
140-
<Container maxWidth="xl" className={classes.container}>
141-
<h1 className={classes.pageTitle}>ReacType Tutorial</h1>
142-
<div className={classes.wrapper}>{cards}</div>
143-
</Container>
144-
</PageContext.Provider>
139+
<Container maxWidth="xl" className={classes.container}>
140+
<h1 className={classes.pageTitle}>ReacType Tutorial</h1>
141+
<div className={classes.wrapper}>{cards}</div>
142+
</Container>
145143
);
146144
};
147145

app/src/tutorial/TutorialPage.tsx

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import React, { useState, useContext } from 'react';
1+
import React, { useState } from 'react';
2+
import { makeStyles } from '@material-ui/core/styles';
23
import { Link, withRouter, RouteComponentProps } from 'react-router-dom';
34
import Pages from './Pages';
45
import Customization from './Customization';
@@ -10,14 +11,27 @@ import ComponentTree from './ComponentTree';
1011
import HTMLElements from './HtmlElements';
1112
import CodePreview from './CodePreview';
1213

13-
import { PageContext } from './Tutorial';
14+
const useStyles = makeStyles({
15+
tutorial_page: {
16+
display: 'flex',
17+
flexDirection: 'row',
18+
justifyContent: 'center'
19+
},
20+
main_tutorial: {
21+
flexGrow: 2
22+
},
23+
sidebar: {
24+
flexGrow: 1
25+
}
26+
})
1427

15-
const TutorialPage: React.FC<RouteComponentProps> = () => {
16-
const { page, setPage } = useContext(PageContext);
28+
const TutorialPage: React.FC<RouteComponentProps> = (props) => {
29+
const classes = useStyles();
30+
const [page, setPage] = useState(props.match.params.learn);
1731

1832
return (
19-
<div>
20-
<div className="main-tutorial">
33+
<div className={classes.tutorial_page}>
34+
<div className={classes.main_tutorial}>
2135
{page === 'Pages' && <Pages/>}
2236
{page === 'Route Links' && <RouteLinks/>}
2337
{page === 'Code Preview' && <CodePreview/>}
@@ -28,9 +42,9 @@ const TutorialPage: React.FC<RouteComponentProps> = () => {
2842
{page === 'Styling' && <Styling/>}
2943
{page === 'Customization' && <Customization/>}
3044
</div>
31-
<div className="sidebar">
45+
<div className={classes.sidebar}>
3246
<Link to={`/tutorial`}>
33-
<button>Tutorial Main</button>
47+
<button>Tutorial Home</button>
3448
</Link>
3549
<ul>
3650
<li onClick={() => setPage('Pages')}>Pages</li>

0 commit comments

Comments
 (0)