diff --git a/src/App.js b/src/App.js index c3edbe1..c3652f7 100644 --- a/src/App.js +++ b/src/App.js @@ -1,7 +1,7 @@ import React from 'react' -import { Tasks } from './components' +import { About, Tasks, Navbar } from './components' -const defaultState = { loading: true } +const defaultState = { loading: true, search: '' } // hard-coded for now, but can be passed anything and set on state const data = { user: { name: 'Scott', role: 'manager' }, component: 'tasks' } @@ -10,6 +10,9 @@ class App extends React.Component { constructor() { super() this.state = defaultState + this.navigate = this.navigate.bind(this) + this.handleChange = this.handleChange.bind(this) + this.handleSubmit = this.handleSubmit.bind(this) } fetchData() { @@ -23,22 +26,43 @@ class App extends React.Component { this.setState({ loading: false, ...data }) } + navigate(component) { + this.setState( {component} ) + } + + handleChange(e) { + this.setState( { [e.target.name]: e.target.value }) + console.log( this.state ) + } + handleSubmit(e) { + e.preventDefault() + console.log("Search term: ", this.state.search) + this.setState({ search: ''}) + } renderLoading() { return
Loading...
} - renderError() { return
Something went wrong. Please try again.
} + renderAbout() { + return + } renderTasks() { // {...this.state} passes everything on state to the component return } render() { - if (this.state.loading) return this.renderLoading() - if (this.state.error) return this.renderError() - if (this.state.component === 'tasks') return this.renderTasks() - return
+ + const renderComponent = () => this.state.loading ? this.renderLoading() + : this.state.component === 'tasks' ? this.renderTasks() + : this.state.component === 'about' ? this.renderAbout() + : this.renderError() + + return (
+ + { renderComponent() } +
) } } diff --git a/src/components/about.js b/src/components/about.js new file mode 100644 index 0000000..f88cbaf --- /dev/null +++ b/src/components/about.js @@ -0,0 +1,7 @@ +import React from 'react' + +function About(props) { + // props are passed from App as {...this.state} + return "we'r here" +} +export default About diff --git a/src/components/index.js b/src/components/index.js index 650dacc..2650dcc 100644 --- a/src/components/index.js +++ b/src/components/index.js @@ -1,6 +1,8 @@ // this is just for exporting each component from this folder, // so they can all be imported neatly into App using object destructuring +export { default as Navbar } from './navbar' +export { default as About } from './about' export { default as Tasks } from './tasks' // export {default as CreateASign} from ./create-a-sign.js // etc diff --git a/src/components/navbar.js b/src/components/navbar.js new file mode 100644 index 0000000..92d0ba9 --- /dev/null +++ b/src/components/navbar.js @@ -0,0 +1,34 @@ +import React from 'react' + +function Navbar(props) { + // props are passed from App as {...this.state} +return ( + +) +} + +export default Navbar