Skip to content

Commit 9c18a8c

Browse files
committed
refactor: remove unused code and improve function calls in various components
1 parent 2c05dc8 commit 9c18a8c

File tree

10 files changed

+37
-31
lines changed

10 files changed

+37
-31
lines changed

src/components/dialogs/convertDialog/component.tsx

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,6 @@ class ConvertDialog extends React.Component<
4949
this.state[item.propName] ? "no" : "yes"
5050
);
5151
BookUtil.reloadBooks();
52-
// ConfigService.setReaderConfig(
53-
// "isConvertPDF",
54-
// ConfigService.getReaderConfig("isConvertPDF") === "yes"
55-
// ? "no"
56-
// : "yes"
57-
// );
58-
// toast.success(
59-
// ConfigService.getReaderConfig("isConvertPDF") === "yes"
60-
// ? this.props.t("PDF to Text is enabled")
61-
// : this.props.t("PDF to Text is disabled")
62-
// );
63-
// BookUtil.reloadBooks();
6452
}}
6553
style={this.state[item.propName] ? {} : { opacity: 0.6 }}
6654
>

src/components/readerSettings/themeList/component.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ class ThemeList extends React.Component<ThemeListProps, ThemeListState> {
5050
ConfigService.setReaderConfig("textColor", "rgba(0,0,0,1)");
5151
}
5252
this.props.renderBookFunc();
53-
// BookUtil.reloadBooks();
5453
};
5554

5655
handleChooseBgColor = (color) => {
@@ -187,7 +186,7 @@ class ThemeList extends React.Component<ThemeListProps, ThemeListState> {
187186
ConfigService.setReaderConfig("backgroundColor", "");
188187
this.props.handleBackgroundColor("");
189188
toast.success(this.props.t("Removal successful"));
190-
BookUtil.reloadBooks();
189+
this.props.renderBookFunc();
191190
}}
192191
>
193192
<Trans>Clear</Trans>{" "}

src/containers/panels/operationPanel/component.tsx

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { OperationPanelProps, OperationPanelState } from "./interface";
77
import { ConfigService } from "../../../assets/lib/kookit-extra-browser.min";
88
import { withRouter } from "react-router-dom";
99
import toast from "react-hot-toast";
10-
import { HtmlMouseEvent } from "../../../utils/reader/mouseEvent";
1110
import TTSUtil from "../../../utils/reader/ttsUtil";
1211
import { isElectron } from "react-device-detect";
1312
import { handleExitFullScreen, handleFullScreen } from "../../../utils/common";
@@ -55,12 +54,6 @@ class OperationPanel extends React.Component<
5554
1000,
5655
});
5756
this.handleDisplayBookmark();
58-
// HtmlMouseEvent(
59-
// this.props.htmlBook.rendition,
60-
// this.props.currentBook.key,
61-
// this.props.readerMode,
62-
// this.props.currentBook.format
63-
// );
6457
});
6558
}
6659

src/containers/viewer/component.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import Background from "../../components/background";
77
import toast from "react-hot-toast";
88
import StyleUtil from "../../utils/reader/styleUtil";
99
import "./index.css";
10-
import { HtmlMouseEvent } from "../../utils/reader/mouseEvent";
10+
import { htmlMouseEvent } from "../../utils/reader/mouseEvent";
1111
import ImageViewer from "../../components/imageViewer";
1212
import { getIframeDoc } from "../../utils/reader/docUtil";
1313
import PopupBox from "../../components/popups/popupBox";
@@ -293,11 +293,13 @@ class Viewer extends React.Component<ViewerProps, ViewerState> {
293293
};
294294

