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/[...id].tsx | 121 ++++++++++++++++++++++++++++++++++++++++++ pages/id/novel/read/index.tsx | 115 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 236 insertions(+) create mode 100644 pages/id/novel/[...id].tsx create mode 100644 pages/id/novel/read/index.tsx (limited to 'pages/id/novel') diff --git a/pages/id/novel/[...id].tsx b/pages/id/novel/[...id].tsx new file mode 100644 index 0000000..7e9e155 --- /dev/null +++ b/pages/id/novel/[...id].tsx @@ -0,0 +1,121 @@ +import axios from "axios"; +import Image from "next/image"; +import Link from "next/link"; +import { useEffect, useState } from "react"; +import { Navbar } from "../../../components/shared/NavBar"; +import MobileNav from "../../../components/shared/MobileNav"; +import { GetServerSideProps } from "next"; + +type InfoNovelProps = { + id: string; + API: string; +}; + +type NovelData = { + image?: string; + title?: string; + Release?: string; + Status?: string; + Author?: string; + description?: string; + chapters?: { + chapterId?: string; + chapter?: string; + release?: string; + }[]; + notFound?: boolean; +}; + +export default function InfoNovel({ id, API }: InfoNovelProps) { + const [data, setData] = useState(); + const [loading, setLoading] = useState(true); + + useEffect(() => { + async function fetchData() { + setLoading(true); + try { + const { data } = await axios.get(`${API}/api/novel/info/` + id); + setData(data); + } catch (error) { + setData({ + notFound: true, + }); + } finally { + setLoading(false); + } + } + fetchData(); + + return () => { + setData(undefined); + }; + }, [id]); + + return ( +
+ + +
+ {data && ( +
+ {data?.image && ( + coverImage + )} +
+

+ {data?.title} +

+
+

+ Release: {data?.Release} +

+

+ Status: {data?.Status} +

+

+ Author: {data?.Author} +

+
+

+ {data?.description} +

+
+
+ )} + +
+ {data?.chapters?.map((chapter) => ( + +
+

{chapter?.chapter}

+

{chapter?.release}

+
+ + ))} +
+
+
+
+ ); +} + +export const getServerSideProps: GetServerSideProps = async ({ params }) => { + const { id } = params || {}; + const API = process.env.ID_API; + return { + props: { + id, + API, + }, + }; +}; 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