poa-dapps-voting/src/App.js

78 lines
2.4 KiB
JavaScript
Raw Normal View History

2017-12-11 14:23:01 -08:00
import React, { Component } from 'react';
2017-12-25 06:23:09 -08:00
import { Route, NavLink } from 'react-router-dom';
2017-12-11 14:23:01 -08:00
import { Header, Ballots, NewBallot, Settings, Footer } from './components';
import './assets/App.css';
2017-12-25 09:01:09 -08:00
//import DevTools from 'mobx-react-devtools'
import Loading from './Loading';
import { inject, observer } from 'mobx-react';
2017-12-11 14:23:01 -08:00
@inject("commonStore")
@observer
2017-12-11 14:23:01 -08:00
class App extends Component {
onBallotsRender = () => {
2017-12-25 06:23:09 -08:00
const { commonStore } = this.props;
2017-12-26 04:12:37 -08:00
commonStore.isActiveFilter = false;
2017-12-25 06:23:09 -08:00
return <Ballots/>;
}
onActiveBallotsRender = () => {
const { commonStore } = this.props;
2017-12-26 04:12:37 -08:00
commonStore.isActiveFilter = true;
return <Ballots/>;
}
onNewBallotRender = () => {
return <NewBallot/>;
}
onSettingsRender = () => {
return <Settings/>;
}
2017-12-25 07:47:33 -08:00
onSearch = (e) => {
const { commonStore } = this.props;
commonStore.setSearchTerm(e.target.value.toLowerCase());
}
2017-12-25 08:03:02 -08:00
shouldShowNavPan = () => {
const { commonStore } = this.props;
const currentPath = this.props.location.pathname;
let showNavPan =
2018-01-05 12:36:25 -08:00
currentPath === `${commonStore.rootPath}`
|| currentPath === "/"
|| currentPath === `${commonStore.rootPath}/`
|| currentPath === `${commonStore.rootPath}/active`;
2017-12-25 08:03:02 -08:00
return showNavPan;
}
2017-12-11 14:23:01 -08:00
render() {
const { commonStore } = this.props;
const loading = commonStore.loading ? <Loading /> : ''
2017-12-25 08:03:02 -08:00
const nav = this.shouldShowNavPan() ? <div className="search">
2017-12-25 07:47:33 -08:00
<div className="container flex-container">
<div className="nav">
<NavLink className="nav-i" exact activeClassName="nav-i_active" to={`${commonStore.rootPath}/`}>All</NavLink>
<NavLink className="nav-i" activeClassName="nav-i_active" to={`${commonStore.rootPath}/active`}>Active</NavLink>
</div>
<input type="search" className="search-input" onChange={this.onSearch}/>
</div>
</div> : null;
2017-12-11 14:23:01 -08:00
return (
<div>
{loading}
2017-12-11 14:23:01 -08:00
<Header />
2017-12-25 07:47:33 -08:00
{nav}
2018-01-05 12:36:25 -08:00
<Route exact path={`/`} render={this.onBallotsRender}/>
2017-12-21 10:55:19 -08:00
<Route exact path={`${commonStore.rootPath}/`} render={this.onBallotsRender}/>
2017-12-25 06:23:09 -08:00
<Route exact path={`${commonStore.rootPath}/active`} render={this.onActiveBallotsRender}/>
2017-12-21 10:55:19 -08:00
<Route path={`${commonStore.rootPath}/new`} render={this.onNewBallotRender}/>
{/*<Route path={`${commonStore.rootPath}/settings`} render={this.onSettingsRender}/>*/}
2017-12-11 14:23:01 -08:00
<Footer />
2017-12-25 09:01:09 -08:00
{/*<DevTools />*/}
2017-12-11 14:23:01 -08:00
</div>
);
}
}
export default App;