Compare commits
No commits in common. "92ccb90a54dee52bd0de39f7782a3570210a628e" and "5dae8ce6c008e452664dd6f963da25a0de4fc10c" have entirely different histories.
92ccb90a54
...
5dae8ce6c0
3
movie-app/.gitignore → .gitignore
vendored
|
@ -1,5 +1,8 @@
|
|||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
||||
|
||||
# Ignore node_modules folder
|
||||
node_modules/
|
||||
|
||||
# dependencies
|
||||
/node_modules
|
||||
/.pnp
|
70
README.md
|
@ -0,0 +1,70 @@
|
|||
# Getting Started with Create React App
|
||||
|
||||
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
|
||||
|
||||
## Available Scripts
|
||||
|
||||
In the project directory, you can run:
|
||||
|
||||
### `npm start`
|
||||
|
||||
Runs the app in the development mode.\
|
||||
Open [http://localhost:3000](http://localhost:3000) to view it in your browser.
|
||||
|
||||
The page will reload when you make changes.\
|
||||
You may also see any lint errors in the console.
|
||||
|
||||
### `npm test`
|
||||
|
||||
Launches the test runner in the interactive watch mode.\
|
||||
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
|
||||
|
||||
### `npm run build`
|
||||
|
||||
Builds the app for production to the `build` folder.\
|
||||
It correctly bundles React in production mode and optimizes the build for the best performance.
|
||||
|
||||
The build is minified and the filenames include the hashes.\
|
||||
Your app is ready to be deployed!
|
||||
|
||||
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
|
||||
|
||||
### `npm run eject`
|
||||
|
||||
**Note: this is a one-way operation. Once you `eject`, you can't go back!**
|
||||
|
||||
If you aren't satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
|
||||
|
||||
Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you're on your own.
|
||||
|
||||
You don't have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn't feel obligated to use this feature. However we understand that this tool wouldn't be useful if you couldn't customize it when you are ready for it.
|
||||
|
||||
## Learn More
|
||||
|
||||
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
|
||||
|
||||
To learn React, check out the [React documentation](https://reactjs.org/).
|
||||
|
||||
### Code Splitting
|
||||
|
||||
This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting)
|
||||
|
||||
### Analyzing the Bundle Size
|
||||
|
||||
This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size)
|
||||
|
||||
### Making a Progressive Web App
|
||||
|
||||
This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app)
|
||||
|
||||
### Advanced Configuration
|
||||
|
||||
This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration)
|
||||
|
||||
### Deployment
|
||||
|
||||
This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment)
|
||||
|
||||
### `npm run build` fails to minify
|
||||
|
||||
This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify)
|
|
@ -1 +0,0 @@
|
|||
REACT_APP_ACCESS_TOKEN = eyJhbGciOiJIUzI1NiJ9.eyJhdWQiOiI1OTY5MGVmZDE0ZTM3NTIyNWM0NTMxZmNkY2VkMjkwMSIsIm5iZiI6MTczNTU1OTMwMS41NDksInN1YiI6IjY3NzI4ODg1OThmMmY4MmZjNDkyNmY3ZSIsInNjb3BlcyI6WyJhcGlfcmVhZCJdLCJ2ZXJzaW9uIjoxfQ.UzaJvuxHsMibgfMtuRWROSX2uGrNNP59LWap2ghYNUQ
|
|
@ -1,70 +0,0 @@
|
|||
# Getting Started with Create React App
|
||||
|
||||
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
|
||||
|
||||
## Available Scripts
|
||||
|
||||
In the project directory, you can run:
|
||||
|
||||
### `npm start`
|
||||
|
||||
Runs the app in the development mode.\
|
||||
Open [http://localhost:3000](http://localhost:3000) to view it in your browser.
|
||||
|
||||
The page will reload when you make changes.\
|
||||
You may also see any lint errors in the console.
|
||||
|
||||
### `npm test`
|
||||
|
||||
Launches the test runner in the interactive watch mode.\
|
||||
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
|
||||
|
||||
### `npm run build`
|
||||
|
||||
Builds the app for production to the `build` folder.\
|
||||
It correctly bundles React in production mode and optimizes the build for the best performance.
|
||||
|
||||
The build is minified and the filenames include the hashes.\
|
||||
Your app is ready to be deployed!
|
||||
|
||||
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
|
||||
|
||||
### `npm run eject`
|
||||
|
||||
**Note: this is a one-way operation. Once you `eject`, you can't go back!**
|
||||
|
||||
If you aren't satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
|
||||
|
||||
Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you're on your own.
|
||||
|
||||
You don't have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn't feel obligated to use this feature. However we understand that this tool wouldn't be useful if you couldn't customize it when you are ready for it.
|
||||
|
||||
## Learn More
|
||||
|
||||
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
|
||||
|
||||
To learn React, check out the [React documentation](https://reactjs.org/).
|
||||
|
||||
### Code Splitting
|
||||
|
||||
This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting)
|
||||
|
||||
### Analyzing the Bundle Size
|
||||
|
||||
This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size)
|
||||
|
||||
### Making a Progressive Web App
|
||||
|
||||
This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app)
|
||||
|
||||
### Advanced Configuration
|
||||
|
||||
This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration)
|
||||
|
||||
### Deployment
|
||||
|
||||
This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment)
|
||||
|
||||
### `npm run build` fails to minify
|
||||
|
||||
This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify)
|
|
@ -1,64 +0,0 @@
|
|||
// import React, { useState, useEffect } from "react";
|
||||
// import { useParams } from "react-router-dom"; // Hook to retrieve URL parameters
|
||||
// // import "./MovieDetailPage.css";
|
||||
// import SearchPage from "../components/SearchPage";
|
||||
|
||||
// const DetailPage = () => {
|
||||
// const [movieDetails, setMovieDetails] = useState(null);
|
||||
// const { id } = useParams(); // Get movie ID from URL parameters
|
||||
|
||||
// // Fetch movie details when the component is mounted
|
||||
// useEffect(() => {
|
||||
// const fetchMovieDetails = async () => {
|
||||
// const response = await fetch(
|
||||
// `https://api.themoviedb.org/3/movie/${id}?api_key=59690efd14e375225c4531fcdced2901`
|
||||
// );
|
||||
// const data = await response.json();
|
||||
// setMovieDetails(data);
|
||||
// };
|
||||
// fetchMovieDetails();
|
||||
// }, [id]); // Re-fetch if the ID changes
|
||||
|
||||
// if (movieDetails) {
|
||||
// return (
|
||||
// <div className="movie-detail-container">
|
||||
// <div className="movie-detail-card">
|
||||
// <img
|
||||
// src={`https://image.tmdb.org/t/p/w500/${movieDetails.poster_path}`}
|
||||
// alt={movieDetails.title}
|
||||
// className="movie-detail-poster"
|
||||
// />
|
||||
// <div className="movie-detail-info">
|
||||
// <h2>{movieDetails.title}</h2>
|
||||
// <p className="movie-detail-release-date">
|
||||
// <strong>Release Date:</strong> {movieDetails.release_date}
|
||||
// </p>
|
||||
// <p className="movie-detail-tagline">
|
||||
// <em>{movieDetails.tagline}</em>
|
||||
// </p>
|
||||
// <p className="movie-detail-overview">{movieDetails.overview}</p>
|
||||
// <p className="movie-detail-genres">
|
||||
// <strong>Genres:</strong>{" "}
|
||||
// {movieDetails.genres.map((genre) => genre.name).join(", ")}
|
||||
// </p>
|
||||
// <p className="movie-detail-runtime">
|
||||
// <strong>Runtime:</strong> {movieDetails.runtime} minutes
|
||||
// </p>
|
||||
// <a
|
||||
// href={movieDetails.homepage}
|
||||
// target="_blank"
|
||||
// rel="noopener noreferrer"
|
||||
// className="movie-detail-link"
|
||||
// >
|
||||
// Official Website
|
||||
// </a>
|
||||
// </div>
|
||||
// </div>
|
||||
// </div>
|
||||
// );
|
||||
// }
|
||||
|
||||
// return <p>Loading movie details...</p>;
|
||||
// };
|
||||
|
||||
// export default DetailPage;
|
|
@ -1,5 +0,0 @@
|
|||
// jest-dom adds custom jest matchers for asserting on DOM nodes.
|
||||
// allows you to do things like:
|
||||
// expect(element).toHaveTextContent(/react/i)
|
||||
// learn more: https://github.com/testing-library/jest-dom
|
||||
import '@testing-library/jest-dom';
|
|
@ -1,11 +0,0 @@
|
|||
/** @type {import('tailwindcss').Config} */
|
||||
module.exports = {
|
||||
content: [
|
||||
"./src/**/*.{html,js}",
|
||||
],
|
||||
theme: {
|
||||
extend: {},
|
||||
},
|
||||
plugins: [],
|
||||
}
|
||||
|
Before Width: | Height: | Size: 3.8 KiB After Width: | Height: | Size: 3.8 KiB |
Before Width: | Height: | Size: 5.2 KiB After Width: | Height: | Size: 5.2 KiB |
Before Width: | Height: | Size: 9.4 KiB After Width: | Height: | Size: 9.4 KiB |
|
@ -3,10 +3,7 @@ import AppRouter from "./routes";
|
|||
|
||||
function App() {
|
||||
return (
|
||||
<>
|
||||
|
||||
<AppRouter />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
Before Width: | Height: | Size: 49 KiB After Width: | Height: | Size: 49 KiB |
Before Width: | Height: | Size: 27 KiB After Width: | Height: | Size: 27 KiB |
Before Width: | Height: | Size: 20 KiB After Width: | Height: | Size: 20 KiB |
|
@ -20,7 +20,7 @@ html, body {
|
|||
align-items: center;
|
||||
height: 100vh;
|
||||
padding: 20px;
|
||||
overflow: hidden;
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -5,14 +5,14 @@ import "./SearchPage.css";
|
|||
const SearchPage = () => {
|
||||
const [movieDetails, setMovieDetails] = useState(null);
|
||||
const [searchResults, setSearchResults] = useState([]);
|
||||
const [trailerKey, setTrailerKey] = useState(null); // Store trailer key for embedding
|
||||
const [trailerKey, setTrailerKey] = useState(null);
|
||||
const location = useLocation();
|
||||
const navigate = useNavigate();
|
||||
const queryParams = new URLSearchParams(location.search);
|
||||
const query = queryParams.get("q");
|
||||
const movieId = queryParams.get("id");
|
||||
|
||||
// Fetch movie details including trailer video
|
||||
|
||||
useEffect(() => {
|
||||
if (movieId) {
|
||||
const fetchMovieDetails = async () => {
|
||||
|
@ -22,23 +22,22 @@ const SearchPage = () => {
|
|||
const movieData = await movieResponse.json();
|
||||
setMovieDetails(movieData);
|
||||
|
||||
// Fetch video details (trailer)
|
||||
const videoResponse = await fetch(
|
||||
`https://api.themoviedb.org/3/movie/${movieId}/videos?api_key=59690efd14e375225c4531fcdced2901`
|
||||
);
|
||||
const videoData = await videoResponse.json();
|
||||
const trailer = videoData.results.find(
|
||||
const videoData = await videoResponse?.json();
|
||||
const trailer = videoData?.results?.find(
|
||||
(video) => video.type === "Trailer"
|
||||
);
|
||||
if (trailer) {
|
||||
setTrailerKey(trailer.key);
|
||||
setTrailerKey(trailer?.key);
|
||||
}
|
||||
};
|
||||
fetchMovieDetails();
|
||||
}
|
||||
}, [movieId]);
|
||||
|
||||
// Fetch search results based on query
|
||||
|
||||
useEffect(() => {
|
||||
if (query) {
|
||||
const fetchSearchResults = async () => {
|
||||
|
@ -46,7 +45,7 @@ const SearchPage = () => {
|
|||
`https://api.themoviedb.org/3/search/movie?api_key=59690efd14e375225c4531fcdced2901&query=${query}`
|
||||
);
|
||||
const data = await response.json();
|
||||
setSearchResults(data.results);
|
||||
setSearchResults(data?.results);
|
||||
};
|
||||
fetchSearchResults();
|
||||
}
|
||||
|
@ -58,28 +57,28 @@ const SearchPage = () => {
|
|||
<div className="movie-detail-container">
|
||||
<div className="movie-detail-card">
|
||||
<img
|
||||
src={`https://image.tmdb.org/t/p/w500/${movieDetails.poster_path}`}
|
||||
alt={movieDetails.title}
|
||||
src={`https://image.tmdb.org/t/p/w500/${movieDetails?.poster_path}`}
|
||||
alt={movieDetails?.title}
|
||||
className="movie-detail-poster"
|
||||
/>
|
||||
<div className="movie-detail-info">
|
||||
<h2>{movieDetails.title}</h2>
|
||||
<h2>{movieDetails?.title}</h2>
|
||||
<p className="movie-detail-release-date">
|
||||
<strong>Release Date:</strong> {movieDetails.release_date}
|
||||
<strong>Release Date:</strong> {movieDetails?.release_date}
|
||||
</p>
|
||||
<p className="movie-detail-tagline">
|
||||
<em>{movieDetails.tagline}</em>
|
||||
<em>{movieDetails?.tagline}</em>
|
||||
</p>
|
||||
<p className="movie-detail-overview">{movieDetails.overview}</p>
|
||||
<p className="movie-detail-overview">{movieDetails?.overview}</p>
|
||||
<p className="movie-detail-genres">
|
||||
<strong>Genres:</strong>{" "}
|
||||
{movieDetails.genres.map((genre) => genre.name).join(", ")}
|
||||
</p>
|
||||
<p className="movie-detail-runtime">
|
||||
<strong>Runtime:</strong> {movieDetails.runtime} minutes
|
||||
<strong>Runtime:</strong> {movieDetails?.runtime} minutes
|
||||
</p>
|
||||
<a
|
||||
href={movieDetails.homepage}
|
||||
href={movieDetails?.homepage}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className="movie-detail-link"
|
||||
|
@ -108,7 +107,7 @@ const SearchPage = () => {
|
|||
}
|
||||
|
||||
|
||||
if (searchResults.length > 0) {
|
||||
if (searchResults?.length > 0) {
|
||||
return (
|
||||
<div>
|
||||
<h1>Search Results for "{query}"</h1>
|
||||
|
@ -117,14 +116,14 @@ const SearchPage = () => {
|
|||
<div
|
||||
key={movie.id}
|
||||
className="search-item"
|
||||
onClick={() => navigate(`/search?id=${movie.id}`)}
|
||||
onClick={() => navigate(`/search?id=${movie?.id}`)}
|
||||
>
|
||||
<img
|
||||
src={`https://image.tmdb.org/t/p/w500/${movie.poster_path}`}
|
||||
alt={movie.title}
|
||||
src={`https://image.tmdb.org/t/p/w500/${movie?.poster_path}`}
|
||||
alt={movie?.title}
|
||||
className="search-item-poster"
|
||||
/>
|
||||
<h3>{movie.title}</h3>
|
||||
<h3>{movie?.title}</h3>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
|
@ -1,4 +1,4 @@
|
|||
.header {
|
||||
header {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
width: 100%;
|
||||
|
@ -16,7 +16,7 @@
|
|||
margin: 0 auto;
|
||||
}
|
||||
|
||||
.logo {
|
||||
.header-container img {
|
||||
width: 100px;
|
||||
height: 50px;
|
||||
}
|
||||
|
@ -27,14 +27,14 @@
|
|||
margin-left: auto;
|
||||
}
|
||||
|
||||
.filter-select {
|
||||
select {
|
||||
padding: 8px;
|
||||
border-radius: 8px;
|
||||
border: 1px solid #ccc;
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
.filter-range {
|
||||
.filters input {
|
||||
padding: 8px;
|
||||
border-radius: 8px;
|
||||
border: 1px solid #ccc;
|
||||
|
@ -45,7 +45,7 @@
|
|||
position: relative;
|
||||
}
|
||||
|
||||
.search-input {
|
||||
.search-container input{
|
||||
padding: 8px 16px;
|
||||
border-radius: 8px;
|
||||
border: 1px solid #ccc;
|
||||
|
@ -53,7 +53,7 @@
|
|||
width: 300px;
|
||||
}
|
||||
|
||||
.suggestions-list {
|
||||
ul {
|
||||
position: absolute;
|
||||
top: 100%;
|
||||
left: 0;
|
||||
|
@ -69,12 +69,12 @@
|
|||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.suggestion-item {
|
||||
li {
|
||||
padding: 8px 16px;
|
||||
cursor: pointer;
|
||||
transition: background-color 0.2s ease;
|
||||
}
|
||||
|
||||
.suggestion-item:hover {
|
||||
li:hover {
|
||||
background-color: #f0f0f0;
|
||||
}
|
|
@ -3,14 +3,13 @@ import logo from "../assets/logo.png";
|
|||
import { useNavigate } from "react-router-dom";
|
||||
import "./Header.css";
|
||||
import Movie from "./Movie";
|
||||
import { Outlet} from "react-router-dom";
|
||||
|
||||
import { Outlet } from "react-router-dom";
|
||||
const Header = () => {
|
||||
const [searchTerm, setSearchTerm] = useState("");
|
||||
const [suggestions, setSuggestions] = useState([]);
|
||||
const [genre, setGenre] = useState("");
|
||||
const [year, setYear] = useState(""); // Year filter state
|
||||
const [rating, setRating] = useState([0, 10]); // Rating filter state
|
||||
const [year, setYear] = useState("");
|
||||
const [rating, setRating] = useState([0, 10]);
|
||||
const navigate = useNavigate();
|
||||
|
||||
useEffect(() => {
|
||||
|
@ -19,8 +18,8 @@ const Header = () => {
|
|||
const response = await fetch(
|
||||
`https://api.themoviedb.org/3/search/movie?api_key=59690efd14e375225c4531fcdced2901&query=${searchTerm}`
|
||||
);
|
||||
const data = await response.json();
|
||||
setSuggestions(data.results);
|
||||
const data = await response?.json();
|
||||
setSuggestions(data?.results);
|
||||
};
|
||||
fetchSuggestions();
|
||||
} else {
|
||||
|
@ -40,16 +39,13 @@ const Header = () => {
|
|||
|
||||
return (
|
||||
<>
|
||||
<div>
|
||||
<header className="header">
|
||||
<header >
|
||||
<div className="header-container">
|
||||
<div>
|
||||
<img src={logo} alt="logo" className="logo" />
|
||||
<img src={logo} alt="logo" />
|
||||
</div>
|
||||
|
||||
<div className="filters">
|
||||
<select
|
||||
className="filter-select"
|
||||
value={genre}
|
||||
onChange={(e) => setGenre(e.target.value)}
|
||||
>
|
||||
|
@ -60,7 +56,6 @@ const Header = () => {
|
|||
</select>
|
||||
|
||||
<select
|
||||
className="filter-select"
|
||||
value={year}
|
||||
onChange={(e) => setYear(e.target.value)}
|
||||
>
|
||||
|
@ -70,17 +65,22 @@ const Header = () => {
|
|||
<option value="2022">2022</option>
|
||||
</select>
|
||||
|
||||
<input
|
||||
type="range"
|
||||
min="0"
|
||||
max="10"
|
||||
step="0.1"
|
||||
value={rating[0]}
|
||||
onChange={(e) =>
|
||||
setRating([parseFloat(e.target.value), rating[1]])
|
||||
}
|
||||
className="filter-range"
|
||||
/>
|
||||
{rating.map((value, index) => (
|
||||
<input
|
||||
key={index}
|
||||
type="range"
|
||||
min="0"
|
||||
max="10"
|
||||
step="0.1"
|
||||
value={value}
|
||||
onChange={(e) => {
|
||||
const newRating = [...rating];
|
||||
newRating[index] = parseFloat(e.target.value);
|
||||
setRating(newRating);
|
||||
}}
|
||||
/>
|
||||
))}
|
||||
|
||||
<span>
|
||||
{rating[0]} - {rating[1]}
|
||||
</span>
|
||||
|
@ -91,18 +91,16 @@ const Header = () => {
|
|||
type="text"
|
||||
value={searchTerm}
|
||||
onChange={handleSearchChange}
|
||||
className="search-input"
|
||||
placeholder="Search for movies..."
|
||||
/>
|
||||
{suggestions.length > 0 && (
|
||||
<ul className="suggestions-list">
|
||||
{suggestions?.length > 0 && (
|
||||
<ul >
|
||||
{suggestions.map((movie) => (
|
||||
<li
|
||||
key={movie.id}
|
||||
className="suggestion-item"
|
||||
onClick={() => handleSuggestionClick(movie.id)}
|
||||
key={movie?.id}
|
||||
onClick={() => handleSuggestionClick(movie?.id)}
|
||||
>
|
||||
{movie.title}
|
||||
{movie?.title}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
|
@ -110,10 +108,8 @@ const Header = () => {
|
|||
</div>
|
||||
</div>
|
||||
</header>
|
||||
<Outlet/>
|
||||
<Outlet/>
|
||||
<Movie filters={{ genre, year, rating }} />
|
||||
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
};
|
|
@ -20,24 +20,20 @@
|
|||
transform: translateY(-5px);
|
||||
cursor:pointer;
|
||||
}
|
||||
.movie-poster {
|
||||
img {
|
||||
width: 100%;
|
||||
height: auto;
|
||||
border-bottom: 3px solid #181717;
|
||||
}
|
||||
|
||||
.movie-details {
|
||||
padding: 15px;
|
||||
}
|
||||
|
||||
.movie-title {
|
||||
h3 {
|
||||
font-size: 1.2rem;
|
||||
font-weight: bold;
|
||||
color: #bd3333;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.movie-overview {
|
||||
p {
|
||||
font-size: 1rem;
|
||||
color: #776565;
|
||||
text-align: justify;
|
||||
|
@ -51,7 +47,7 @@
|
|||
margin-top: 20px;
|
||||
}
|
||||
|
||||
.pagination-button {
|
||||
button{
|
||||
padding: 10px;
|
||||
margin: 0 10px;
|
||||
font-size: 16px;
|
||||
|
@ -62,7 +58,7 @@
|
|||
border-radius: 5px;
|
||||
}
|
||||
|
||||
.pagination-button:disabled {
|
||||
button:disabled {
|
||||
background-color: #ddd;
|
||||
cursor: not-allowed;
|
||||
}
|
|
@ -1,68 +1,66 @@
|
|||
import React, { useState, useEffect } from "react";
|
||||
import "./Movie.css";
|
||||
|
||||
function Movie({ filters }) {
|
||||
const [movieList, setMovieList] = useState([]);
|
||||
const [page, setPage] = useState(1);
|
||||
|
||||
|
||||
const getMovie = (pageNumber, filters) => {
|
||||
const { genre, year, rating } = filters;
|
||||
let url = `https://api.themoviedb.org/3/discover/movie?api_key=59690efd14e375225c4531fcdced2901&page=${pageNumber}`;
|
||||
|
||||
if (genre) url += `&with_genres=${genre}`;
|
||||
if (year) url += `&year=${year}`;
|
||||
if (rating[0] && rating[1])
|
||||
url += `&vote_average.gte=${rating[0]}&vote_average.lte=${rating[1]}`;
|
||||
|
||||
fetch(url)
|
||||
.then((res) => res.json())
|
||||
.then((json) => setMovieList(json.results));
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
getMovie(page, filters);
|
||||
}, [page, filters]);
|
||||
|
||||
const handleNextPage = () => {
|
||||
setPage((prevPage) => prevPage + 1);
|
||||
};
|
||||
|
||||
const handlePreviousPage = () => {
|
||||
if (page > 1) {
|
||||
setPage((prevPage) => prevPage - 1);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<><div className="movie-container">
|
||||
{movieList.map((movie) => (
|
||||
<div key={movie.id} className="movie-card">
|
||||
<img
|
||||
className="movie-poster"
|
||||
src={`https://image.tmdb.org/t/p/w500${movie.poster_path}`}
|
||||
alt={movie.title} />
|
||||
<div className="movie-details">
|
||||
<h3 className="movie-title">{movie.title}</h3>
|
||||
<p className="movie-overview">{movie.overview}</p>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
|
||||
<div className="pagination-controls">
|
||||
<button
|
||||
className="pagination-button"
|
||||
onClick={handlePreviousPage}
|
||||
disabled={page === 1}
|
||||
>
|
||||
Previous
|
||||
</button>
|
||||
<button className="pagination-button" onClick={handleNextPage}>
|
||||
Next
|
||||
</button>
|
||||
</div>
|
||||
</div></>
|
||||
);
|
||||
}
|
||||
|
||||
export default Movie;
|
||||
import React, { useState, useEffect } from "react";
|
||||
import "./Movie.css";
|
||||
|
||||
function Movie({ filters }) {
|
||||
const [movieList, setMovieList] = useState([]);
|
||||
const [page, setPage] = useState(1);
|
||||
|
||||
|
||||
const getMovie = (pageNumber, filters) => {
|
||||
const { genre, year, rating } = filters;
|
||||
let url = `https://api.themoviedb.org/3/discover/movie?api_key=59690efd14e375225c4531fcdced2901&page=${pageNumber}`;
|
||||
|
||||
if (genre) url += `&with_genres=${genre}`;
|
||||
if (year) url += `&year=${year}`;
|
||||
if (rating[0] && rating[1])
|
||||
url += `&vote_average.gte=${rating[0]}&vote_average.lte=${rating[1]}`;
|
||||
|
||||
fetch(url)
|
||||
.then((res) => res.json())
|
||||
.then((json) => setMovieList(json.results));
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
getMovie(page, filters);
|
||||
}, [page, filters]);
|
||||
|
||||
const handleNextPage = () => {
|
||||
setPage((prevPage) => prevPage + 1);
|
||||
};
|
||||
|
||||
const handlePreviousPage = () => {
|
||||
if (page > 1) {
|
||||
setPage((prevPage) => prevPage - 1);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="movie-container">
|
||||
{movieList.map((movie) => (
|
||||
<div key={movie?.id} className="movie-card">
|
||||
<img
|
||||
src={`https://image.tmdb.org/t/p/w500${movie?.poster_path}`}
|
||||
alt={movie?.title} />
|
||||
<div >
|
||||
<h3 >{movie?.title}</h3>
|
||||
<p >{movie?.overview}</p>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
|
||||
<div className="pagination-controls">
|
||||
<button
|
||||
onClick={handlePreviousPage}
|
||||
disabled={page === 1}
|
||||
>
|
||||
Previous
|
||||
</button>
|
||||
<button onClick={handleNextPage}>
|
||||
Next
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default Movie;
|
|
@ -2,7 +2,6 @@ import React from "react";
|
|||
import { BrowserRouter, Routes, Route } from "react-router-dom";
|
||||
import Header from "../pages/Header";
|
||||
import Movie from "../pages/Movie";
|
||||
import DetailPage from "../pages/DetailPage";
|
||||
import SearchPage from "../components/SearchPage";
|
||||
|
||||
|
1
src/setupTests.js
Normal file
|
@ -0,0 +1 @@
|
|||
import '@testing-library/jest-dom';
|