diff --git a/client/src/App.js b/client/src/App.js index 048a1923..25f8ad3d 100644 --- a/client/src/App.js +++ b/client/src/App.js @@ -8,7 +8,7 @@ import MovieHeader from './components/MovieHeader'; import EditMovieForm from './components/EditMovieForm'; import FavoriteMovieList from './components/FavoriteMovieList'; - +import AddMovieForm from "./components/addMovieForm"; import axios from 'axios'; const App = (props) => { @@ -26,6 +26,7 @@ const App = (props) => { }, []); const deleteMovie = (id)=> { + } const addToFavorites = (movie) => { @@ -44,20 +45,24 @@ const App = (props) => { - - + } /> - - - + } /> - - - + } /> + + } /> + diff --git a/client/src/components/DeleteMovieModal.js b/client/src/components/DeleteMovieModal.js index 87b96bb5..eebb188d 100644 --- a/client/src/components/DeleteMovieModal.js +++ b/client/src/components/DeleteMovieModal.js @@ -1,6 +1,9 @@ +import axios from 'axios'; import React from 'react'; const DeleteMovieModal = () => { + + return (
diff --git a/client/src/components/EditMovieForm.js b/client/src/components/EditMovieForm.js index 9c058388..3a835ae3 100644 --- a/client/src/components/EditMovieForm.js +++ b/client/src/components/EditMovieForm.js @@ -6,6 +6,7 @@ import axios from 'axios'; const EditMovieForm = (props) => { const { push } = useHistory(); + const { id } = useParams() const [movie, setMovie] = useState({ title:"", @@ -22,8 +23,26 @@ const EditMovieForm = (props) => { }); } + useEffect(()=> { + axios.get(`http://localhost:5000/api/movies/${id}`) + .then(resp=> { + setMovie(resp.data); + }) + .catch(err=> { + console.log(err); + }) + }, []); + const handleSubmit = (e) => { e.preventDefault(); + axios.put(`http://localhost:5000/api/movies/${id}`, movie) + .then(resp=> { + props.setMovies(resp.data); + push(`/movies/${id}`); + }) + .catch(err=> { + console.log(err); + }) } const { title, director, genre, metascore, description } = movie; diff --git a/client/src/components/Movie.js b/client/src/components/Movie.js index fc2b0e05..42035d69 100644 --- a/client/src/components/Movie.js +++ b/client/src/components/Movie.js @@ -21,6 +21,17 @@ const Movie = (props) => { }) }, [id]); + + const handleDelete = () =>{ + axios.delete(`http://localhost:5000/api/movies/${id}`) + .then(resp=>{ + props.setMovies(resp.data); + push('/movies'); + }) + .catch(err => { + console.log(err); + }) + } return(
@@ -52,7 +63,7 @@ const Movie = (props) => {
Favorite Edit - +
diff --git a/client/src/components/MovieHeader.js b/client/src/components/MovieHeader.js index 48ee5dd6..63376508 100644 --- a/client/src/components/MovieHeader.js +++ b/client/src/components/MovieHeader.js @@ -1,6 +1,7 @@ import React from 'react'; import { Link } from 'react-router-dom'; + const MovieHeader = ()=> { return(
@@ -8,7 +9,7 @@ const MovieHeader = ()=> {

IMDB Movie Database

- Add New Movie + Add New Movie View All Movies
diff --git a/client/src/components/addMovieForm.js b/client/src/components/addMovieForm.js new file mode 100644 index 00000000..1ce554d4 --- /dev/null +++ b/client/src/components/addMovieForm.js @@ -0,0 +1,78 @@ +import React, { useState } from 'react'; +import { useHistory } from 'react-router-dom'; +import { Link } from 'react-router-dom'; + +import axios from 'axios'; + +const AddMovieForm = (props) => { + const { push } = useHistory(); + + const [movie, setMovie] = useState({ + title:"", + director: "", + genre: "", + metascore: 0, + description: "" + }); + + const handleChange = (e) => { + setMovie({ + ...movie, + [e.target.name]: e.target.value + }); + } + + const handleSubmit = (e) => { + axios.post(`http://localhost:5000/api/movies`, movie) + .then(res => { + props.setMovies(res.data); + push('/movies'); + }) + .catch(err=> { + console.log(err); + }) + } + + + const { title, director, genre, metascore, description } = movie; + + return ( +
+
+
+
+

Editing {movie.title}

+
+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+ +
+
+ + +
+
+
+
); +} + +export default AddMovieForm; \ No newline at end of file