mirror of
https://github.com/lifegpc/bookdownload.git
synced 2026-07-08 01:31:31 +08:00
修复性能问题
This commit is contained in:
@@ -3,7 +3,7 @@ import { useBookInfo } from "./BookInfoProvider";
|
|||||||
import styles from './BookIndex.module.css';
|
import styles from './BookIndex.module.css';
|
||||||
import { loadChapterListsIfNeeded, useBookContext, useBookStatus } from "./BookStatusProvider";
|
import { loadChapterListsIfNeeded, useBookContext, useBookStatus } from "./BookStatusProvider";
|
||||||
import VolumesList from "./VolumesList";
|
import VolumesList from "./VolumesList";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useMemo, useState } from "react";
|
||||||
import { useDb } from "../dbProvider";
|
import { useDb } from "../dbProvider";
|
||||||
import type { Volume } from "../../qdtypes";
|
import type { Volume } from "../../qdtypes";
|
||||||
import { ChapterShowMode, get_new_volumes } from "../../utils/qd";
|
import { ChapterShowMode, get_new_volumes } from "../../utils/qd";
|
||||||
@@ -53,13 +53,17 @@ export default function BookIndex() {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
handle();
|
handle();
|
||||||
}, [bookInfo.id]);
|
}, [bookInfo.id]);
|
||||||
setItems([]);
|
useEffect(() => {
|
||||||
let vols: Volume[] = bookInfo.volumes;
|
setItems([]);
|
||||||
if (bookStatus.chapterLists) {
|
}, [setItems]);
|
||||||
vols = get_new_volumes(bookStatus.chapterLists, bookInfo.volumes, bookStatus.chapterShowMode);
|
const vols = useMemo<Volume[]>(() => {
|
||||||
} else if (bookStatus.chapterShowMode != ChapterShowMode.All) {
|
if (bookStatus.chapterLists) {
|
||||||
vols = [];
|
return get_new_volumes(bookStatus.chapterLists, bookInfo.volumes, bookStatus.chapterShowMode);
|
||||||
}
|
} else if (bookStatus.chapterShowMode != ChapterShowMode.All) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
return bookInfo.volumes;
|
||||||
|
}, [bookStatus.chapterLists, bookInfo.volumes, bookStatus.chapterShowMode]);
|
||||||
return (
|
return (
|
||||||
<div className={styles.c}>
|
<div className={styles.c}>
|
||||||
<Flex justify="center" align="center">
|
<Flex justify="center" align="center">
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import { Link } from "react-router";
|
|||||||
import { CheckCircleOutlined } from "@ant-design/icons";
|
import { CheckCircleOutlined } from "@ant-design/icons";
|
||||||
import OpenInNewTab from "../../../node_modules/@material-icons/svg/svg/open_in_new/twotone.svg";
|
import OpenInNewTab from "../../../node_modules/@material-icons/svg/svg/open_in_new/twotone.svg";
|
||||||
import Icon from "../../components/Icon";
|
import Icon from "../../components/Icon";
|
||||||
import { useEffect, useMemo, useRef, useState } from "react";
|
import { memo, useEffect, useMemo, useRef, useState } from "react";
|
||||||
import LocationSearchingTwotone from "../../../node_modules/@material-icons/svg/svg/location_searching/twotone.svg";
|
import LocationSearchingTwotone from "../../../node_modules/@material-icons/svg/svg/location_searching/twotone.svg";
|
||||||
import { generateId } from "../../utils";
|
import { generateId } from "../../utils";
|
||||||
|
|
||||||
@@ -34,7 +34,7 @@ async function open_in_qidian(bookId: number, chapterId: number) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function VolumesList({ volumes, bookId, oneLine, current, loc, locTip, setLoc }: VolumesListProps) {
|
export default memo(function VolumesList({ volumes, bookId, oneLine, current, loc, locTip, setLoc }: VolumesListProps) {
|
||||||
const containerRef = useRef<HTMLDivElement>(null);
|
const containerRef = useRef<HTMLDivElement>(null);
|
||||||
const currentVolumeId = useMemo(() => {
|
const currentVolumeId = useMemo(() => {
|
||||||
if (!current) return null;
|
if (!current) return null;
|
||||||
@@ -137,4 +137,4 @@ export default function VolumesList({ volumes, bookId, oneLine, current, loc, lo
|
|||||||
/></div>
|
/></div>
|
||||||
{current && <Tooltip title="定位到当前章节" placement="left"><Icon cls={styles.current}><LocationSearchingTwotone fill="currentColor" onClick={scrollToCurrent} /></Icon></Tooltip>}
|
{current && <Tooltip title="定位到当前章节" placement="left"><Icon cls={styles.current}><LocationSearchingTwotone fill="currentColor" onClick={scrollToCurrent} /></Icon></Tooltip>}
|
||||||
</div>);
|
</div>);
|
||||||
}
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user