295295
handleRest = async (rendition: any) => {
296-
HtmlMouseEvent(
296+
htmlMouseEvent(
297297
rendition,
298298
this.props.currentBook.key,
299299
this.props.readerMode,
300-
this.props.currentBook.format
300+
this.props.currentBook.format,
301+
this.props.handleScale,
302+
this.props.renderBookFunc
301303
);
302304
let chapters = rendition.getChapter();
303305
let chapterDocs = rendition.getChapterDoc();

src/containers/viewer/index.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
handleFetchPlugins,
1919
handleReaderMode,
2020
handleFetchAuthed,
21+
handleScale,
2122
} from "../../store/actions";
2223
import Viewer from "./component";
2324
import { stateType } from "../../store";
@@ -40,6 +41,7 @@ const mapStateToProps = (state: stateType) => {
4041
menuMode: state.viewArea.menuMode,
4142
scale: state.reader.scale,
4243
margin: state.reader.margin,
44+
renderBookFunc: state.book.renderBookFunc,
4345
};
4446
};
4547
const actionCreator = {
@@ -61,6 +63,7 @@ const actionCreator = {
6163
handleFetchPlugins,
6264
handleReaderMode,
6365
handleFetchAuthed,
66+
handleScale,
6467
};
6568
export default connect(
6669
mapStateToProps,

src/containers/viewer/interface.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ export interface ViewerProps {
4040
handleCurrentChapterIndex: (currentChapterIndex: number) => void;
4141
handlePercentage: (percentage: number) => void;
4242
handleFetchPercentage: (book: Book) => void;
43+
handleScale: (scale: string) => void;
44+
renderBookFunc: () => void;
4345
}
4446
export interface ViewerState {
4547
key: string;

src/pages/reader/component.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ class Reader extends React.Component<ReaderProps, ReaderState> {
302302
parseFloat(fieldVal) / 100 + ""
303303
);
304304
}
305-
BookUtil.reloadBooks();
305+
this.props.renderBookFunc();
306306
}}
307307
/>
308308
<span> %</span>
@@ -323,7 +323,8 @@ class Reader extends React.Component<ReaderProps, ReaderState> {
323323
this.setState({ scale: event.target.value });
324324
}}
325325
onMouseUp={() => {
326-
BookUtil.reloadBooks();
326+
this.props.handleScale(this.state.scale);
327+
this.props.renderBookFunc();
327328
}}
328329
style={{
329330
zIndex: 100,

src/pages/reader/index.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@ import {
99
handleOriginalText,
1010
handleOpenMenu,
1111
handleConvertDialog,
12+
handleScale,
1213
} from "../../store/actions";
1314
import { connect } from "react-redux";
1415
import { stateType } from "../../store";
1516
import Reader from "./component";
1617
import { withTranslation } from "react-i18next";
18+
import { render } from "react-dom";
1719

1820
const mapStateToProps = (state: stateType) => {
1921
return {
@@ -27,6 +29,7 @@ const mapStateToProps = (state: stateType) => {
2729
isAuthed: state.manager.isAuthed,
2830
isSearch: state.manager.isSearch,
2931
scale: state.reader.scale,
32+
renderBookFunc: state.book.renderBookFunc,
3033
};
3134
};
3235
const actionCreator = {
@@ -40,6 +43,7 @@ const actionCreator = {
4043
handleOriginalText,
4144
handleOpenMenu,
4245
handleConvertDialog,
46+
handleScale,
4347
};
4448
export default connect(
4549
mapStateToProps,

src/pages/reader/interface.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ export interface ReaderProps {
2222
handleFetchBookmarks: () => void;
2323
handleFetchPercentage: (currentBook: BookModel) => void;
2424
handleReadingBook: (book: BookModel) => void;
25+
handleScale: (scale: string) => void;
26+
renderBookFunc: () => void;
2527
}
2628

2729
export interface ReaderState {

src/utils/reader/mouseEvent.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,9 @@ export const bindHtmlEvent = (
137137
rendition: any,
138138
doc: any,
139139
key: string = "",
140-
readerMode: string = ""
140+
readerMode: string = "",
141+
handleScale: (scale: string) => void,
142+
renderBookFunc: () => void
141143
) => {
142144
doc.addEventListener(
143145
"keydown",
@@ -161,7 +163,8 @@ export const bindHtmlEvent = (
161163
} else {
162164
ConfigService.setReaderConfig("scale", scale - 0.1 + "");
163165
}
164-
BookUtil.reloadBooks();
166+
handleScale(ConfigService.getReaderConfig("scale") || "1");
167+
renderBookFunc();
165168
return;
166169
}
167170
if (lock) return;
@@ -228,11 +231,13 @@ export const bindHtmlEvent = (
228231
{ passive: false }
229232
);
230233
};
231-
export const HtmlMouseEvent = (
234+
export const htmlMouseEvent = (
232235
rendition: any,
233236
key: string,
234237
readerMode: string,
235-
format: string
238+
format: string,
239+
handleScale: (scale: string) => void,
240+
renderBookFunc: () => void
236241
) => {
237242
rendition.on("rendered", () => {
238243
let iframe = getIframeWin();
@@ -242,7 +247,14 @@ export const HtmlMouseEvent = (
242247
for (let i = 0; i < docs.length; i++) {
243248
let doc = docs[i];
244249
if (!doc) continue;
245-
bindHtmlEvent(rendition, doc, key, readerMode);
250+
bindHtmlEvent(
251+
rendition,
252+
doc,
253+
key,
254+
readerMode,
255+
handleScale,
256+
renderBookFunc
257+
);
246258
}
247259
lock = false;
248260
});

0 commit comments

Comments
 (0)