-
-
Notifications
You must be signed in to change notification settings - Fork 21
/
App.jsx
114 lines (101 loc) · 3.52 KB
/
App.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import React, { useState, useEffect } from 'react';
import { createRoot } from 'react-dom/client';
function App() {
const [mostPopular, setMostPopular] = useState([]);
const [recommended, setRecommended] = useState([]);
const [awardWinning, setAwardWinning] = useState([]);
const [directorSpotlight, setDirectorSpotlight] = useState([]);
useEffect(() => {
const fetchMovies = async (category, setter) => {
const api_key = process.env.REACT_APP_API_KEY;
const url = `https://api.themoviedb.org/3/${category}?api_key=${api_key}&language=en-US&page=1`;
const response = await fetch(url);
const data = await response.json();
setter(data.results);
};
fetchMovies('movie/popular', setMostPopular);
fetchMovies('movie/top_rated', setRecommended);
fetchMovies('movie/now_playing', setAwardWinning);
fetchMovies('discover/movie', setDirectorSpotlight);
}, []);
const [currentPage, setCurrentPage] = useState(1);
const handleNextPage = () => {
setCurrentPage(currentPage + 1);
};
const handlePreviousPage = () => {
setCurrentPage(currentPage - 1);
};
return (
<main>
{/* Most Popular */}
<section id="most-popular">
<h2>Most Popular</h2>
<div className="movie-list">
{mostPopular.map(movie => (
<div key={movie.id} className="movie-card">
<img src={`https://image.tmdb.org/t/p/w500${movie.poster_path}`} alt={movie.title} />
<h3>{movie.title}</h3>
<p>{movie.overview}</p>
</div>
))}
</div>
</section>
{/* Recommended */}
<section id="recommended">
<h2>Recommended</h2>
<div className="movie-list">
{recommended.map(movie => (
<div key={movie.id} className="movie-card">
<img src={`https://image.tmdb.org/t/p/w500${movie.poster_path}`} alt={movie.title} />
<h3>{movie.title}</h3>
<p>{movie.overview}</p>
</div>
))}
</div>
</section>
{/* Award Winning */}
<section id="award-winning">
<h2>Award Winning</h2>
<div className="movie-list">
{awardWinning.map(movie => (
<div key={movie.id} className="movie-card">
<img src={`https://image.tmdb.org/t/p/w500${movie.poster_path}`} alt={movie.title} />
<h3>{movie.title}</h3>
<p>{movie.overview}</p>
</div>
))}
</div>
</section>
{/* Director Spotlight */}
<section id="director-spotlight">
<h2>Director Spotlight</h2>
<div className="movie-list">
{directorSpotlight.map(movie => (
<div key={movie.id} className="movie-card">
<img src={`https://image.tmdb.org/t/p/w500${movie.poster_path}`} alt={movie.title} />
<h3>{movie.title}</h3>
<p>{movie.overview}</p>
</div>
))}
</div>
</section>
{/* Pagination */}
<section id="pagination">
<div className="pagination-buttons">
<button onClick={handlePreviousPage}>Previous</button>
<button onClick={handleNextPage}>Next</button>
</div>
<div className="page-number">
<p>Page {currentPage}</p>
</div>
</section>
{/* Footer */}
<footer>
<p>© 2024 MovieVerse App</p>
</footer>
</main>
);
}
const container = document.getElementById('root');
const root = createRoot(container);
root.render(<App />);