forked from Ada-C11/video-store-consumer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from kaseea/search
Search
- Loading branch information
Showing
6 changed files
with
189 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
|
||
# misc | ||
.DS_Store | ||
.env | ||
.env.local | ||
.env.development.local | ||
.env.test.local | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,5 +26,8 @@ | |
"last 1 firefox version", | ||
"last 1 safari version" | ||
] | ||
}, | ||
"devDependencies": { | ||
"dotenv": "^8.0.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,120 @@ | ||
import React, { Component } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
import './Search.css'; | ||
import axios from 'axios'; | ||
|
||
require('dotenv').config(); | ||
|
||
class Search extends Component { | ||
constructor(props) { | ||
super(props); | ||
|
||
this.state = { | ||
result: [], | ||
titleSearch: '', | ||
errorMessage: '', | ||
}; | ||
} | ||
|
||
onChangeHandler = (event) => { | ||
const field = {} | ||
field[event.target.name] = event.target.value; | ||
|
||
this.setState(field); | ||
} | ||
|
||
searchMovie = (event) => { | ||
event.preventDefault(); | ||
|
||
this.searchMovieResults(this.state.titleSearch); | ||
|
||
render() { | ||
return ( | ||
<div> | ||
{ console.log(this.props.customer) } | ||
<h2>THIS IS A SEARCH</h2> | ||
</div> | ||
) | ||
} | ||
} | ||
this.setState({ | ||
titleSearch: '', | ||
}); | ||
} | ||
|
||
componentDidMount () { | ||
this.searchMovieResults(); | ||
} | ||
|
||
Search.propTypes = { | ||
searchMovieResults = (titleSearch) => { | ||
const externalUrl = `https://api.themoviedb.org/3/search/movie?api_key=${process.env.REACT_APP_API_KEY}&language=en-US&query=${titleSearch}&page=1&include_adult=false`; | ||
console.log(externalUrl); | ||
axios.get(externalUrl) | ||
.then((response) => { | ||
const movies = response.data.map((movie) => { | ||
return { | ||
id: movie.id, | ||
title: movie.title, | ||
overview: movie.overview, | ||
release_date: movie.release_date, | ||
image_url: movie.image_url, | ||
external_id: movie.external_id, | ||
} | ||
}) | ||
this.setState({ | ||
result: movies, | ||
}); | ||
}) | ||
.catch((error) => { | ||
this.setState({ | ||
errorMessage: `${error.message} when retrieving movies.`, | ||
}); | ||
}); | ||
} | ||
|
||
}; | ||
// addMovie = (movieId) => { | ||
// console.log(this.state); | ||
// const addedMovie = this.state.searchResults.find(movie => movie.external_id === movieId) | ||
// const addedMovieInfo = { | ||
// title: addedMovie.title, | ||
// overview: addedMovie.overview, | ||
// release_date: addedMovie.release_date, | ||
// image_url: addedMovie.image_url, | ||
// external_id: addedMovie.external_id, | ||
// inventory: 5 | ||
// } | ||
|
||
// axios.post('http://localhost:3000/movies/', addedMovieInfo) | ||
// .then((response) => { | ||
// this.props.searchCallback(`Successfully added ${addedMovieData.title} to library`) | ||
// }) | ||
// .catch((error) => { | ||
// console.log(`Error: ${error.message}`); | ||
// }) | ||
// } | ||
|
||
render() { | ||
// const result = this.state.result.map((movie, i) => { | ||
// return | ||
// <div> | ||
// <p><movie.title></p> | ||
// </div> | ||
|
||
export default Search; | ||
// }); | ||
return ( | ||
<form className="search-movie-form" onSubmit={this.searchMovie}> | ||
<div className="search-movie"> | ||
<h3 className="search-movie__header">Search Movie</h3> | ||
</div> | ||
<div> | ||
<label | ||
className="search-movie-form__form-label" | ||
htmlFor="title">Movie Title</label> | ||
<input className="search-movie-form__form-input" | ||
name="titleSearch" | ||
onChange={this.onChangeHandler} | ||
value={this.state.titleSearch}> | ||
</input> | ||
</div> | ||
<input className="search-movie-form__form-button" type="submit" name="submit" value="Search Movie" /> | ||
</form> | ||
)}; | ||
} | ||
|
||
Search.propTypes = { | ||
searchMovieResults: PropTypes.func.isRequired, | ||
}; | ||
|
||
export default Search; |