aboutsummaryrefslogtreecommitdiff
path: root/src/app/movies/components/popular.jsx
blob: 3ef050172c2272f04b930ff5b698206196ec3895 (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
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}>
			<h2>Popular Movies</h2>
			<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 className={styles.MovieEntryPrev}>
								<div className={styles.MovieEntry}>
									<Image
										src={`https://sup-proxy.zephex0-f6c.workers.dev/api-content?url=https://image.tmdb.org/t/p/original${item.poster_path}`}
										width={180}
										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;
};