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

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

	return (
		<main className={styles.Main}>
			<h1>Trending 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"
									></Image>
									<p>{item.title}</p>
								</div>
							</div>
						</Link>
					))}
			</section>
		</main>
	);
}

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