aboutsummaryrefslogtreecommitdiff
path: root/pages/id/novel/read/index.tsx
blob: 5f36e54a321a05b52b69aecbd4169842fde67304 (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
111
112
113
114
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<IData>();

  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 (
    <>
      <Navbar withNav paddingY="py-2" scrollP={2} />
      <MobileNav hideProfile />
      <div className="w-screen flex flex-col items-center">
        {/* {data && ( */}
        <div className="flex items-center gap-5 w-full max-w-screen-lg px-5 mt-16 font-karla font-bold">
          <div className="flex gap-2">
            <Link
              href={`/id/novel/read/?id=${data?.navigation?.prev}`}
              className={`${
                data?.navigation?.prev ? "" : "pointer-events-none opacity-60"
              } py-1 px-2 bg-secondary rounded`}
            >
              prev
            </Link>
            <Link
              href={`/id/novel/read/?id=${data?.navigation?.next}`}
              className={`${
                data?.navigation?.next ? "" : "pointer-events-none opacity-60"
              } py-1 px-2 bg-secondary rounded`}
            >
              next
            </Link>
          </div>
          <span>/</span>
          <Link href={`/id/novel/${mangaId}`} className="text-lg line-clamp-1">
            {data?.novelTitle}
          </Link>
        </div>
        {/* )} */}
        <div className="block mt-5">
          <div className="px-5 w-full h-full max-w-screen-lg pointer-events-none select-none">
            <p className="text-xl font-bold my-5">{data?.title}</p>
            {data?.content && (
              <p
                dangerouslySetInnerHTML={{ __html: data?.content }}
                className="space-y-5"
              />
            )}
          </div>
        </div>
        {data?.content && (
          <div className="px-5 py-10 w-full h-full max-w-screen-lg">
            <div className="flex w-full gap-2">
              <Link
                href={`/id/novel/read/?id=${data?.navigation?.prev}`}
                className={`${
                  data?.navigation?.prev ? "" : "pointer-events-none opacity-60"
                } py-1 px-2 bg-secondary rounded`}
              >
                prev
              </Link>
              <Link
                href={`/id/novel/read/?id=${data?.navigation?.next}`}
                className={`${
                  data?.navigation?.next ? "" : "pointer-events-none opacity-60"
                } py-1 px-2 bg-secondary rounded`}
              >
                next
              </Link>
            </div>
          </div>
        )}
      </div>
    </>
  );
}