Skip to content

Commit

Permalink
Step 2
Browse files Browse the repository at this point in the history
  • Loading branch information
CovertIII committed Jun 17, 2020
1 parent cf554a3 commit 340f058
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
39 changes: 36 additions & 3 deletions src/Container.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,45 @@
import React from 'react';
import React, { useState } from 'react';
import Input from './Input.js';
import Results from './Results.js';

function Container() {
const [state, setState] = useState({
data: [],
loading: false,
errorMessage: ''
});

const onChange = e => {
const term = e.target.value;

setState(s => ({
loading: true,
data: [],
errorMessage: ''
}));

fetch('https://fa-search-backend.herokuapp.com/search?delay=true&term=' + term).then(response => {
return response.json();
}).then(data => {
setState(s => ({
loading: false,
data,
errorMessage: ''
}));
}).catch(e => {
setState(s => ({
loading: false,
data: [],
errorMessage: e.message
}));
});
};


return (
<div className="container">
<Input />
<Results />
<Input loading={state.loading} onChange={onChange} />
<Results data={state.data} errorMessage={state.errorMessage} />
</div>
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Results.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function Results({data = [], errorMessage = '', noResults = false}) {
<div className="grid">
{ data.map(({name, uri}) =>
<div key={uri} className="card grid-child">
<img src={uri} className="card-img-top" alt={name} />
<img src={'https://fa-search-backend.herokuapp.com/' + uri} className="card-img-top" alt={name} />
<p className="card-text"><a href={'https://fontawesome.com/icons/' + name}>{name}</a></p>
</div>
)}
Expand Down

0 comments on commit 340f058

Please sign in to comment.