Created
February 21, 2018 03:41
-
-
Save reciosonny/a35a2b255386bbee9819d0fca2555db7 to your computer and use it in GitHub Desktop.
Sample component reuse React
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from 'react'; | |
import logo from './logo.svg'; | |
import './App.css'; | |
import { Route, Switch, Link, Router, NavLink } from "react-router-dom"; | |
import SchemaTablesList from './SchemaTablesList'; | |
import Settings from './Settings'; | |
import { ToastContainer } from "react-toastr"; | |
import { connect } from "react-redux"; | |
import { bindActionCreators } from "redux"; | |
import DbSchema from './DbSchema'; | |
import { Button, Modal, ModalHeader, ModalBody, ModalFooter } from 'reactstrap'; //for more documentations, see reactstrap: https://reactstrap.github.io/ | |
import Dashboard from './Dashboard'; | |
import { withRouter } from "react-router-dom"; | |
import Mousetrap from "mousetrap"; | |
import ModalQuickAddTable from './Schema/ModalQuickAddTable'; | |
/* ACTIONS */ | |
import { initializeSchema, toggleModalAddSchema } from "../Actions/actionsSchema"; | |
import { initializeTableTags } from "../Actions/actionsTableTags"; | |
import { toggleModalTableAdd } from "../Actions/actionsModalTable"; | |
import SidebarTableSchemas from './Sidebar/SidebarTableSchemas'; | |
import SidebarTableTags from "./Sidebar/SidebarTableTags"; | |
import MenuTags from "./Menu/MenuTags"; | |
class App extends Component { | |
container; | |
constructor(props) { | |
super(props); | |
this.state = { container: null, showModal: false, schemaTableModal: false }; | |
this.toggleSchemaTableModalAdd = this.toggleSchemaTableModalAdd.bind(this); | |
} | |
toggleSchemaTableModalAdd() { | |
this.props.toggleModalTableAdd(); | |
} | |
componentWillMount() { | |
this.props.initializeSchema(); | |
this.props.initializeTableTags(); | |
} | |
componentDidMount() { | |
Mousetrap.bind(['q'], this.toggleSchemaTableModalAdd); | |
} | |
componentWillUnmount() { | |
Mousetrap.bind(['q'], this.toggleSchemaTableModalAdd); | |
} | |
onAddNewSchemaTable(e) { | |
e.preventDefault(); | |
} | |
render() { | |
return ( | |
<div> | |
<ModalQuickAddTable /> | |
<header> | |
<nav className="navbar navbar-expand-md navbar-dark fixed-top bg-dark"> | |
<a className="navbar-brand" href="#">Note My DB</a> | |
<button className="navbar-toggler d-lg-none" type="button" data-toggle="collapse" data-target="#navbarsExampleDefault" aria-controls="navbarsExampleDefault" aria-expanded="false" aria-label="Toggle navigation"> | |
<span className="navbar-toggler-icon"></span> | |
</button> | |
<div className="collapse navbar-collapse" id="navbarsExampleDefault"> | |
<ul className="navbar-nav mr-auto"> | |
<li className="nav-item active"> | |
<a className="nav-link" href="#">Home <span className="sr-only">(current)</span></a> | |
</li> | |
<li className="nav-item"> | |
<a className="nav-link" href="#">Settings</a> | |
</li> | |
<li className="nav-item"> | |
<a className="nav-link" href="#">Profile</a> | |
</li> | |
<li className="nav-item"> | |
<a className="nav-link" href="#">Help</a> | |
</li> | |
</ul> | |
</div> | |
</nav> | |
</header> | |
<div className="container-fluid"> | |
<div className="row"> | |
<nav className="col-sm-3 col-md-2 d-none d-sm-block bg-light sidebar"> | |
<ul className="nav nav-pills flex-column"> | |
<li className="nav-item"> | |
<NavLink exact to="/" className="nav-link"> | |
<i className="fas fa-home"></i> Dashboard | |
</NavLink> | |
</li> | |
<li className="nav-item"> | |
<a className="nav-link" href="#">Configuration</a> | |
</li> | |
<li className="nav-item"> | |
<a className="nav-link" href="#">Options</a> | |
</li> | |
</ul> | |
<SidebarTableSchemas /> | |
<SidebarTableTags /> | |
</nav> | |
<main role="main" className="col-sm-9 ml-sm-auto col-md-10 pt-3"> | |
<div> | |
<Switch> | |
<Route exact path="/" component={ Dashboard } /> | |
<Route path="/settings" component={ Settings } /> | |
<Route path="/schemas/:id" component={ SchemaTablesList } /> | |
<Route path="/tags/:id" component={ MenuTags } /> | |
</Switch> | |
</div> | |
</main> | |
</div> | |
</div> | |
</div> | |
); | |
} | |
} | |
function mapDispatchToProps(dispatch) { | |
return bindActionCreators({ initializeSchema, toggleModalAddSchema, toggleModalTableAdd, initializeTableTags }, dispatch); | |
} | |
function mapStateToProps(state) { | |
return { schemas: state.schemas }; | |
} | |
// export default connect(mapStateToProps, mapDispatchToProps)(App); | |
// export default App; | |
export default withRouter( | |
connect(mapStateToProps, mapDispatchToProps)(App) | |
); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment