diff --git a/src/manage/qd/BookChapter.tsx b/src/manage/qd/BookChapter.tsx index 4306278..44759a8 100644 --- a/src/manage/qd/BookChapter.tsx +++ b/src/manage/qd/BookChapter.tsx @@ -6,7 +6,7 @@ import { useDb } from "../dbProvider"; import type { QdChapterInfo } from "../../types"; import type { Volume } from "../../qdtypes"; import { useBookInfo } from "./BookInfoProvider"; -import { get_new_volumes } from "../../utils/qd"; +import { ChapterShowMode, get_new_volumes } from "../../utils/qd"; import VolumesList from "./VolumesList"; import styles from './BookChapter.module.css'; import ChapterEditor from "./ChapterEditor"; @@ -79,8 +79,8 @@ export default function BookChapter() { } let vols: Volume[] = bookInfo.volumes; if (bookStatus.chapterLists) { - vols = get_new_volumes(bookStatus.chapterLists, bookInfo.volumes, !bookStatus.showSavedOnly); - } else if (bookStatus.showSavedOnly) { + vols = get_new_volumes(bookStatus.chapterLists, bookInfo.volumes, bookStatus.chapterShowMode); + } else if (bookStatus.chapterShowMode != ChapterShowMode.All) { vols = []; } return (<> @@ -90,8 +90,8 @@ export default function BookChapter() { }, 1); }}> - {bookStatus.showSavedOnly && listErr && 重试} />} - {bookStatus.showSavedOnly && !bookStatus.chapterLists && !listErr && } + {bookStatus.chapterShowMode != ChapterShowMode.All && listErr && 重试} />} + {bookStatus.chapterShowMode != ChapterShowMode.All && !bookStatus.chapterLists && !listErr && } {vols.length > 0 && } diff --git a/src/manage/qd/BookIndex.tsx b/src/manage/qd/BookIndex.tsx index 3e0e9e0..753914c 100644 --- a/src/manage/qd/BookIndex.tsx +++ b/src/manage/qd/BookIndex.tsx @@ -1,4 +1,4 @@ -import { Affix, Flex, Space, Tag, Typography, Switch, Skeleton, Result, Button } from "antd"; +import { Affix, Flex, Space, Tag, Typography, Skeleton, Result, Button } from "antd"; import { useBookInfo } from "./BookInfoProvider"; import styles from './BookIndex.module.css'; import { loadChapterListsIfNeeded, useBookContext, useBookStatus } from "./BookStatusProvider"; @@ -6,7 +6,8 @@ import VolumesList from "./VolumesList"; import { useEffect, useState } from "react"; import { useDb } from "../dbProvider"; import type { Volume } from "../../qdtypes"; -import { get_new_volumes } from "../../utils/qd"; +import { ChapterShowMode, get_new_volumes } from "../../utils/qd"; +import ShowMode from "./ShowMode"; const { Paragraph, Link } = Typography; @@ -18,8 +19,8 @@ export default function BookIndex() { const [bookStatus, setBookStatus] = useBookStatus(); const setItems = useBookContext(); const [err, setErr] = useState(null); - function setShowSavedOnly(showSavedOnly: boolean) { - setBookStatus({ ...bookStatus, showSavedOnly }); + function setChapterShowMode(chapterShowMode: ChapterShowMode) { + setBookStatus({ ...bookStatus, chapterShowMode }); } function handle() { if (err) { @@ -36,8 +37,8 @@ export default function BookIndex() { setItems([]); let vols: Volume[] = bookInfo.volumes; if (bookStatus.chapterLists) { - vols = get_new_volumes(bookStatus.chapterLists, bookInfo.volumes, !bookStatus.showSavedOnly); - } else if (bookStatus.showSavedOnly) { + vols = get_new_volumes(bookStatus.chapterLists, bookInfo.volumes, bookStatus.chapterShowMode); + } else if (bookStatus.chapterShowMode != ChapterShowMode.All) { vols = []; } return ( @@ -64,11 +65,11 @@ export default function BookIndex() { - + - {bookStatus.showSavedOnly && err && 重试} />} - {bookStatus.showSavedOnly && !bookStatus.chapterLists && !err && } + {bookStatus.chapterShowMode != ChapterShowMode.All && err && 重试} />} + {bookStatus.chapterShowMode != ChapterShowMode.All && !bookStatus.chapterLists && !err && } {vols.length > 0 && } ); diff --git a/src/manage/qd/BookStatusProvider.ts b/src/manage/qd/BookStatusProvider.ts index 072fbd8..38a301c 100644 --- a/src/manage/qd/BookStatusProvider.ts +++ b/src/manage/qd/BookStatusProvider.ts @@ -3,15 +3,16 @@ import { QdChapterSimpleInfo } from "../../types"; import { Db } from "../../db/interfaces"; import { useOutletContext } from "react-router"; import type { ItemType } from "antd/es/breadcrumb/Breadcrumb"; +import { ChapterShowMode } from "../../utils/qd"; export type BookStatus = { - showSavedOnly: boolean; + chapterShowMode: ChapterShowMode; chapterLists?: QdChapterSimpleInfo[]; } export function createBookStatus(): BookStatus { return { - showSavedOnly: false, + chapterShowMode: ChapterShowMode.All, } } diff --git a/src/manage/qd/ShowMode.tsx b/src/manage/qd/ShowMode.tsx new file mode 100644 index 0000000..06440b7 --- /dev/null +++ b/src/manage/qd/ShowMode.tsx @@ -0,0 +1,28 @@ +import { Select } from "antd"; +import { ChapterShowMode } from "../../utils/qd" + +const TEXTS = { + [ChapterShowMode.All]: "显示所有章节", + [ChapterShowMode.SavedOnly]: "仅显示已保存章节", + [ChapterShowMode.UnsavedOnly]: "仅显示未保存章节", +} + +export interface ShowModeProps { + mode: ChapterShowMode; + onChange: (mode: ChapterShowMode) => void; +} + +export default function ShowMode({ mode, onChange }: ShowModeProps) { + return ( +