-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Patrick Lusaya
committed
Jun 7, 2023
1 parent
23687dc
commit 0dede9c
Showing
11 changed files
with
251 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,88 @@ | ||
import React, { Component } from 'react' | ||
import {connect} from 'react-redux'; | ||
import {Link} from 'react-router-dom' | ||
import { fetchMovies } from '../redux/action'; | ||
|
||
import '../App.css' | ||
import React, { Component } from 'react'; | ||
import { connect } from 'react-redux'; | ||
import { Link } from 'react-router-dom'; | ||
import { fetchMovies, searchMovies, setSearchTerm } from '../redux/action'; | ||
|
||
import '../App.css'; | ||
|
||
class Movie extends Component { | ||
componentDidMount() { | ||
this.props.fetchMovies(); | ||
} | ||
handleSearch = () => { | ||
const searchTerm = this.props.searchTerm; | ||
this.props.searchMovies(searchTerm); | ||
}; | ||
handleInputChange = (event) => { | ||
const searchTerm = event.target.value; | ||
this.props.setSearchTerm(searchTerm); | ||
}; | ||
|
||
|
||
componentDidMount(){ | ||
this.props.fetchMovies() | ||
} | ||
|
||
|
||
render() { | ||
const { movies, error } = this.props; | ||
render() { | ||
const { movies, searchResults, error } = this.props; | ||
console.log(this.props.searchTerm); | ||
|
||
if (error) { | ||
return <div className='movieError'> {error}: Check Your Internet connection</div>; | ||
} | ||
if (error) { | ||
return <div className="movieError">{error}: Check Your Internet connection</div>; | ||
} | ||
|
||
return ( | ||
<div class='movie'> | ||
<h3>Popular 🔥</h3> | ||
<div className="movie-card-container"> | ||
{movies.length === 0 ? ( | ||
<div className='load'> | ||
<div className="loader "> | ||
<div className="ball"></div> | ||
<div className="ball"></div> | ||
<div className="ball"></div> | ||
</div> | ||
</div> | ||
) : ( | ||
movies.map((movie) => ( | ||
<Link to={`/movie-details/${movie.id}`} state={movie} className="movie-card-link" key={movie.id}> | ||
<div className="movie-card"> | ||
<img | ||
src={`https://image.tmdb.org/t/p/w500/${movie.poster_path}`} | ||
alt="img" | ||
className="movie-card__image" | ||
/> | ||
<div className="movie-card__details"> | ||
<h2 className="movie-card__title">{movie.title}</h2> | ||
<p className="movie-card__overview">{movie.overview}</p> | ||
</div> | ||
</div> | ||
</Link> | ||
)) | ||
)} | ||
</div> | ||
const displayMovies = searchResults.length > 0 ? searchResults : movies; | ||
|
||
</div> | ||
); | ||
} | ||
return ( | ||
<div className="movie"> | ||
|
||
<h2>Trending Movies</h2> | ||
|
||
<div className="movie-card-container"> | ||
{displayMovies.length === 0 ? ( | ||
<div className="load"> | ||
<div className="loader"> | ||
<div className="ball"></div> | ||
<div className="ball"></div> | ||
<div className="ball"></div> | ||
</div> | ||
</div> | ||
) : ( | ||
displayMovies.map((movie) => ( | ||
<Link | ||
to={`/movie-details/${movie.id}`} | ||
state={movie} | ||
className="movie-card-link" | ||
key={movie.id} | ||
> | ||
<div className="movie-card"> | ||
<img | ||
src={`https://image.tmdb.org/t/p/w500/${movie.poster_path}`} | ||
alt="img" | ||
className="movie-card__image" | ||
/> | ||
<div className="movie-card__details"> | ||
<h2 className="movie-card__title">{movie.title}</h2> | ||
<p className="movie-card__overview">{movie.overview}</p> | ||
</div> | ||
</div> | ||
</Link> | ||
)) | ||
)} | ||
</div> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
const mapStateToProps = (state) => ({ | ||
movies: state.movies, | ||
searchResults: state.searchResults, | ||
error: state.error, | ||
searchTerm: state.searchTerm | ||
}); | ||
const mapDispatchToProps = (dispatch) => ({ | ||
fetchMovies: () => dispatch(fetchMovies()), | ||
searchMovies: (searchTerm) => dispatch(searchMovies(searchTerm)), | ||
setSearchTerm: (searchTerm) => dispatch(setSearchTerm(searchTerm)), | ||
}); | ||
|
||
export default connect(mapStateToProps, { fetchMovies })(Movie); | ||
export default connect(mapStateToProps,mapDispatchToProps)(Movie); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import React from 'react' | ||
import { Link, useLocation } from "react-router-dom"; | ||
export default function RecommendationDetails() { | ||
const location = useLocation(); | ||
const propsData = location.state; | ||
console.log(propsData); | ||
return ( | ||
<div> | ||
{propsData && ( | ||
<div className="movie-details-container"> | ||
<div className="movie-details"> | ||
<div className="movie-details-content"> | ||
|
||
<p className="movie-details-title">{propsData.title}</p> | ||
<p className="movie-details-overview">{propsData.description}</p> | ||
<p className="movie-details-info"> | ||
<span className="movie-details-info-label">Release Year:</span> {propsData.releaseDate} <br/> | ||
<span className="movie-details-info-label">Recommended By:</span> {propsData.recommender} | ||
</p> | ||
|
||
</div> | ||
|
||
<div className="movie-details-image"> | ||
<img src={`${propsData.movieImage}`} alt="Movie Poster" /> | ||
|
||
</div> | ||
</div> | ||
</div> | ||
|
||
)} | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.