aboutsummaryrefslogtreecommitdiff
path: root/src/app/anime/page.jsx
blob: 14c579725c6fb2ddab2f256f629c33c83d26df2b (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
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
import { Card, CardHeader, CardBody, Link } from "@nextui-org/react";
import Image from "next/image";
import styles from "../page.module.css";

export const metadata = {
	title: "Dramalama Anime",
	description: "Anime page for Dramalama",
};

import { top_airing, recent, popular } from "./data-fetch/request";
import SearchBar from "./components/search";
import { preFetchAnimeInfo } from "./components/cacher";

const AnimeHomepage = async () => {
	const popular_data = await popular();
	const recent_data = await recent();
	const airing_data = await top_airing();

	const dataToBeLoaded = [popular_data, recent_data, airing_data];

	for (let item of dataToBeLoaded) {
		preFetchAnimeInfo(item);
	}

	const header = (title) => (
		<>
			<p className={`my-1 text-3xl font-bold text-sky-400 antialiased`}>
				{title}
			</p>
		</>
	);

	const format = (data) => (
		<>
			{data &&
				data.results.map((item, index) => (
					<Link
						key={index}
						href={`/anime/${item.id}`}
						aria-label="anime redirection links"
						className="flex flex-col items-center"
						title={item.title}
					>
						<Card
							className="overflow-visible bg-stone-800"
							isPressable
							isHoverable
							shadow="sm"
						>
							<CardBody>
								<Image
									alt="Anime Poster"
									src={`https://sup-proxy.zephex0-f6c.workers.dev/api-content?url=${item.image}`}
									width={270}
									height={170}
									className="h-64 overflow-hidden rounded-md w-auto"
									priority
								/>
							</CardBody>
							<CardHeader>
								<h4
									className={`w-44 overflow-hidden text-ellipsis whitespace-nowrap text-center text-small uppercase antialiased`}
								>
									{item.title}
								</h4>
							</CardHeader>
						</Card>
					</Link>
				))}
		</>
	);

	return (
		<section className="pt-4">
			<div className="mx-2">
				<SearchBar />
			</div>

			<div className="p-1">
				{header("Popular Animes")}
				<div
					className={`flex overflow-auto pb-3 2xl:grid 2xl:grid-cols-9 xl:grid xl:grid-cols-6 xl:overflow-none lg:grid lg:grid-cols-5 gap-2 ${styles.ScrollBarAdjuster}`}
				>
					{format(popular_data)}
				</div>
			</div>

			<div className="mx-2">
				{header("Recent Animes")}
				<div
					className={`flex overflow-auto pb-3 2xl:grid 2xl:grid-cols-9 xl:grid xl:grid-cols-6 xl:overflow-none lg:grid lg:grid-cols-5 gap-2 ${styles.ScrollBarAdjuster}`}
				>
					{format(recent_data)}
				</div>
			</div>
			<div className="mx-2">
				{header("Top Airing Animes")}
				<div
					className={`flex overflow-auto pb-3 2xl:grid 2xl:grid-cols-9 xl:grid xl:grid-cols-6 xl:overflow-none lg:grid lg:grid-cols-5 gap-2 ${styles.ScrollBarAdjuster}`}
				>
					{format(airing_data)}
				</div>
			</div>
			<br />
			<br />
		</section>
	);
};

export default AnimeHomepage;