From 50a0f0240d7fef133eb5acc1bea2b1168b08e9db Mon Sep 17 00:00:00 2001 From: Factiven Date: Sun, 24 Dec 2023 13:03:54 +0700 Subject: migrate to typescript --- pages/id/novel/read/index.tsx | 115 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 pages/id/novel/read/index.tsx (limited to 'pages/id/novel/read') diff --git a/pages/id/novel/read/index.tsx b/pages/id/novel/read/index.tsx new file mode 100644 index 0000000..5f36e54 --- /dev/null +++ b/pages/id/novel/read/index.tsx @@ -0,0 +1,115 @@ +import Link from "next/link"; +import { useSearchParams } from "next/navigation"; +import { useEffect, useState } from "react"; +import { Navbar } from "@/components/shared/NavBar"; +import MobileNav from "@/components/shared/MobileNav"; +import pls from "@/utils/request/index"; + +interface IData { + novelTitle: string; + title: string; + navigation: { + next: string; + prev: string; + }; + content: string; +} + +export async function getServerSideProps() { + const API = process.env.ID_API; + return { + props: { + API, + }, + }; +} + +export default function ReadNovel({ API }: { API: string }) { + const [data, setData] = useState(); + + const searchParams = useSearchParams(); + const id = searchParams.get("id"); + const mangaId = id?.split("/")[0]; + + useEffect(() => { + async function fetchData() { + if (id) { + const data = await pls.get(`${API}/api/novel/chapter/${id}`); + setData(data); + } + } + fetchData(); + + return () => { + setData(undefined); + }; + }, [id]); + + return ( + <> + + +
+ {/* {data && ( */} +
+
+ + prev + + + next + +
+ / + + {data?.novelTitle} + +
+ {/* )} */} +
+
+

{data?.title}

+ {data?.content && ( +

+ )} +

+
+ {data?.content && ( +
+
+ + prev + + + next + +
+
+ )} +
+ + ); +} -- cgit v1.2.3