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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
|
import axios from "axios";
import Head from "next/head";
import Image from "next/image";
import Link from "next/link";
import { useEffect, useState } from "react";
import Layout from "../../../components/layout";
// { `Don't touch this` }
// import { useUser } from "@auth0/nextjs-auth0/client";
// import {
// arrayRemove,
// arrayUnion,
// collection,
// doc,
// getDoc,
// getDocs,
// setDoc,
// updateDoc,
// } from "firebase/firestore";
// import db from "../../../lib/firebase";
const options = [
"mangadex",
"mangahere",
"mangakakalot",
"mangapark",
"mangapill",
"mangareader",
"mangasee123",
];
export default function MangaDetail({ data, manga, aniId, provider }) {
const [selectOption, setSelectedOption] = useState(options[0]);
const [recentWatch, setRecentWatch] = useState();
const [load, setLoad] = useState(true);
useEffect(() => {
function getRecent() {
const recentWatch = JSON.parse(localStorage.getItem("watchedManga"))?.map(
(data) => data.id
);
setRecentWatch(recentWatch);
}
getRecent();
}, []);
function handleLoad() {
setLoad(false);
}
const relation = data?.relations.filter(
(relation) => relation.malId !== null
);
const mangan = JSON.stringify(manga);
async function clickDeez(props) {
localStorage.setItem("chapters", mangan);
localStorage.setItem("currentChapterId", props);
}
return (
<>
<Head>
<title>{data.title?.english || data.title.romaji}</title>
<meta name="info" content="More detailed info about the Manga" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="icon" href="/c.svg" />
</Head>
<div className="w-screen">
<Layout>
<div className="flex w-screen justify-center pt-[10rem] ">
{data ? (
<div className="flex w-[85%] flex-col gap-10 ">
<div className="flex gap-10">
<div className="relative h-[358px] w-[230px]">
<Image
src={data.image}
alt="CoverImage"
fill
className="object-cover"
/>
</div>
<div className="flex w-[77%] flex-col gap-10">
<h1 className="font-karla text-3xl font-bold">
{data.title?.english}
</h1>
<p dangerouslySetInnerHTML={{ __html: data.description }} />
</div>
</div>
{relation?.length > 0 ? (
<div className="p-3 lg:p-0">
<h1 className="items-start py-5 text-2xl font-bold">
Relations
</h1>
<div
className={`grid grid-cols-1 justify-items-center py-5 px-5 lg:grid-cols-3 ${
load ? "h-[290px] overflow-y-clip" : ""
}`}
>
{relation &&
relation.map((relation, index) => {
return (
<div key={index} className="w-full gap-6 p-5 ">
<Link
href={
relation.type === "MANGA" ||
relation.type === "NOVEL"
? `/manga/detail/id?aniId=${relation.id}`
: `/anime/${relation.id}`
}
className={`flex w-full justify-between rounded-md bg-[#282828] p-2 shadow-lg duration-300 ease-out hover:scale-105 ${
relation.type === "TV" ||
relation.type === "OVA" ||
relation.type === "MOVIE" ||
relation.type === "SPECIAL" ||
relation.type === "ONA" ||
relation.type === "MANGA" ||
relation.type === "TV_SHORT"
? ``
: "pointer-events-none"
}`}
>
<div className="flex flex-col justify-between">
<div className="font-bold text-[#FF7F57]">
{relation.relationType}
</div>
<div className="text-lg font-bold text-white">
{relation.title.romaji ||
relation.title.english ||
relation.title.userPreferred}
</div>
<div className="flex">
<p className="dynamic-text rounded-lg p-1 font-outfit text-sm font-semibold">
{relation.type}
</p>
</div>
</div>
<div className="relative h-[200px] w-[140px] shrink-0">
<Image
fill
src={relation.image}
alt={`Cover Image for ${relation.title}`}
className=" bg-slate-400 object-cover"
/>
</div>
</Link>
</div>
);
})}
</div>
{relation.length > 3 && (
<button
type="button"
className="w-full"
onClick={handleLoad}
>
{load ? "Load More" : ""}
</button>
)}
</div>
) : (
<p>No Relations</p>
)}
<div className="flex flex-col gap-10">
<h1 className="text-3xl font-bold">Chapters</h1>
<div className="flex h-[640px] flex-col gap-10 overflow-y-scroll scrollbar-thin scrollbar-thumb-slate-800 scrollbar-thumb-rounded-full hover:scrollbar-thumb-slate-600">
{manga?.map((chapter, index) => {
return (
<div
key={index}
onClick={() => clickDeez(chapter.id)}
className={`${
recentWatch?.includes(chapter.id)
? "text-gray-400"
: ""
}`}
>
<Link
// href="#"
href={`/manga/chapter/[chapter]`}
as={`/manga/chapter/read?id=${chapter.id}&title=${
data.title?.english || data.title?.romaji
}&provider=${provider}&aniId=${aniId}`}
>
{typeof chapter.title === "string" &&
!isNaN(Number(chapter.title)) ? (
<div>Chapter {Number(chapter.title)}</div>
) : (
<div>
{chapter.chapter ? (
<p>Chapter {chapter.chapter}</p>
) : (
<p>{chapter.title}</p>
)}
</div>
)}
</Link>
</div>
);
})}
</div>
</div>
</div>
) : (
<p>Oops no data found :(</p>
)}
</div>
</Layout>
</div>
</>
);
}
export const getServerSideProps = async (context) => {
context.res.setHeader("Cache-Control", "public, max-age=3600");
const { aniId, aniTitle } = context.query;
const prv = "mangahere";
try {
const info = await axios.get(
`https://api.moopa.my.id/meta/anilist-manga/info/${aniId}?provider=${prv}`
);
const result = info.data;
const manga = result.chapters;
return {
props: {
data: result,
aniId: aniId,
provider: prv,
manga,
},
};
} catch (error) {
if (error.response && error.response.status === 404) {
try {
const prv = "mangakakalot";
const manga = await axios.get(
`https://api.moopa.my.id/meta/anilist-manga/info/${aniId}?provider=${prv}`
);
const results = manga.data;
return {
props: {
data: results,
aniId: aniId,
manga: results.chapters,
provider: prv,
},
};
} catch (error) {
console.error(error);
return {
notFound: true,
};
}
} else {
console.error(error);
return {
notFound: true,
};
}
}
};
|