diff --git a/README.md b/README.md index e1509e4e47..216c4c874c 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ Topics: * When a user clicks on a movie card they should be taken to `/movies/{id of movie here}` to see the details for the selected movie. * You will need to modify line 13 of `Movie.js` in order to accept the correct id for the movie selected. * Add functionality so the `Home` button on the `SavedList` component navigates back to home. -* You should now be able to navigate back and forth between the individual movies and the home screen. +** You should now be able to navigate back and forth between the individual movies and the home screen. ## Stretch Goals. diff --git a/client/src/App.js b/client/src/App.js index 740adc7a8a..27e327cb57 100644 --- a/client/src/App.js +++ b/client/src/App.js @@ -1,18 +1,22 @@ import React, { useState } from 'react'; - +import { Route } from 'react-router-dom'; +import Movie from './Movies/Movie'; +//import MovieCard from './Movies/MovieCard'; +import MovieList from './Movies/MovieList'; import SavedList from './Movies/SavedList'; const App = () => { - const [savedList, setSavedList] = useState( [] ); + const [savedList, setSavedList] = useState([]); const addToSavedList = movie => { - setSavedList( [...savedList, movie] ); + setSavedList([...savedList, movie]); }; return (
-
Replace this Div with your Routes
+ +
); }; diff --git a/client/src/Movies/Movie.js b/client/src/Movies/Movie.js index 25dd470bee..ffd97a872e 100644 --- a/client/src/Movies/Movie.js +++ b/client/src/Movies/Movie.js @@ -2,24 +2,26 @@ import React, { useState, useEffect } from 'react'; import axios from 'axios'; const Movie = (props) => { - const [movie, setMovie] = useState({}); - + const [movie, setMovie] = useState(); + console.log('Movie', props, props.match.params.id); + useEffect(() => { - const id = 1; + const id = props.match.params.id; + console.log(id) // change ^^^ that line and grab the id from the URL // You will NEED to add a dependency array to this effect hook - axios - .get(`http://localhost:5000/api/movies/${id}`) - .then(response => { - setMovie(response.data); - }) - .catch(error => { - console.error(error); - }); - - },[]); - + axios + .get(`http://localhost:5000/api/movies/${id}`) + .then(response => { + setMovie(response.data); + }) + .catch(error => { + console.error(error); + }); + + }, [props.match.params.id]); + // Uncomment this only when you have moved on to the stretch goals // const saveMovie = () => { // const addToSavedList = props.addToSavedList; diff --git a/client/src/Movies/MovieList.js b/client/src/Movies/MovieList.js index ab22a906a1..73aab2b151 100644 --- a/client/src/Movies/MovieList.js +++ b/client/src/Movies/MovieList.js @@ -1,5 +1,7 @@ import React, { useState, useEffect } from 'react'; import axios from 'axios'; +import { Link } from 'react-router-dom' + const MovieList = props => { const [movies, setMovies] = useState([]) @@ -14,10 +16,10 @@ const MovieList = props => { console.error('Server Error', error); }); } - + getMovies(); }, []); - + return (
{movies.map(movie => ( @@ -28,13 +30,19 @@ const MovieList = props => { } function MovieDetails({ movie }) { + const { title, director, metascore, stars } = movie; return ( +
-

{title}

+ +

{title}

+ +
Director: {director}
+
Metascore: {metascore}
@@ -46,6 +54,7 @@ function MovieDetails({ movie }) {
))}
+ ); } diff --git a/client/src/Movies/SavedList.js b/client/src/Movies/SavedList.js index 2c7d484cac..5551cb8ba1 100644 --- a/client/src/Movies/SavedList.js +++ b/client/src/Movies/SavedList.js @@ -1,4 +1,5 @@ import React from 'react'; +import { Link } from 'react-router-dom' const SavedList = props => (
@@ -6,7 +7,7 @@ const SavedList = props => ( {props.list.map(movie => ( {movie.title} ))} -
Home
+ Home
); diff --git a/client/src/index.css b/client/src/index.css index 80f0cec934..41299d9848 100644 --- a/client/src/index.css +++ b/client/src/index.css @@ -69,4 +69,5 @@ body { .home-button { padding: 5px 10px; background-color: lightskyblue; + text-decoration: none; } diff --git a/client/src/index.js b/client/src/index.js index 9eac967ab4..58da5e65b9 100644 --- a/client/src/index.js +++ b/client/src/index.js @@ -1,7 +1,10 @@ import React from 'react'; import ReactDOM from 'react-dom'; - +import { BrowserRouter as Router } from 'react-router-dom'; import './index.css'; import App from './App'; -ReactDOM.render(, document.getElementById('root')); +ReactDOM.render( + + + , document.getElementById('root'));