Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Done #747

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Done #747

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
22 changes: 21 additions & 1 deletion src/components/LatestMovieReviewsContainer.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,29 @@
import React, { Component } from 'react';
import 'isomorphic-fetch';
import MovieReviews from './MovieReviews'
import { render } from 'enzyme';

const NYT_API_KEY = 'your-key-here';
const NYT_API_KEY = '8ZQNa4f2Wn0pi7TydyxTFiusUj69sPtM';
const URL = 'https://api.nytimes.com/svc/movies/v2/reviews/all.json?'
+ `api-key=${NYT_API_KEY}`;

// Code LatestMovieReviewsContainer Here
class LatestMovieReviewsContainer extends Component {
state = {movieList: []}

componentDidMount(){
fetch(URL)
.then(resp => resp.json())
.then(response => this.setState({movieList: response.results}))
}

render() {
return(
<div className='latest-movie-reviews'>
<h2>latest movies!</h2>
<MovieReviews reviews={this.state.movieList} />
</div>
)
}
}
export default LatestMovieReviewsContainer
35 changes: 35 additions & 0 deletions src/components/MovieReviews.js
Original file line number Diff line number Diff line change
@@ -1 +1,36 @@
// Code MovieReviews Here
import React from 'react'
const Review = ({
headline,
byline,
link,
summary_short
}) => {
return (

<div
key={headline}
className="review"
>
<header>
<a
className="review-link"
href={link.url}
>
{headline}
</a>
<br/>
<span className="author">{byline}</span>
</header>
<blockquote>{summary_short}</blockquote>
</div>
);
};

const MovieReviews = ({ reviews }) => <div className="review-list">{reviews.map(Review)}</div>;

MovieReviews.defaultProps = {
reviews: []
};

export default MovieReviews
32 changes: 31 additions & 1 deletion src/components/SearchableMovieReviewsContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,38 @@ import React, { Component } from 'react';
import 'isomorphic-fetch';
import MovieReviews from './MovieReviews'

const NYT_API_KEY = 'your-key-here';
const NYT_API_KEY = '8ZQNa4f2Wn0pi7TydyxTFiusUj69sPtM';
const URL = 'https://api.nytimes.com/svc/movies/v2/reviews/search.json?'
+ `api-key=${NYT_API_KEY}`;

// Code SearchableMovieReviewsContainer Here
class SearchableMovieReviewsContainer extends Component {
state = {moviesList : [], searchTerm: ''}

render() {
return(
<div className='searchable-movie-reviews'>
<form onSubmit={this.movieSearch}>
<label>search for a specific movie</label>
<input type='text' onChange={this.movieNameInput}></input>
<button type='submit'>submit</button>
</form>
{typeof this.state.reviews === 'object' &&
this.state.reviews.length > 0 && <h2>Movie Review By Search:</h2>}
<MovieReviews reviews={this.state.moviesList} />
</div>
)
}

movieNameInput = (event) => {
this.setState({searchTerm: URL + `&query=${event.target.value}`})
}

movieSearch = event => {
event.preventDefault()
fetch(this.state.searchTerm)
.then(res => res.json())
.then(results => this.setState({moviesList: results.results}))
}
}
export default SearchableMovieReviewsContainer