Compare commits
No commits in common. "dev" and "main" have entirely different histories.
26
.gitignore
vendored
26
.gitignore
vendored
|
@ -1,26 +0,0 @@
|
|||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
||||
|
||||
# Ignore node_modules folder
|
||||
node_modules/
|
||||
|
||||
# dependencies
|
||||
/node_modules
|
||||
/.pnp
|
||||
.pnp.js
|
||||
|
||||
# testing
|
||||
/coverage
|
||||
|
||||
# production
|
||||
/build
|
||||
|
||||
# misc
|
||||
.DS_Store
|
||||
.env.local
|
||||
.env.development.local
|
||||
.env.test.local
|
||||
.env.production.local
|
||||
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
70
README.md
70
README.md
|
@ -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 +0,0 @@
|
|||
Subproject commit fe3832eb66ad224916aaf735cee785a1c6ca4b3c
|
17325
package-lock.json
generated
17325
package-lock.json
generated
File diff suppressed because it is too large
Load diff
40
package.json
40
package.json
|
@ -1,40 +0,0 @@
|
|||
{
|
||||
"name": "movie-app",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"cra-template": "1.2.0",
|
||||
"react": "^19.0.0",
|
||||
"react-dom": "^19.0.0",
|
||||
"react-router-dom": "^6.28.1",
|
||||
"react-scripts": "5.0.1"
|
||||
},
|
||||
"scripts": {
|
||||
"start": "react-scripts start",
|
||||
"build": "react-scripts build",
|
||||
"test": "react-scripts test",
|
||||
"eject": "react-scripts eject"
|
||||
},
|
||||
"eslintConfig": {
|
||||
"extends": [
|
||||
"react-app",
|
||||
"react-app/jest"
|
||||
]
|
||||
},
|
||||
"browserslist": {
|
||||
"production": [
|
||||
">0.2%",
|
||||
"not dead",
|
||||
"not op_mini all"
|
||||
],
|
||||
"development": [
|
||||
"last 1 chrome version",
|
||||
"last 1 firefox version",
|
||||
"last 1 safari version"
|
||||
]
|
||||
},
|
||||
"devDependencies": {
|
||||
"tailwindcss": "^3.4.17",
|
||||
"web-vitals": "^4.2.4"
|
||||
}
|
||||
}
|
Binary file not shown.
Before Width: | Height: | Size: 3.8 KiB |
|
@ -1,43 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<meta name="theme-color" content="#000000" />
|
||||
<meta
|
||||
name="description"
|
||||
content="Web site created using create-react-app"
|
||||
/>
|
||||
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
|
||||
<!--
|
||||
manifest.json provides metadata used when your web app is installed on a
|
||||
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
|
||||
-->
|
||||
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
|
||||
<!--
|
||||
Notice the use of %PUBLIC_URL% in the tags above.
|
||||
It will be replaced with the URL of the `public` folder during the build.
|
||||
Only files inside the `public` folder can be referenced from the HTML.
|
||||
|
||||
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
|
||||
work correctly both with client-side routing and a non-root public URL.
|
||||
Learn how to configure a non-root public URL by running `npm run build`.
|
||||
-->
|
||||
<title>React App</title>
|
||||
</head>
|
||||
<body>
|
||||
<noscript>You need to enable JavaScript to run this app.</noscript>
|
||||
<div id="root"></div>
|
||||
<!--
|
||||
This HTML file is a template.
|
||||
If you open it directly in the browser, you will see an empty page.
|
||||
|
||||
You can add webfonts, meta tags, or analytics to this file.
|
||||
The build step will place the bundled scripts into the <body> tag.
|
||||
|
||||
To begin the development, run `npm start` or `yarn start`.
|
||||
To create a production bundle, use `npm run build` or `yarn build`.
|
||||
-->
|
||||
</body>
|
||||
</html>
|
Binary file not shown.
Before Width: | Height: | Size: 5.2 KiB |
Binary file not shown.
Before Width: | Height: | Size: 9.4 KiB |
|
@ -1,25 +0,0 @@
|
|||
{
|
||||
"short_name": "React App",
|
||||
"name": "Create React App Sample",
|
||||
"icons": [
|
||||
{
|
||||
"src": "favicon.ico",
|
||||
"sizes": "64x64 32x32 24x24 16x16",
|
||||
"type": "image/x-icon"
|
||||
},
|
||||
{
|
||||
"src": "logo192.png",
|
||||
"type": "image/png",
|
||||
"sizes": "192x192"
|
||||
},
|
||||
{
|
||||
"src": "logo512.png",
|
||||
"type": "image/png",
|
||||
"sizes": "512x512"
|
||||
}
|
||||
],
|
||||
"start_url": ".",
|
||||
"display": "standalone",
|
||||
"theme_color": "#000000",
|
||||
"background_color": "#ffffff"
|
||||
}
|
|
@ -1,3 +0,0 @@
|
|||
# https://www.robotstxt.org/robotstxt.html
|
||||
User-agent: *
|
||||
Disallow:
|
14
src/App.js
14
src/App.js
|
@ -1,14 +0,0 @@
|
|||
import React from "react";
|
||||
import AppRouter from "./routes";
|
||||
|
||||
function App() {
|
||||
return (
|
||||
<AppRouter />
|
||||
);
|
||||
}
|
||||
|
||||
export default App;
|
||||
|
||||
|
||||
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
import { render, screen } from '@testing-library/react';
|
||||
import App from './App';
|
||||
|
||||
test('renders learn react link', () => {
|
||||
render(<App />);
|
||||
const linkElement = screen.getByText(/learn react/i);
|
||||
expect(linkElement).toBeInTheDocument();
|
||||
});
|
Binary file not shown.
Before Width: | Height: | Size: 49 KiB |
Binary file not shown.
Before Width: | Height: | Size: 27 KiB |
Binary file not shown.
Before Width: | Height: | Size: 20 KiB |
|
@ -1,190 +0,0 @@
|
|||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
background-color: #f4f4f4;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
line-height: 1.6;
|
||||
margin-top:50px;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
html, body {
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
|
||||
.movie-detail-container {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
height: 100vh;
|
||||
padding: 20px;
|
||||
|
||||
}
|
||||
|
||||
|
||||
.movie-detail-card {
|
||||
display: flex;
|
||||
background-color: #fff;
|
||||
border-radius: 12px;
|
||||
box-shadow: 0 6px 16px rgba(0, 0, 0, 0.1);
|
||||
overflow: hidden;
|
||||
max-width: 100%;
|
||||
max-height: 100%;
|
||||
flex-wrap: wrap;
|
||||
transition: transform 0.3s ease, box-shadow 0.3s ease;
|
||||
}
|
||||
|
||||
|
||||
.movie-detail-card:hover {
|
||||
transform: translateY(-5px);
|
||||
box-shadow: 0 8px 20px rgba(0, 0, 0, 0.15);
|
||||
}
|
||||
|
||||
|
||||
img {
|
||||
width: 40vw;
|
||||
height: auto;
|
||||
object-fit: cover;
|
||||
border-radius: 12px 0 0 12px;
|
||||
transition: transform 0.3s ease;
|
||||
}
|
||||
|
||||
img:hover {
|
||||
transform: scale(1.05);
|
||||
}
|
||||
|
||||
.movie-detail-info {
|
||||
padding: 30px;
|
||||
flex: 1;
|
||||
width: 60vw;
|
||||
overflow-y: auto;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.movie-detail-info h2 {
|
||||
font-size: 3em;
|
||||
font-weight: 700;
|
||||
margin-bottom: 15px;
|
||||
color: #333;
|
||||
line-height: 1.2;
|
||||
}
|
||||
|
||||
|
||||
.movie-detail-release-date,
|
||||
.movie-detail-runtime,
|
||||
.movie-detail-genres {
|
||||
margin: 10px 0;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.movie-detail-tagline {
|
||||
font-style: italic;
|
||||
color: #888;
|
||||
}
|
||||
|
||||
.movie-detail-overview {
|
||||
margin: 20px 0;
|
||||
line-height: 1.6;
|
||||
color: #444;
|
||||
}
|
||||
|
||||
.movie-detail-link {
|
||||
display: inline-block;
|
||||
margin-top: 25px;
|
||||
color: #007BFF;
|
||||
font-weight: bold;
|
||||
text-decoration: none;
|
||||
transition: color 0.3s ease;
|
||||
}
|
||||
|
||||
.movie-detail-link:hover {
|
||||
color: #0056b3;
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
|
||||
.movie-trailer {
|
||||
margin-top: 40px;
|
||||
}
|
||||
|
||||
.movie-trailer iframe {
|
||||
width: 100%;
|
||||
height: 500px;
|
||||
border-radius: 8px;
|
||||
border: none;
|
||||
}
|
||||
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.movie-detail-card {
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.movie-detail-poster {
|
||||
width: 100%;
|
||||
border-radius: 12px 12px 0 0;
|
||||
}
|
||||
|
||||
.movie-detail-info {
|
||||
width: 100%;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.movie-detail-info h2 {
|
||||
font-size: 2.5em;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 480px) {
|
||||
.movie-detail-info h2 {
|
||||
font-size: 2em;
|
||||
}
|
||||
|
||||
.movie-detail-release-date,
|
||||
.movie-detail-runtime,
|
||||
.movie-detail-genres {
|
||||
font-size: 0.9em;
|
||||
}
|
||||
|
||||
.movie-detail-overview {
|
||||
font-size: 0.9em;
|
||||
}
|
||||
|
||||
.movie-trailer iframe {
|
||||
height: 300px;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
.search-results {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
|
||||
gap: 20px;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.search-item {
|
||||
background-color: #fff;
|
||||
border-radius: 10px;
|
||||
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
|
||||
cursor: pointer;
|
||||
transition: transform 0.3s;
|
||||
}
|
||||
|
||||
.search-item:hover {
|
||||
transform: scale(1.05);
|
||||
}
|
||||
|
||||
.search-item img {
|
||||
width: 100%;
|
||||
border-radius: 10px 10px 0 0;
|
||||
}
|
||||
|
||||
.search-item h3 {
|
||||
padding: 15px;
|
||||
text-align: center;
|
||||
font-size: 1.1em;
|
||||
margin: 0;
|
||||
}
|
|
@ -1,136 +0,0 @@
|
|||
import React, { useState, useEffect } from "react";
|
||||
import { useLocation, useNavigate } from "react-router-dom";
|
||||
import "./SearchPage.css";
|
||||
|
||||
const SearchPage = () => {
|
||||
const [movieDetails, setMovieDetails] = useState(null);
|
||||
const [searchResults, setSearchResults] = useState([]);
|
||||
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");
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
if (movieId) {
|
||||
const fetchMovieDetails = async () => {
|
||||
const movieResponse = await fetch(
|
||||
`https://api.themoviedb.org/3/movie/${movieId}?api_key=59690efd14e375225c4531fcdced2901`
|
||||
);
|
||||
const movieData = await movieResponse.json();
|
||||
setMovieDetails(movieData);
|
||||
|
||||
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(
|
||||
(video) => video.type === "Trailer"
|
||||
);
|
||||
if (trailer) {
|
||||
setTrailerKey(trailer?.key);
|
||||
}
|
||||
};
|
||||
fetchMovieDetails();
|
||||
}
|
||||
}, [movieId]);
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
if (query) {
|
||||
const fetchSearchResults = async () => {
|
||||
const response = await fetch(
|
||||
`https://api.themoviedb.org/3/search/movie?api_key=59690efd14e375225c4531fcdced2901&query=${query}`
|
||||
);
|
||||
const data = await response.json();
|
||||
setSearchResults(data?.results);
|
||||
};
|
||||
fetchSearchResults();
|
||||
}
|
||||
}, [query]);
|
||||
|
||||
|
||||
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}
|
||||
/>
|
||||
<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>
|
||||
|
||||
|
||||
{trailerKey && (
|
||||
<div className="movie-trailer">
|
||||
<h3>Watch Trailer:</h3>
|
||||
<iframe
|
||||
title="movie-trailer"
|
||||
width="100%"
|
||||
height="400"
|
||||
src={`https://www.youtube.com/embed/${trailerKey}`}
|
||||
frameBorder="0"
|
||||
allowFullScreen
|
||||
></iframe>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
if (searchResults?.length > 0) {
|
||||
return (
|
||||
<div>
|
||||
<h1>Search Results for "{query}"</h1>
|
||||
<div className="search-results">
|
||||
{searchResults.map((movie) => (
|
||||
<div
|
||||
key={movie.id}
|
||||
className="search-item"
|
||||
onClick={() => navigate(`/search?id=${movie?.id}`)}
|
||||
>
|
||||
<img
|
||||
src={`https://image.tmdb.org/t/p/w500/${movie?.poster_path}`}
|
||||
alt={movie?.title}
|
||||
className="search-item-poster"
|
||||
/>
|
||||
<h3>{movie?.title}</h3>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return <p>No results found.</p>;
|
||||
};
|
||||
|
||||
export default SearchPage;
|
|
@ -1,19 +0,0 @@
|
|||
|
||||
|
||||
@import url('https://fonts.googleapis.com/css2?family=Nunito:wght@200..1000&family=Satisfy&display=swap');
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
font-family: "Nunito ", -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
|
||||
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
|
||||
sans-serif;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
background: rgb(253, 253, 253);
|
||||
}
|
||||
|
||||
code {
|
||||
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
|
||||
monospace;
|
||||
}
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
import React from "react";
|
||||
import ReactDOM from "react-dom/client";
|
||||
import "./index.css";
|
||||
import App from "./App";
|
||||
|
||||
const root = ReactDOM.createRoot(document.getElementById("root"));
|
||||
root.render(<App />);
|
|
@ -1,80 +0,0 @@
|
|||
header {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
width: 100%;
|
||||
height: 64px;
|
||||
background-color: rgba(55, 55, 55, 0.75);
|
||||
z-index: 10;
|
||||
}
|
||||
|
||||
.header-container {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
height: 100%;
|
||||
padding: 0 16px;
|
||||
max-width: 1200px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
.header-container img {
|
||||
width: 100px;
|
||||
height: 50px;
|
||||
}
|
||||
|
||||
.filters {
|
||||
display: flex;
|
||||
gap: 12px;
|
||||
margin-left: auto;
|
||||
}
|
||||
|
||||
select {
|
||||
padding: 8px;
|
||||
border-radius: 8px;
|
||||
border: 1px solid #ccc;
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
.filters input {
|
||||
padding: 8px;
|
||||
border-radius: 8px;
|
||||
border: 1px solid #ccc;
|
||||
}
|
||||
|
||||
.search-container {
|
||||
padding-left: 30px;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.search-container input{
|
||||
padding: 8px 16px;
|
||||
border-radius: 8px;
|
||||
border: 1px solid #ccc;
|
||||
font-size: 16px;
|
||||
width: 300px;
|
||||
}
|
||||
|
||||
ul {
|
||||
position: absolute;
|
||||
top: 100%;
|
||||
left: 0;
|
||||
right: 0;
|
||||
background-color: rgb(255, 253, 253);
|
||||
color: black;
|
||||
padding: 8px 0;
|
||||
margin-top: 4px;
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
|
||||
width: 100%;
|
||||
max-height: 300px;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
li {
|
||||
padding: 8px 16px;
|
||||
cursor: pointer;
|
||||
transition: background-color 0.2s ease;
|
||||
}
|
||||
|
||||
li:hover {
|
||||
background-color: #f0f0f0;
|
||||
}
|
|
@ -1,117 +0,0 @@
|
|||
import React, { useState, useEffect } from "react";
|
||||
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";
|
||||
const Header = () => {
|
||||
const [searchTerm, setSearchTerm] = useState("");
|
||||
const [suggestions, setSuggestions] = useState([]);
|
||||
const [genre, setGenre] = useState("");
|
||||
const [year, setYear] = useState("");
|
||||
const [rating, setRating] = useState([0, 10]);
|
||||
const navigate = useNavigate();
|
||||
|
||||
useEffect(() => {
|
||||
if (searchTerm) {
|
||||
const fetchSuggestions = async () => {
|
||||
const response = await fetch(
|
||||
`https://api.themoviedb.org/3/search/movie?api_key=59690efd14e375225c4531fcdced2901&query=${searchTerm}`
|
||||
);
|
||||
const data = await response?.json();
|
||||
setSuggestions(data?.results);
|
||||
};
|
||||
fetchSuggestions();
|
||||
} else {
|
||||
setSuggestions([]);
|
||||
}
|
||||
}, [searchTerm]);
|
||||
|
||||
const handleSearchChange = (e) => {
|
||||
setSearchTerm(e.target.value);
|
||||
};
|
||||
|
||||
const handleSuggestionClick = (id) => {
|
||||
navigate(`/search?id=${id}`);
|
||||
setSearchTerm("");
|
||||
setSuggestions([]);
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<header >
|
||||
<div className="header-container">
|
||||
<div>
|
||||
<img src={logo} alt="logo" />
|
||||
</div>
|
||||
<div className="filters">
|
||||
<select
|
||||
value={genre}
|
||||
onChange={(e) => setGenre(e.target.value)}
|
||||
>
|
||||
<option value="">Select Genre</option>
|
||||
<option value="28">Action</option>
|
||||
<option value="35">Comedy</option>
|
||||
<option value="18">Drama</option>
|
||||
</select>
|
||||
|
||||
<select
|
||||
value={year}
|
||||
onChange={(e) => setYear(e.target.value)}
|
||||
>
|
||||
<option value="">Select Year</option>
|
||||
<option value="2024">2024</option>
|
||||
<option value="2023">2023</option>
|
||||
<option value="2022">2022</option>
|
||||
</select>
|
||||
|
||||
{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>
|
||||
</div>
|
||||
|
||||
<div className="search-container">
|
||||
<input
|
||||
type="text"
|
||||
value={searchTerm}
|
||||
onChange={handleSearchChange}
|
||||
placeholder="Search for movies..."
|
||||
/>
|
||||
{suggestions?.length > 0 && (
|
||||
<ul >
|
||||
{suggestions.map((movie) => (
|
||||
<li
|
||||
key={movie?.id}
|
||||
onClick={() => handleSuggestionClick(movie?.id)}
|
||||
>
|
||||
{movie?.title}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
<Outlet/>
|
||||
<Movie filters={{ genre, year, rating }} />
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default Header;
|
|
@ -1,64 +0,0 @@
|
|||
.movie-container {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
justify-content: space-around;
|
||||
margin-top: 30px;
|
||||
|
||||
}
|
||||
|
||||
.movie-card {
|
||||
width: 300px;
|
||||
margin: 20px;
|
||||
background-color: #f8f8f8;
|
||||
border-radius: 10px;
|
||||
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
|
||||
overflow: hidden;
|
||||
|
||||
}
|
||||
|
||||
.movie-card:hover{
|
||||
transform: translateY(-5px);
|
||||
cursor:pointer;
|
||||
}
|
||||
img {
|
||||
width: 100%;
|
||||
height: auto;
|
||||
border-bottom: 3px solid #181717;
|
||||
}
|
||||
|
||||
h3 {
|
||||
font-size: 1.2rem;
|
||||
font-weight: bold;
|
||||
color: #bd3333;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
p {
|
||||
font-size: 1rem;
|
||||
color: #776565;
|
||||
text-align: justify;
|
||||
line-height: 1.5;
|
||||
max-height: 100px;
|
||||
overflow: hidden;
|
||||
}
|
||||
.pagination-controls {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
button{
|
||||
padding: 10px;
|
||||
margin: 0 10px;
|
||||
font-size: 16px;
|
||||
cursor: pointer;
|
||||
background-color: #007bff;
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 5px;
|
||||
}
|
||||
|
||||
button:disabled {
|
||||
background-color: #ddd;
|
||||
cursor: not-allowed;
|
||||
}
|
|
@ -1,66 +0,0 @@
|
|||
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;
|
|
@ -1,20 +0,0 @@
|
|||
import React from "react";
|
||||
import { BrowserRouter, Routes, Route } from "react-router-dom";
|
||||
import Header from "../pages/Header";
|
||||
import Movie from "../pages/Movie";
|
||||
import SearchPage from "../components/SearchPage";
|
||||
|
||||
|
||||
export default function AppRouter() {
|
||||
return (
|
||||
<BrowserRouter>
|
||||
<Routes>
|
||||
<Route path="/" element={<Header />}>
|
||||
<Route index element={<Movie />} />
|
||||
<Route path="/search" element={<SearchPage />} />
|
||||
|
||||
</Route>
|
||||
</Routes>
|
||||
</BrowserRouter>
|
||||
);
|
||||
}
|
|
@ -1 +0,0 @@
|
|||
import '@testing-library/jest-dom';
|
Loading…
Reference in a new issue