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 #746

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

Done #746

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
36 changes: 35 additions & 1 deletion src/components/LatestMovieReviewsContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,42 @@ import React, { Component } from 'react';
import 'isomorphic-fetch';
import MovieReviews from './MovieReviews'

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

// Code LatestMovieReviewsContainer Here
class LatestMovieReviewsContainer extends React.Component {
constructor(props) {
super(props);

// Initial state here...
this.state = {
reviews: []
};
}

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

shouldComponentUpdate(nextProps, nextState) {
if (this.state.reviews === nextState.reviews) {
return false
}
return true
}


render() {
// Return JSX that renders into HTML
return(
<div className="latest-movie-reviews">
<MovieReviews reviews={this.state.reviews}/>
</div>)
}
}

export default LatestMovieReviewsContainer
10 changes: 9 additions & 1 deletion src/components/MovieReviews.js
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
// Code MovieReviews Here
import React from 'react';

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

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

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

// Code SearchableMovieReviewsContainer Here
class SearchableMovieReviewsContainer extends React.Component {
constructor(props) {
super(props);

// Initial state here...
this.state = {
searchTerm: "car",
reviews: []
};
}

handleSubmit(searchTerm) {
fetch(URL+`&query=${searchTerm}`)
.then(response => response.json())
.then(reviewData => this.setState({ reviews: reviewData.results }))
}

shouldComponentUpdate(nextProps, nextState) {
if (this.state.reviews === nextState.reviews) {
return false
}
return true
}

handleChange = (event)=>{
this.setState(
{
...this.state.reviews,
searchTerm: e.target.value
}
)
}



render() {
// Return JSX that renders into HTML
return(
<div className="searchable-movie-reviews">
<form onSubmit={()=> this.handleSubmit(this.state.searchTerm)}>
<div>
<label>
Search
<input id="username" name="username" onChange={e => this.handleChange(e)} type="text" value={this.state.searchTerm} />
</label>
</div>
<div>
<button type="submit">Search</button>
</div>
</form>
<MovieReviews reviews={this.state.reviews}/>
</div>
)
}
}

export default SearchableMovieReviewsContainer