Skip to content
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
11 changes: 8 additions & 3 deletions src/actions/movieActions.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
export const DELETE_MOVIE = "DELETE_MOVIE";
export const ADD_MOVIE = "ADD_MOVIE";

export const deleteMovie = (id)=>{
return({type: DELETE_MOVIE, payload:id});
}
export const deleteMovie = (id) => {
return { type: DELETE_MOVIE, payload: id };
};

export const addMovie = (newMovie) => {
return { type: ADD_MOVIE, payload: newMovie };
};
162 changes: 103 additions & 59 deletions src/components/AddMovieForm.js
Original file line number Diff line number Diff line change
@@ -1,70 +1,114 @@
import React, { useState } from 'react';
import { addMovie } from './../actions/movieActions';
import { connect } from 'react-redux';
import React, { useState } from "react";
import { addMovie } from "./../actions/movieActions";
import { connect } from "react-redux";

import { Link, useHistory } from 'react-router-dom';
import { Link, useHistory } from "react-router-dom";

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

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

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

const handleSubmit = (e) => {
}
const handleSubmit = (e) => {
e.preventDefault;
props.addMovie(movie);
push("/movies");
};

const { title, director, genre, metascore, description } = movie;
return(<div className="col">
<div className="modal-dialog">
<div className="modal-content">
<form onSubmit={handleSubmit}>
<div className="modal-header">
<h4 className="modal-title">Add Movie</h4>
</div>
const { title, director, genre, metascore, description } = movie;
return (
<div className="col">
<div className="modal-dialog">
<div className="modal-content">
<form onSubmit={handleSubmit}>
<div className="modal-header">
<h4 className="modal-title">Add Movie</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-success" value="Add"/>
<Link to={`/movies`}><input type="button" className="btn btn-default" value="Cancel"/></Link>
</div>
</form>
<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-success"
value="Add"
onClick={handleSubmit}
/>
<Link to={`/movies`}>
<input
type="button"
className="btn btn-default"
value="Cancel"
/>
</Link>
</div>
</form>
</div>
</div>);
}
</div>
</div>
);
};

export default AddMovieForm;
export default connect(null, { addMovie })(AddMovieForm);
69 changes: 48 additions & 21 deletions src/components/FavoriteMovieList.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,52 @@
import React from 'react';
import React from "react";

import { Link } from 'react-router-dom';
import { Link } from "react-router-dom";

import { connect } from "react-redux";

import { removeFavorite } from "../actions/favoritesActions";

const FavoriteMovieList = (props) => {
const favorites = [];

return (<div className="col-xs savedContainer">
<h5>Favorite Movies</h5>
{
favorites.map(movie=>{
return <div key={movie.id}>
<Link className="btn btn-light savedButton" to={`/movies/${movie.id}`}>
{movie.title}
<span><span class="material-icons">remove_circle</span></span>
</Link>
</div>
})
}
</div>);
}


export default FavoriteMovieList;
const { favorites } = props;
console.log(favorites);

const handleRemove = (id) => {
props.removeFavorite(id);
};

return (
<div className="col-xs savedContainer">
<h5>Favorite Movies</h5>
{favorites.map((movie) => {
return (
<div key={movie.id}>
<Link
className="btn btn-light savedButton"
to={`/movies/${movie.id}`}
>
{movie.title}
<span>
<span
onClick={() => handleRemove(movie.id)}
class="material-icons"
>
remove_circle
</span>
</span>
</Link>
</div>
);
})}
</div>
);
};

const mapStateToProps = (state) => {
console.log(state);
return {
favorites: state.favoritesReducer.favorites,
displayFavorites: state.favoritesReducer.displayFavorites,
};
};

export default connect(mapStateToProps, { removeFavorite })(FavoriteMovieList);
Loading