|
@@ -2,28 +2,28 @@ import clsx from "clsx";
|
|
|
import Link from "next/link";
|
|
import Link from "next/link";
|
|
|
import { useRouter } from "next/router";
|
|
import { useRouter } from "next/router";
|
|
|
import { GetServerSideProps } from "next";
|
|
import { GetServerSideProps } from "next";
|
|
|
-import { ReactElement, useState } from "react";
|
|
|
|
|
|
|
+import { ReactElement, useEffect, useState } from "react";
|
|
|
|
|
|
|
|
import { get } from "../../../utils/http";
|
|
import { get } from "../../../utils/http";
|
|
|
-import useGet from "../../../utils/hooks/useGet";
|
|
|
|
|
|
|
+// import useGet from "../../../utils/hooks/useGet";
|
|
|
import Toc from "../../../components/novel/Toc";
|
|
import Toc from "../../../components/novel/Toc";
|
|
|
import Toolbar from "../../../components/novel/Toolbar";
|
|
import Toolbar from "../../../components/novel/Toolbar";
|
|
|
import Settings from "../../../components/novel/Settings";
|
|
import Settings from "../../../components/novel/Settings";
|
|
|
|
|
|
|
|
import type { NextPageWithLayout } from "../../_app";
|
|
import type { NextPageWithLayout } from "../../_app";
|
|
|
-import type { /* ChapterData, */ ChapterListData } from "../../../types/http";
|
|
|
|
|
|
|
+// import type { ChapterData } from "../../../types/http";
|
|
|
|
|
|
|
|
import styles from "../../../styles/chapter.module.scss";
|
|
import styles from "../../../styles/chapter.module.scss";
|
|
|
import useSWR from "swr";
|
|
import useSWR from "swr";
|
|
|
|
|
|
|
|
interface ChapterData {
|
|
interface ChapterData {
|
|
|
- chapter: "";
|
|
|
|
|
- content: "";
|
|
|
|
|
- errmsg: "ok";
|
|
|
|
|
- errno: 10000;
|
|
|
|
|
- next: "";
|
|
|
|
|
- pre: "";
|
|
|
|
|
- title: "";
|
|
|
|
|
|
|
+ chapter: string;
|
|
|
|
|
+ content: string;
|
|
|
|
|
+ errmsg: string;
|
|
|
|
|
+ errno: number;
|
|
|
|
|
+ next: string;
|
|
|
|
|
+ pre: string;
|
|
|
|
|
+ title: string;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const Chapter: NextPageWithLayout = () => {
|
|
const Chapter: NextPageWithLayout = () => {
|
|
@@ -39,23 +39,9 @@ const Chapter: NextPageWithLayout = () => {
|
|
|
|
|
|
|
|
const [open, setOpen] = useState(false);
|
|
const [open, setOpen] = useState(false);
|
|
|
const [menu, setMenu] = useState("");
|
|
const [menu, setMenu] = useState("");
|
|
|
- const [isSerif, setIsSerif] = useState(
|
|
|
|
|
- JSON.parse(
|
|
|
|
|
- typeof localStorage !== "undefined" &&
|
|
|
|
|
- localStorage.getItem("novelIsSerif")
|
|
|
|
|
- ? localStorage.getItem("novelIsSerif") || "false"
|
|
|
|
|
- : "false"
|
|
|
|
|
- ) as boolean
|
|
|
|
|
- );
|
|
|
|
|
|
|
+ const [isSerif, setIsSerif] = useState(false);
|
|
|
|
|
|
|
|
- const [fontSize, setFontSize] = useState(
|
|
|
|
|
- Number(
|
|
|
|
|
- typeof localStorage !== "undefined" &&
|
|
|
|
|
- localStorage.getItem("novelFontSize")
|
|
|
|
|
- ? localStorage.getItem("novelFontSize")
|
|
|
|
|
- : "3"
|
|
|
|
|
- )
|
|
|
|
|
- );
|
|
|
|
|
|
|
+ const [fontSize, setFontSize] = useState(3);
|
|
|
|
|
|
|
|
const handleOpenToolbar = () => {
|
|
const handleOpenToolbar = () => {
|
|
|
if (open) {
|
|
if (open) {
|
|
@@ -83,11 +69,25 @@ const Chapter: NextPageWithLayout = () => {
|
|
|
localStorage.setItem("novelIsSerif", JSON.stringify(isSerif));
|
|
localStorage.setItem("novelIsSerif", JSON.stringify(isSerif));
|
|
|
setIsSerif(isSerif);
|
|
setIsSerif(isSerif);
|
|
|
};
|
|
};
|
|
|
|
|
+
|
|
|
const handleSetFontSize = (size: number) => {
|
|
const handleSetFontSize = (size: number) => {
|
|
|
localStorage.setItem("novelFontSize", `${size}`);
|
|
localStorage.setItem("novelFontSize", `${size}`);
|
|
|
setFontSize(size);
|
|
setFontSize(size);
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
+ useEffect(() => {
|
|
|
|
|
+ if (typeof localStorage !== "undefined") {
|
|
|
|
|
+ const fs = localStorage.getItem("novelFontSize");
|
|
|
|
|
+ const isSerif = localStorage.getItem("novelIsSerif");
|
|
|
|
|
+ if (fs) {
|
|
|
|
|
+ setFontSize(Number(fs));
|
|
|
|
|
+ }
|
|
|
|
|
+ if (isSerif) {
|
|
|
|
|
+ setIsSerif(JSON.parse(isSerif));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }, []);
|
|
|
|
|
+
|
|
|
if (!chapterData) {
|
|
if (!chapterData) {
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
@@ -127,7 +127,7 @@ const Chapter: NextPageWithLayout = () => {
|
|
|
<main className={styles["chapter-main"]} onClick={handleOpenToolbar}>
|
|
<main className={styles["chapter-main"]} onClick={handleOpenToolbar}>
|
|
|
<div
|
|
<div
|
|
|
className={clsx(styles["chapter-page"], {
|
|
className={clsx(styles["chapter-page"], {
|
|
|
- [styles["serif"]]: isSerif,
|
|
|
|
|
|
|
+ ["font-serif"]: isSerif,
|
|
|
"text-sm": fontSize === 1,
|
|
"text-sm": fontSize === 1,
|
|
|
"text-base": fontSize === 2,
|
|
"text-base": fontSize === 2,
|
|
|
"text-lg": fontSize === 3,
|
|
"text-lg": fontSize === 3,
|