From 701798acaeb28f657bd1420d06253d350eb41b96 Mon Sep 17 00:00:00 2001 From: Factiven Date: Tue, 12 Sep 2023 21:45:30 +0700 Subject: initial v4 commit --- pages/en/manga/[id].js | 72 +++++++++++++++----------------------- pages/en/manga/read/[...params].js | 9 +++-- 2 files changed, 35 insertions(+), 46 deletions(-) (limited to 'pages/en/manga') diff --git a/pages/en/manga/[id].js b/pages/en/manga/[id].js index bb3cbc2..e928bd4 100644 --- a/pages/en/manga/[id].js +++ b/pages/en/manga/[id].js @@ -1,4 +1,3 @@ -import dotenv from "dotenv"; import ChapterSelector from "../../../components/manga/chapters"; import HamburgerMenu from "../../../components/manga/mobile/hamburgerMenu"; import Navbar from "../../../components/navbar"; @@ -11,7 +10,7 @@ import { getServerSession } from "next-auth"; import { authOptions } from "../../api/auth/[...nextauth]"; import getAnifyInfo from "../../../lib/anify/info"; -export default function Manga({ info, userManga, chapters }) { +export default function Manga({ info, userManga }) { const [domainUrl, setDomainUrl] = useState(""); const [firstEp, setFirstEp] = useState(); const chaptersData = info.chapters.data; @@ -45,6 +44,12 @@ export default function Manga({ info, userManga, chapters }) { info.title.romaji || info.title.english }&image=${info.bannerImage || info.coverImage}`} /> +
@@ -78,9 +83,8 @@ export default function Manga({ info, userManga, chapters }) { } export async function getServerSideProps(context) { - dotenv.config(); - const session = await getServerSession(context.req, context.res, authOptions); + const accessToken = session?.user?.token || null; const { id } = context.query; const key = process.env.API_KEY; @@ -93,55 +97,37 @@ export async function getServerSideProps(context) { method: "POST", headers: { "Content-Type": "application/json", + ...(accessToken && { Authorization: `Bearer ${accessToken}` }), }, body: JSON.stringify({ query: ` - query ($username: String, $status: MediaListStatus) { - MediaListCollection(userName: $username, type: MANGA, status: $status, sort: SCORE_DESC) { - user { - id - name - } - lists { - status - name - entries { - id - mediaId - status - progress - score - progressVolumes - media { - id - status - title { - english - romaji + query ($id: Int) { + Media (id: $id) { + mediaListEntry { + status + progress + progressVolumes + status + } + id + idMal + title { + romaji + english + native + } + } } - episodes - coverImage { - large - } - } - } - } - } - } `, variables: { - username: session?.user?.name, + id: parseInt(id), }, }), }); const data = await response.json(); - const user = data?.data?.MediaListCollection; - const userListsCurrent = user?.lists.find((X) => X.status === "CURRENT"); - const matched = userListsCurrent?.entries.find( - (x) => x.mediaId === parseInt(id) - ); - if (matched) { - userManga = matched; + const user = data?.data?.Media?.mediaListEntry; + if (user) { + userManga = user; } } diff --git a/pages/en/manga/read/[...params].js b/pages/en/manga/read/[...params].js index 301b646..faebcd6 100644 --- a/pages/en/manga/read/[...params].js +++ b/pages/en/manga/read/[...params].js @@ -1,4 +1,3 @@ -import dotenv from "dotenv"; import { useEffect, useRef, useState } from "react"; import { LeftBar } from "../../../../components/manga/leftBar"; import { useRouter } from "next/router"; @@ -115,6 +114,12 @@ export default function Read({ data, currentId, sessions }) { }` : "Getting Info..."} +
@@ -226,8 +231,6 @@ export default function Read({ data, currentId, sessions }) { } export async function getServerSideProps(context) { - dotenv.config(); - const cookies = nookies.get(context); const key = process.env.API_KEY; -- cgit v1.2.3