diff --git a/client/package-lock.json b/client/package-lock.json index 79a45ec39..cd3583dbc 100644 --- a/client/package-lock.json +++ b/client/package-lock.json @@ -8054,7 +8054,8 @@ }, "ansi-regex": { "version": "2.1.1", - "bundled": true + "bundled": true, + "optional": true }, "aproba": { "version": "1.2.0", @@ -8072,11 +8073,13 @@ }, "balanced-match": { "version": "1.0.0", - "bundled": true + "bundled": true, + "optional": true }, "brace-expansion": { "version": "1.1.11", "bundled": true, + "optional": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -8089,15 +8092,18 @@ }, "code-point-at": { "version": "1.1.0", - "bundled": true + "bundled": true, + "optional": true }, "concat-map": { "version": "0.0.1", - "bundled": true + "bundled": true, + "optional": true }, "console-control-strings": { "version": "1.1.0", - "bundled": true + "bundled": true, + "optional": true }, "core-util-is": { "version": "1.0.2", @@ -8200,7 +8206,8 @@ }, "inherits": { "version": "2.0.4", - "bundled": true + "bundled": true, + "optional": true }, "ini": { "version": "1.3.5", @@ -8210,6 +8217,7 @@ "is-fullwidth-code-point": { "version": "1.0.0", "bundled": true, + "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -8222,17 +8230,20 @@ "minimatch": { "version": "3.0.4", "bundled": true, + "optional": true, "requires": { "brace-expansion": "^1.1.7" } }, "minimist": { "version": "1.2.5", - "bundled": true + "bundled": true, + "optional": true }, "minipass": { "version": "2.9.0", "bundled": true, + "optional": true, "requires": { "safe-buffer": "^5.1.2", "yallist": "^3.0.0" @@ -8249,6 +8260,7 @@ "mkdirp": { "version": "0.5.3", "bundled": true, + "optional": true, "requires": { "minimist": "^1.2.5" } @@ -8304,7 +8316,8 @@ }, "npm-normalize-package-bin": { "version": "1.0.1", - "bundled": true + "bundled": true, + "optional": true }, "npm-packlist": { "version": "1.4.8", @@ -8329,7 +8342,8 @@ }, "number-is-nan": { "version": "1.0.1", - "bundled": true + "bundled": true, + "optional": true }, "object-assign": { "version": "4.1.1", @@ -8339,6 +8353,7 @@ "once": { "version": "1.4.0", "bundled": true, + "optional": true, "requires": { "wrappy": "1" } @@ -8407,7 +8422,8 @@ }, "safe-buffer": { "version": "5.1.2", - "bundled": true + "bundled": true, + "optional": true }, "safer-buffer": { "version": "2.1.2", @@ -8437,6 +8453,7 @@ "string-width": { "version": "1.0.2", "bundled": true, + "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", @@ -8454,6 +8471,7 @@ "strip-ansi": { "version": "3.0.1", "bundled": true, + "optional": true, "requires": { "ansi-regex": "^2.0.0" } @@ -8492,11 +8510,13 @@ }, "wrappy": { "version": "1.0.2", - "bundled": true + "bundled": true, + "optional": true }, "yallist": { "version": "3.1.1", - "bundled": true + "bundled": true, + "optional": true } } } @@ -15297,7 +15317,8 @@ }, "ansi-regex": { "version": "2.1.1", - "bundled": true + "bundled": true, + "optional": true }, "aproba": { "version": "1.2.0", @@ -15315,11 +15336,13 @@ }, "balanced-match": { "version": "1.0.0", - "bundled": true + "bundled": true, + "optional": true }, "brace-expansion": { "version": "1.1.11", "bundled": true, + "optional": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -15332,15 +15355,18 @@ }, "code-point-at": { "version": "1.1.0", - "bundled": true + "bundled": true, + "optional": true }, "concat-map": { "version": "0.0.1", - "bundled": true + "bundled": true, + "optional": true }, "console-control-strings": { "version": "1.1.0", - "bundled": true + "bundled": true, + "optional": true }, "core-util-is": { "version": "1.0.2", @@ -15443,7 +15469,8 @@ }, "inherits": { "version": "2.0.4", - "bundled": true + "bundled": true, + "optional": true }, "ini": { "version": "1.3.5", @@ -15453,6 +15480,7 @@ "is-fullwidth-code-point": { "version": "1.0.0", "bundled": true, + "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -15465,17 +15493,20 @@ "minimatch": { "version": "3.0.4", "bundled": true, + "optional": true, "requires": { "brace-expansion": "^1.1.7" } }, "minimist": { "version": "1.2.5", - "bundled": true + "bundled": true, + "optional": true }, "minipass": { "version": "2.9.0", "bundled": true, + "optional": true, "requires": { "safe-buffer": "^5.1.2", "yallist": "^3.0.0" @@ -15492,6 +15523,7 @@ "mkdirp": { "version": "0.5.3", "bundled": true, + "optional": true, "requires": { "minimist": "^1.2.5" } @@ -15547,7 +15579,8 @@ }, "npm-normalize-package-bin": { "version": "1.0.1", - "bundled": true + "bundled": true, + "optional": true }, "npm-packlist": { "version": "1.4.8", @@ -15572,7 +15605,8 @@ }, "number-is-nan": { "version": "1.0.1", - "bundled": true + "bundled": true, + "optional": true }, "object-assign": { "version": "4.1.1", @@ -15582,6 +15616,7 @@ "once": { "version": "1.4.0", "bundled": true, + "optional": true, "requires": { "wrappy": "1" } @@ -15650,7 +15685,8 @@ }, "safe-buffer": { "version": "5.1.2", - "bundled": true + "bundled": true, + "optional": true }, "safer-buffer": { "version": "2.1.2", @@ -15680,6 +15716,7 @@ "string-width": { "version": "1.0.2", "bundled": true, + "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", @@ -15697,6 +15734,7 @@ "strip-ansi": { "version": "3.0.1", "bundled": true, + "optional": true, "requires": { "ansi-regex": "^2.0.0" } @@ -15735,11 +15773,13 @@ }, "wrappy": { "version": "1.0.2", - "bundled": true + "bundled": true, + "optional": true }, "yallist": { "version": "3.1.1", - "bundled": true + "bundled": true, + "optional": true } } }, @@ -16056,7 +16096,8 @@ }, "ansi-regex": { "version": "2.1.1", - "bundled": true + "bundled": true, + "optional": true }, "aproba": { "version": "1.2.0", @@ -16074,11 +16115,13 @@ }, "balanced-match": { "version": "1.0.0", - "bundled": true + "bundled": true, + "optional": true }, "brace-expansion": { "version": "1.1.11", "bundled": true, + "optional": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -16091,15 +16134,18 @@ }, "code-point-at": { "version": "1.1.0", - "bundled": true + "bundled": true, + "optional": true }, "concat-map": { "version": "0.0.1", - "bundled": true + "bundled": true, + "optional": true }, "console-control-strings": { "version": "1.1.0", - "bundled": true + "bundled": true, + "optional": true }, "core-util-is": { "version": "1.0.2", @@ -16202,7 +16248,8 @@ }, "inherits": { "version": "2.0.4", - "bundled": true + "bundled": true, + "optional": true }, "ini": { "version": "1.3.5", @@ -16212,6 +16259,7 @@ "is-fullwidth-code-point": { "version": "1.0.0", "bundled": true, + "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -16224,17 +16272,20 @@ "minimatch": { "version": "3.0.4", "bundled": true, + "optional": true, "requires": { "brace-expansion": "^1.1.7" } }, "minimist": { "version": "1.2.5", - "bundled": true + "bundled": true, + "optional": true }, "minipass": { "version": "2.9.0", "bundled": true, + "optional": true, "requires": { "safe-buffer": "^5.1.2", "yallist": "^3.0.0" @@ -16251,6 +16302,7 @@ "mkdirp": { "version": "0.5.3", "bundled": true, + "optional": true, "requires": { "minimist": "^1.2.5" } @@ -16306,7 +16358,8 @@ }, "npm-normalize-package-bin": { "version": "1.0.1", - "bundled": true + "bundled": true, + "optional": true }, "npm-packlist": { "version": "1.4.8", @@ -16331,7 +16384,8 @@ }, "number-is-nan": { "version": "1.0.1", - "bundled": true + "bundled": true, + "optional": true }, "object-assign": { "version": "4.1.1", @@ -16341,6 +16395,7 @@ "once": { "version": "1.4.0", "bundled": true, + "optional": true, "requires": { "wrappy": "1" } @@ -16409,7 +16464,8 @@ }, "safe-buffer": { "version": "5.1.2", - "bundled": true + "bundled": true, + "optional": true }, "safer-buffer": { "version": "2.1.2", @@ -16439,6 +16495,7 @@ "string-width": { "version": "1.0.2", "bundled": true, + "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", @@ -16456,6 +16513,7 @@ "strip-ansi": { "version": "3.0.1", "bundled": true, + "optional": true, "requires": { "ansi-regex": "^2.0.0" } @@ -16494,11 +16552,13 @@ }, "wrappy": { "version": "1.0.2", - "bundled": true + "bundled": true, + "optional": true }, "yallist": { "version": "3.1.1", - "bundled": true + "bundled": true, + "optional": true } } }, diff --git a/client/src/App.js b/client/src/App.js index 66daf147f..ea9ccf7e3 100644 --- a/client/src/App.js +++ b/client/src/App.js @@ -1,8 +1,10 @@ import React, { useState, useEffect } from "react"; -import { Route } from "react-router-dom"; +import { Route, NavLink } from "react-router-dom"; import SavedList from "./Movies/SavedList"; import MovieList from "./Movies/MovieList"; import Movie from "./Movies/Movie"; +import UpdateForm from "./components/UpdateForm" +import AddMovieInfo from "./components/AddMovieInfo"; import axios from 'axios'; const App = () => { @@ -28,12 +30,24 @@ const App = () => { <> +
+ Add New Movie Info +
+ + + + + - + + + + + ); diff --git a/client/src/Movies/Movie.js b/client/src/Movies/Movie.js index e2da52bdb..77a06eecb 100644 --- a/client/src/Movies/Movie.js +++ b/client/src/Movies/Movie.js @@ -1,11 +1,13 @@ import React, { useEffect, useState } from "react"; import axios from "axios"; -import { useParams } from "react-router-dom"; +import { useParams, useHistory } from "react-router-dom"; import MovieCard from "./MovieCard"; -function Movie({ addToSavedList }) { +function Movie({ addToSavedList, getMovieList }) { const [movie, setMovie] = useState(null); - const params = useParams(); + const { id } = useParams(); + console.log(" id params for movies", id) + const { push } = useHistory() const fetchMovie = (id) => { axios @@ -18,9 +20,23 @@ function Movie({ addToSavedList }) { addToSavedList(movie); }; + const deleteMovie = e => { + e.preventDefault(); + axios + // I did a delete request to delete movies + .delete(`http://localhost:5000/api/movies/${id}`) + .then(res => { + getMovieList(res.data); + push('/') + }) + .catch(err => console.log(err.message)) + } + useEffect(() => { - fetchMovie(params.id); - }, [params.id]); + fetchMovie(id); + }, [id]); + + if (!movie) { return
Loading movie information...
; @@ -33,6 +49,12 @@ function Movie({ addToSavedList }) {
Save
+ + ); } diff --git a/client/src/components/AddMovieInfo.js b/client/src/components/AddMovieInfo.js new file mode 100644 index 000000000..5279035fd --- /dev/null +++ b/client/src/components/AddMovieInfo.js @@ -0,0 +1,75 @@ +import React, { useState } from "react"; +import { useParams, useHistory } from "react-router-dom"; +import axios from "axios"; + +const AddMovieInfo = ({ getMovieList }) => { + const movieInfo = { + id: Date.now(), + title: "", + director: "", + metarscore: "", + stars: [], + }; + + const [newMovie, setNewMovie] = useState(movieInfo); + const { push } = useHistory(); + + + const handleChanger = (e) => { + setNewMovie({ ...newMovie, [e.target.name]: e.target.value }); + }; + + const handleSubmit = (e) => { + e.preventDefault(); + axios + .post("http://localhost:5000/api/movies", newMovie) + .then((res) => { + console.log("The response for newFriendFrom is:", res); + setNewMovie(res.data); + getMovieList(); + push("/"); + }) + .catch((err) => console.log("NewMovie data error:", err.message)); + setNewMovie({ + title: "", + director: "", + metarscore: "", + stars: [], + }); + }; + + return ( + <> +

Please Add A New Movie Info

+
+ + + + + + + +
+ + ); +}; + +export default AddMovieInfo; diff --git a/client/src/components/UpdateForm.js b/client/src/components/UpdateForm.js new file mode 100644 index 000000000..8cce5c6be --- /dev/null +++ b/client/src/components/UpdateForm.js @@ -0,0 +1,109 @@ +import React, { useState, useEffect } from "react"; +import { useParams, useHistory } from "react-router-dom"; +import axios from "axios"; + +const initialItem = { + id: "", + title: "", + director: "", + metascore: "", + stars: [], +}; + +const UpdateForm = ({ getMovieList }) => { + const [update, setUpdate] = useState(initialItem); + const { push } = useHistory(); + //This one shows the variables in the url + const { id } = useParams(); + console.log("This is the id params for update", id); + + useEffect(() => { + axios + .get(`http://localhost:5000/api/movies/${id}`) + .then((res) => { + console.log("This is the Update Response", res); + setUpdate(res.data); + }) + .catch((error) => console.log("This is the update error", error.message)); + }, [id]); + const handleChanger = (e) => { + e.persist(); + + setUpdate({ + ...update, + [e.target.name]: e.target.value, + }); + }; + + const starsChangeHandler = (e, index) => { + e.persist(); + let actors = [...update.stars]; + actors[index] = e.target.value; + console.log("This is the actors index", actors[index]); + setUpdate({ ...update, stars: [...actors] }); + }; + + const handleSubmit = (e) => { + e.preventDefault(); + // I did a PUT request to update movies + axios + .put(`http://localhost:5000/api/movies/${id}`, update) + .then((res) => { + console.log("Updating response", res.data); + getMovieList(); + push("/"); + }) + .catch((err) => console.log("The error is:", err.message)); + }; + + return ( +
+

Please Update Movie

+
+ + + + + +Im doing some mapping here with the +
+

Update New Actors

+ {update.stars.map((actor, index) => { + return ( +
+ starsChangeHandler(e, index)} + /> +
+ ); + })} +
+ + +
+
+ ); +}; + +export default UpdateForm;