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

Leo Ọládimú #108

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
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
33,803 changes: 28,734 additions & 5,069 deletions client/package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"axios": "^0.19.0",
"axios": "^0.23.0",
"react": "^16.9.0",
"react-dom": "^16.9.0",
"react-router-dom": "^5.0.1",
"react-scripts": "^3.1.1"
"react-scripts": "^4.0.3"
},
"scripts": {
"start": "react-scripts start",
Expand Down
36 changes: 23 additions & 13 deletions client/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,28 @@ import EditMovieForm from './components/EditMovieForm';
import FavoriteMovieList from './components/FavoriteMovieList';

import axios from 'axios';
import AddMovieForm from "./components/AddMovieForm";

const App = (props) => {
const [movies, setMovies] = useState([]);
console.log('☃︎', '☠︎', props, movies);
const [favoriteMovies, setFavoriteMovies] = useState([]);

useEffect(()=>{
axios.get('http://localhost:5000/api/movies')
.then(res => {
setMovies(res.data);
})
.catch(err => {
console.log(err);
});
}, []);

const deleteMovie = (id)=> {
// useEffect(() => {
// axios.get('http://localhost:3002/api/movies')
// .then('☠︎', r => {
// setMovies(r.data);
// })
// .catch(err => {
// console.log(err);
// });
// }, []);

const deleteMovie = (id) => {
setMovies(
movies.filter(
movie => movie.id !== Number(id)
));
}

const addToFavorites = (movie) => {
Expand All @@ -35,7 +41,7 @@ const App = (props) => {
return (
<div>
<nav className="navbar navbar-dark bg-dark">
<span className="navbar-brand" ><img width="40px" alt="" src="./Lambda-Logo-Red.png"/> HTTP / CRUD Module Project</span>
<span className="navbar-brand" ><img width="40px" alt="" src="./Lambda-Logo-Red.png"/> HTTP / CRUD Module Project </span>
</nav>

<div className="container">
Expand All @@ -45,12 +51,17 @@ const App = (props) => {

<Switch>
<Route path="/movies/edit/:id">
<EditMovieForm setMovies = { setMovies } />
</Route>

<Route path="/movies/:id">
<Movie/>
</Route>

<Route path="/movies/add">
<AddMovieForm setMovies = { setMovies } />
</Route>

<Route path="/movies">
<MovieList movies={movies}/>
</Route>
Expand All @@ -67,4 +78,3 @@ const App = (props) => {


export default App;

87 changes: 87 additions & 0 deletions client/src/components/AddMovieForm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import React, { useState, useEffect } from 'react';
import { useParams, useHistory } from 'react-router-dom';
import { Link } from 'react-router-dom';
import axios from 'axios';

const AddMovieForm = (props) => {
console.log(props);
const { push } = useHistory();

useEffect(() => {
axios.get(`http://localhost:3002/api/movies/${id}`)
.then(res => {
setNewMovie(res.data);
})
.catch(err => console.log(err));
}, [])

const [movie, setMovie] = useState({
title:'',
director:'',
genre: '',
metascore: 0,
description: ''
});

const handleChange = (e) => {
setMovie({
...movie,
[e.target.name]: e.target.value
});
}

const handleSubmit = (e) => {
e.preventDefault();
axios.post(`http://localhost:3002/api/movies`, movie)
.then(res => {
props.setMovies(res.data);
push(`/movies`);
})
.catch(err => {
console.log(err.response);
});
};

const { title, director, genre, metascore, description } = movie;

return (

<div className="col">
<div className="modal-content">
<form onSubmit={handleSubmit}>
<div className="modal-header">
<h4 className="modal-title">Adding <strong>{movie.title}</strong></h4>
</div>
<div className="modal-body">
<div className="form-group">
<label>Title</label>
<input value={title} onChange={handleChange} name="title" type="text" className="form-control"/>
</div>
<div className="form-group">
<label>Director</label>
<input value={director} onChange={handleChange} name="director" type="text" className="form-control"/>
</div>
<div className="form-group">
<label>Genre</label>
<input value={genre} onChange={handleChange} name="genre" type="text" className="form-control"/>
</div>
<div className="form-group">
<label>Metascore</label>
<input value={metascore} onChange={handleChange} name="metascore" type="number" className="form-control"/>
</div>
<div className="form-group">
<label>Description</label>
<textarea value={description} onChange={handleChange} name="description" className="form-control"></textarea>
</div>

</div>
<div className="modal-footer">
<input type="submit" className="btn btn-info" value="Save"/>
<Link to={`/movies`}><input type="button" className="btn btn-default" value="Cancel"/></Link>
</div>
</form>
</div>
</div>);
}

export default AddMovieForm;
2 changes: 1 addition & 1 deletion client/src/components/DeleteMovieModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const DeleteMovieModal = () => {
<h4 className="modal-title">Delete Movie</h4>
<button type="button" className="close" data-dismiss="modal" aria-hidden="true">&times;</button>
</div>
<div className="modal-body">
<div className="modal-body">
<p>Are you sure you want to delete these records?</p>
<p className="text-warning"><small>This action cannot be undone.</small></p>
</div>
Expand Down
3 changes: 1 addition & 2 deletions client/src/components/MovieList.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@ const MovieList = (props)=> {
<th></th>
</tr>
</thead>

<tbody>
{
movies.map(movie=><MovieListItem key={movie.id} movie={movie}/>)
movies.map(movie => <MovieListItem key={movie.id} movie={movie}/>)
}
</tbody>
</table>
Expand Down
Loading