Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import {

import Products from './Products'
import Logos from './Logos'
import Categories from './Categories'
import Stores from './Stores'
import Variations from './Variations'
import ProductTypes from './Product-Types'

// This site has 3 pages, all of which are rendered
// dynamically in the browser (not server rendered).
Expand All @@ -32,6 +36,18 @@ export default function BasicExample() {
<li>
<Link to="/logos">Logos</Link>
</li>
<li>
<Link to='/Categories'>Categories</Link>
</li>
<li>
<Link to='/Stores'>Stores</Link>
</li>
<li>
<Link to='/Variations'>Variations</Link>
</li>
<li>
<Link to='/Product-Types'>Product Types</Link>
</li>
</ul>

<hr />
Expand All @@ -53,6 +69,18 @@ export default function BasicExample() {
<Route path="/logos">
<Logos />
</Route>
<Route path="/categories">
<Categories />
</Route>
<Route path="/stores">
<Stores />
</Route>
<Route path='/variations'>
<Variations />
</Route>
<Route path='/product-types'>
<ProductTypes />
</Route>
</Switch>
</div>
</Router>
Expand Down
48 changes: 48 additions & 0 deletions src/Categories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import React from 'react'

class Categories extends React.Component {
constructor () {
super()
this.state = {
response: []
}
}

componentDidMount () {
this.callApi()
.then((response) => {
this.setState({ response })
})
.catch(err => console.log(err))
}

callApi = async () => {
const response = await fetch('http://localhost:3001/Categories')
const body = await response.json();
if (response.status !== 200) throw Error (body.message);

return body
}

render () {
const { response } = this.state

const itemsList = []

for (const [index, item] of response.entries()) {
itemsList.push(<li key={index}> {item.category} </li>)
}

return (
<div>
<h1>{ response.length } items found</h1>
<ul>
{itemsList}
</ul>
</div>
)

}
}

export default Categories
55 changes: 50 additions & 5 deletions src/Logos.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,53 @@
import React from 'react'

class Logos extends React.Component {
constructor () {
super()
this.state = {
response: []
}
}

export default () => {
return (
<div>Logos Place holder</div>
)
}
componentDidMount() {
this.callApi()
.then((response) => {
this.setState({ response })
})
.catch(err => console.log(err))
}

callApi = async () => {
const response = await fetch ('http://localhost:3001/logos')
const body = await response.json();
if (response.status !== 200) throw Error(body.message);

return body;
}

render () {
const { response } = this.state

const itemsList = []

for (const [index, item] of response.entries()) {
itemsList.push(<li key={index}> {item.name} </li>)
}

return (
<div>
<h1>{ response.length } items found</h1>
<ul>
{itemsList}
</ul>
</div>
)
}
}

export default Logos

// export default () => {
// return (
// <div>Logos Place holder</div>
// )
// }
48 changes: 48 additions & 0 deletions src/Product-Types.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import React from 'react'

class ProductTypes extends React.Component {
constructor() {
super ()
this.state= {
response: []
}
}

componentDidMount () {
this.callApi()
.then((response) => {
this.setState({ response })
})
.catch(err => console.log(err))
}

callApi = async () => {
const response = await fetch('http://localhost:3001/Product-Types')
const body = await response.json();
if (response.status !== 200) throw Error (body.message);

return body
}

render () {
const { response } = this.state

const itemsList = []

for (const [index, item] of response.entries()) {
itemsList.push(<li key={index}> {item.name} </li>)
}

return (
<div>
<h1>{ response.length } items found</h1>
<ul>
{itemsList}
</ul>
</div>
)
}

}

export default ProductTypes
20 changes: 16 additions & 4 deletions src/Products.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ class Products extends React.Component {
constructor () {
super()
this.state = {
results: []
response: []
}
}

componentDidMount() {
this.callApi()
.then(res => this.setState({ response: res.express }))
.then((response) => {
this.setState({ response })
})
.catch(err => console.log(err));
}

Expand All @@ -23,10 +25,20 @@ class Products extends React.Component {
};

render () {
const { response } = this.state;

const itemsList = []

for (const [index, item] of response.entries()) {
itemsList.push(<li key={index}> {item.title} </li>)
}

return (
<div>
<div>Products Place holder</div>
<div>{this.state.response}</div>
<h1>{response.length} items found </h1>
<ul>
{itemsList}
</ul>
</div>
)
}
Expand Down
47 changes: 47 additions & 0 deletions src/Stores.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import React from 'react'

class Stores extends React.Component {
constructor () {
super()
this.state = {
response: []
}
}

componentDidMount () {
this.callApi()
.then((response) => {
this.setState({ response })
})
.catch(err => console.log(err))
}

callApi = async () => {
const response = await fetch('http://localhost:3001/Stores')
const body = await response.json();
if (response.status !== 200) throw Error (body.message);

return body
}

render () {
const { response } = this.state

const itemsList = []

for (const [index, item] of response.entries()) {
itemsList.push(<li key={index}> {item.name} </li>)
}

return (
<div>
<h1>{ response.length } items found</h1>
<ul>
{itemsList}
</ul>
</div>
)
}
}

export default Stores
Loading