aboutsummaryrefslogtreecommitdiff
path: root/src/app/web-series/components/HomePageModules.jsx
blob: 90af2f8c3497f22d51c23ab565e45c9654fb9cea (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
import { POPULAR_SHOWS, TRENDING_SHOWS, TOP_SHOWS } from "./data-fetch";
import styles from "../styles/pages.module.css";
import Image from "next/image";
import Link from "next/link";
import PreFecthSeriesInfo from "./cacher";

const HomepageUtils = async (type) => {
	const fetchFunctions = {
		popular: POPULAR_SHOWS,
		trending: TRENDING_SHOWS,
		top: TOP_SHOWS,
	};

	const fetchData = fetchFunctions[type];

	if (fetchData) {
		return await fetchData();
	} else {
		return;
	}
};

const Pages = async ({ type: type }) => {
	const data = await HomepageUtils(type);
	PreFecthSeriesInfo(data);
	return (
		<main className={styles.main}>
			<h2>{type} series</h2>
			<section className={styles.SeriesContainer}>
				{data &&
					data.results.length > 0 &&
					data.results.map((item, index) => (
						<Link
							key={index}
							href={`/web-series/${item.id}`}
							style={{ textDecoration: "none", color: "white" }}
							title={item.name}
						>
							<section className={styles.SeriesEntry}>
								<Image
									src={`https://sup-proxy.zephex0-f6c.workers.dev/api-content?url=https://image.tmdb.org/t/p/original${item.poster_path}`}
									width={167}
									height={267}
									alt="Series Poster"
									priority
								/>
								<p>{item.name || "Not sure"}</p>
							</section>
						</Link>
					))}
			</section>
		</main>
	);
};

export default Pages;