diff --git a/index.js b/index.js deleted file mode 100644 index c104ec8..0000000 --- a/index.js +++ /dev/null @@ -1,4 +0,0 @@ -import React from 'react' -import ReactDOM from 'react-dom' -import { App } from './src' -ReactDOM.render(, document.getElementById('app')) diff --git a/src/app.js b/src/app.js new file mode 100644 index 0000000..835c843 --- /dev/null +++ b/src/app.js @@ -0,0 +1,15 @@ +import React from 'react' +import { Navbar, Main, Footer } from './components' + + +const App = () => { + return ( +
+ +
+
+
+ ) +} + +export default App diff --git a/src/components/index.js b/src/components/index.js index b7d3ea3..6634469 100644 --- a/src/components/index.js +++ b/src/components/index.js @@ -1,53 +1,3 @@ -import React, { Component } from 'react' -import axios from 'axios' -import { Items } from './items' - -class App extends Component { - constructor() { - super() - this.state = { loading: true } - } - - componentDidMount() { - this.fetchAPI() - } - - async fetchAPI() { - try { - const { data } = await axios.get('/api') - const { ascii } = await data - await console.log(ascii) - await this.fetchItems() - await this.setState({ ascii }) - } catch (e) { - console.log(e) - } - } - - async fetchItems() { - try { - const { data } = await axios.get('/api/items') - this.setState({ loading: false, items: data }) - } catch (e) { - console.log(e) - } - } - renderData() { - return ( -
- -
- ) - } - renderError() { - return
{this.state.error}
- } - render() { - if (this.state.loading) return
- if (this.state.items) return this.renderData() - if (this.state.error) return this.renderError() - return
- } -} - -export default App +export {default as Main } from './main' +export {default as Navbar } from './navbar' +export {default as Footer } from './footer' diff --git a/src/components/main.js b/src/components/main.js new file mode 100644 index 0000000..aa1985d --- /dev/null +++ b/src/components/main.js @@ -0,0 +1,43 @@ +import React, { Component } from 'react' +import axios from 'axios' +import { Items } from './items' +import {Container, Row, Col} from 'react-bootstrap' + +class App extends Component { + constructor() { + super() + this.state = { loading: true } + } + + componentDidMount() { + this.fetchApi() + } + + async fetchApi() { + try { + const { data } = await axios.get('/api/items') + this.setState({ loading: false, items: data }) + } catch (e) { + console.log(e) + this.setState({loading: false, apiNotFound: true}) + } + } + + renderData() { + return + } + + renderApiNotFound() { + return + Hello! The client is working correctly, but no API was found. + + } + render() { + if (this.state.loading) return
+ if(this.state.apiNotFound) return this.renderApiNotFound() + if (this.state.items) return this.renderData() + return
+ } +} + +export default App diff --git a/src/index.js b/src/index.js index 1931007..3aa4730 100644 --- a/src/index.js +++ b/src/index.js @@ -1,14 +1,4 @@ import React from 'react' import ReactDOM from 'react-dom' -import Main from './components' -import Navbar from './components/navbar' -import Footer from './components/footer' - -ReactDOM.render( -
- -
-
-
, - document.getElementById('app') -) +import App from './app' +ReactDOM.render(, document.getElementById('app'))