refactor navbar to functional component
This commit is contained in:
parent
66639d1aa8
commit
fa35a34355
28
src/App.js
28
src/App.js
|
@ -1,35 +1,33 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { BrowserRouter as Router, Route, Redirect } from "react-router-dom";
|
import { BrowserRouter as Router, Route, Redirect } from "react-router-dom";
|
||||||
import LeaderBoard from './view/LeaderBoard';
|
import LeaderBoard from './view/LeaderBoard';
|
||||||
import { DoudizhuGameView, LeducHoldemGameView } from './view/GameView';
|
import { DoudizhuReplayView, LeducHoldemReplayView } from './view/ReplayView';
|
||||||
import { PVEDoudizhuDemoView } from './view/PVEView';
|
import { PvEDoudizhuDemoView } from './view/PvEView';
|
||||||
import Navbar from "./components/Navbar";
|
import Navbar from "./components/Navbar";
|
||||||
import {makeStyles} from "@material-ui/core/styles";
|
|
||||||
|
|
||||||
const useStyles = makeStyles(() => ({
|
const navbarSubtitleMap = {
|
||||||
navBar: {
|
"/leaderboard": "",
|
||||||
zIndex: 1002
|
"/replay/doudizhu": "Doudizhu",
|
||||||
}
|
"/replay/leduc-holdem": "Leduc Hold'em",
|
||||||
}));
|
"/pve/doudizhu-demo": "Doudizhu PvE Demo"
|
||||||
|
};
|
||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
const classes = useStyles();
|
|
||||||
|
|
||||||
// todo: add 404 page
|
// todo: add 404 page
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Router>
|
<Router>
|
||||||
<Navbar className={classes.navBar} gameName={""}/>
|
<Navbar subtitleMap={navbarSubtitleMap}/>
|
||||||
<div style={{marginTop: '75px'}}>
|
<div style={{marginTop: '75px'}}>
|
||||||
<Route exact path="/">
|
<Route exact path="/">
|
||||||
{/* for test use */}
|
{/* for test use */}
|
||||||
{/* <Redirect to="/leaderboard?type=game&name=leduc-holdem" /> */}
|
{/* <Redirect to="/leaderboard?type=game&name=leduc-holdem" /> */}
|
||||||
<Redirect to="/pve-doudizhu-demo" />
|
<Redirect to="/pve/doudizhu-demo" />
|
||||||
</Route>
|
</Route>
|
||||||
<Route path="/leaderboard" component={LeaderBoard} />
|
<Route path="/leaderboard" component={LeaderBoard} />
|
||||||
<Route path="/replay/doudizhu" component={DoudizhuGameView} />
|
<Route path="/replay/doudizhu" component={DoudizhuReplayView} />
|
||||||
<Route path="/replay/leduc-holdem" component={LeducHoldemGameView} />
|
<Route path="/replay/leduc-holdem" component={LeducHoldemReplayView} />
|
||||||
<Route path="/pve-doudizhu-demo" component={PVEDoudizhuDemoView} />
|
<Route path="/pve/doudizhu-demo" component={PvEDoudizhuDemoView} />
|
||||||
</div>
|
</div>
|
||||||
</Router>
|
</Router>
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,39 +1,37 @@
|
||||||
import React from "react";
|
import React, { useEffect, useState } from "react";
|
||||||
import { Link } from 'react-router-dom';
|
import { Link, useLocation } from 'react-router-dom';
|
||||||
import logo_white from "../assets/images/logo_white.png";
|
import logo_white from "../assets/images/logo_white.png";
|
||||||
import GitHubIcon from "@material-ui/icons/GitHub";
|
import GitHubIcon from "@material-ui/icons/GitHub";
|
||||||
import AppBar from "@material-ui/core/AppBar";
|
import AppBar from "@material-ui/core/AppBar";
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
|
|
||||||
class Navbar extends React.Component {
|
function Navbar({subtitleMap}) {
|
||||||
constructor(props) {
|
const [stars, setStars] = useState('...');
|
||||||
super(props);
|
let location = useLocation();
|
||||||
|
console.log(location.pathname, subtitleMap);
|
||||||
|
const subtitle = subtitleMap[location.pathname];
|
||||||
|
|
||||||
this.state = {stars: '...'};
|
useEffect(() => {
|
||||||
}
|
|
||||||
|
|
||||||
componentDidMount() {
|
|
||||||
axios.get("https://api.github.com/repos/datamllab/rlcard")
|
axios.get("https://api.github.com/repos/datamllab/rlcard")
|
||||||
.then(res=>{
|
.then(res=>{
|
||||||
this.setState({stars: res.data.stargazers_count});
|
setStars(res.data.stargazers_count);
|
||||||
});
|
});
|
||||||
}
|
}, [])
|
||||||
|
|
||||||
render() {
|
return (
|
||||||
return (
|
<AppBar position="fixed" className={"header-bar-wrapper"}>
|
||||||
<AppBar position="fixed" className={"header-bar-wrapper"}>
|
<div className={"header-bar"}>
|
||||||
<div className={"header-bar"}>
|
<Link to="/leaderboard"><img src={logo_white} alt={"Logo"} height="65px" /></Link>
|
||||||
<Link to="/leaderboard"><img src={logo_white} alt={"Logo"} height="65px" /></Link>
|
<div className={"title unselectable"}><div className={"title-text"}>Showdown<span className={"subtitle"}>{subtitle ? '/ ' + subtitle : ''}</span></div></div>
|
||||||
<div className={"title unselectable"}><div className={"title-text"}>Showdown<span className={"subtitle"}>{this.props.gameName === '' ? '' : '/ ' + this.props.gameName}</span></div></div>
|
<div className={"stretch"} />
|
||||||
<div className={"stretch"} />
|
<div className={"github-info"} onClick={()=>{window.location.href = 'https://github.com/datamllab/rlcard'}}>
|
||||||
<div className={"github-info"} onClick={()=>{window.location.href = 'https://github.com/datamllab/rlcard'}}>
|
<div className={"github-icon"}><GitHubIcon /></div>
|
||||||
<div className={"github-icon"}><GitHubIcon /></div>
|
<div className={"github-text"}>Github<br /><span>{stars} stars</span></div>
|
||||||
<div className={"github-text"}>Github<br /><span>{this.state.stars} stars</span></div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</AppBar>
|
</div>
|
||||||
|
</AppBar>
|
||||||
)
|
)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Navbar;
|
export default Navbar;
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import ReactDOM from 'react-dom';
|
import ReactDOM from 'react-dom';
|
||||||
|
|
||||||
import './assets/index.scss';
|
import './assets/index.scss';
|
||||||
import App from './App';
|
import App from './App';
|
||||||
|
|
||||||
|
|
|
@ -1,15 +1,20 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
import Navbar from "../../components/Navbar";
|
||||||
|
import { DoudizhuGameBoard } from '../../components/GameBoard';
|
||||||
|
|
||||||
class PVEDoudizhuDemoView extends React.Component {
|
|
||||||
|
class PvEDoudizhuDemoView extends React.Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<div>Under Development...</div>
|
<div>
|
||||||
|
<div>Under Development...</div>
|
||||||
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default PVEDoudizhuDemoView;
|
export default PvEDoudizhuDemoView;
|
|
@ -1,3 +1,3 @@
|
||||||
import PVEDoudizhuDemoView from './PVEDoudizhuDemoView';
|
import PvEDoudizhuDemoView from './PvEDoudizhuDemoView';
|
||||||
|
|
||||||
export {PVEDoudizhuDemoView};
|
export {PvEDoudizhuDemoView};
|
Loading…
Reference in New Issue