aboutsummaryrefslogtreecommitdiff
path: root/src/app/movies/components/popular.jsx
blob: 04d9cf86ec4eca5d0eb66d6984f6f2e082483fcd (plain) (blame)
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
import { POPULAR } from "../../../../utils/movie_urls";
import PreFetchMovieInfo from "./cacher";
import styles from "../styles/pop_trend.module.css";
import Image from "next/image";
import Link from "next/link";

export default async function POPULAR_MOVIES() {
	const data = await get_popular();
	PreFetchMovieInfo(data);

	return (
		<main className={styles.Main}>
			<h1>Popular Movies</h1>
			<section className={styles.MovieContainer}>
				{data &&
					data.results &&
					data.results.slice(0, 16).map((item, index) => (
						<Link
							href={`/movies/${item.id}`}
							style={{
								textDecoration: "none",
								color: "white",
							}}
							key={index}
						>
							<div
								style={{
									borderRadius: "0.5rem",
									overflow: "hidden",
									backgroundImage: `url(https://image.tmdb.org/t/p/original${item.backdrop_path})`,
									backgroundRepeat: "no-repeat",
									backgroundSize: "cover",
								}}
								className={styles.MovieEntryPrev}
							>
								<div className={styles.MovieEntry}>
									<Image
										src={`https://image.tmdb.org/t/p/original${item.poster_path}`}
										width={200}
										height={300}
										alt="Movie Poster"
										priority
									></Image>
									<p>{item.title}</p>
								</div>
							</div>
						</Link>
					))}
			</section>
		</main>
	);
}

const get_popular = async () => {
	const res = await fetch(POPULAR, { next: { revalidate: 21600 } });
	const data = await res.json();
	return data;
};