Skip to content

Commit

Permalink
adding solution
Browse files Browse the repository at this point in the history
  • Loading branch information
OrkunSA committed Dec 28, 2020
1 parent 0e3b164 commit 4f772a9
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import React from 'react'
import React from "react";

import NavBar from './NavBar'
import NavBar from "./NavBar";
import GifListContainer from "../containers/GifListContainer";

// the App component should render out the GifListContainer component
// the App component should render out the GifListContainer component

const App = () => {
return (
<div>
< NavBar color='black' title="Giphy Search" />
<NavBar color="black" title="Giphy Search" />
<GifListContainer />
</div>
)
}
);
};

export default App
export default App;
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React from "react";

const GifList = (props) => {
console.log(props);
return (
<div>
{props.gifs.map((gif) => (
<img key={gif.url} src={gif.url} alt="gif" />
))}
</div>
);
};

export default GifList;
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import React from "react";

class GifSearch extends React.Component {
state = {
query: "",
};

handleSubmit = (event) => {
event.preventDefault();
this.props.fetchGifs(this.state.query);
};

render() {
return (
<div>
<form onSubmit={this.handleSubmit}>
<input
type="text"
value={this.state.query}
onChange={(event) => this.setState({ query: event.target.value })}
/>
</form>
</div>
);
}
}

export default GifSearch;
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import React, { Component } from "react";
import GifList from "../components/GifList";
import GifSearch from "../components/GifSearch";

class GifListContainer extends Component {
state = {
gifs: [],
};

render() {
return (
<div>
<GifSearch fetchGIFs={this.fetchGIFs} />
<GifList gifs={this.state.gifs} />
</div>
);
}

fetchGIFs = (query = "dolphins") => {
fetch(
`https://api.giphy.com/v1/gifs/search?q=${query}&api_key=j5gbJI17mAkckytGHgiwdmoSctTLQglh&rating=g&limit=3`
)
.then((res) => res.json())
.then(({ data }) => {
this.setState({
gifs: data.map((gif) => ({ url: gif.images.original.url })),
});
});
};

componentDidMount() {
this.fetchGIFs();
}
}

export default GifListContainer;

0 comments on commit 4f772a9

Please sign in to comment.