Skip to content

Commit

Permalink
fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
troyeguo committed Sep 9, 2023
1 parent f05fe40 commit 5a619ba
Show file tree
Hide file tree
Showing 24 changed files with 154 additions and 123 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"request": "^2.88.2",
"webdav": "^3.6.2",
"webdav-fs": "^3.0.0",
"wink-lemmatizer": "^3.0.4",
"ws": "^8.13.0",
"zip-a-folder": "^0.0.12"
},
Expand Down
2 changes: 2 additions & 0 deletions src/assets/locales/cn/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@
"Ascend": "升序",
"Sort by Name": "按书名",
"Turn on Bionic Reading": "开启仿生阅读",
"Lemmatize words when looking up in a dictionary": "查询单词前将词性还原",
"To reduce the different forms of a word to one single form, for example, reducing builds, building or built to build, reducing cats to cat, reducing fastest to fast": "将不同变形的单词还原成单词原形,例如将builds, building 和 built 还原为 build,将cats还原为cat,fastest还原成fast",
"Export All Books": "导出所有图书",
"Export All Dictionary History": "导出所有查词历史",
"Export Dictionary History": "导出查词历史",
Expand Down
2 changes: 2 additions & 0 deletions src/assets/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@
"Light Mode": "Light Mode",
"Night Mode": "Night Mode",
"Turn on Bionic Reading": "Turn on Bionic Reading",
"Lemmatize words when looking up in a dictionary": "查询单词前将词性还原",
"To reduce the different forms of a word to one single form, for example, reducing builds, building or built to build, reducing cats to cat, reducing fastest to fast": "To reduce the different forms of a word to one single form, for example, reducing builds, building or built to build, reducing cats to cat, reducing fastest to fast",
"Export All Books": "Export All Books",
"Export All Notes": "Export All Notes",
"Export All Highlights": "Export All Highlights",
Expand Down
10 changes: 8 additions & 2 deletions src/components/bookListItem/component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ class BookListItem extends React.Component<BookItemProps, BookItemState> {
handleCancelLoveBook = () => {
AddFavorite.clear(this.props.book.key);
this.setState({ isFavorite: false });
if (
Object.keys(AddFavorite.getAllFavorite()).length === 0 &&
this.props.mode === "favorite"
) {
this.props.history.push("/manager/empty");
}
toast.success(this.props.t("Cancel Successfully"));
};
handleRestoreBook = () => {
Expand Down Expand Up @@ -212,8 +218,8 @@ class BookListItem extends React.Component<BookItemProps, BookItemState> {
className="icon-message book-selected-icon"
style={
this.props.isSelected
? { left: "35px", bottom: "5px" }
: { left: "35px", bottom: "5px", color: "#eee" }
? { left: "20px", bottom: "5px" }
: { left: "20px", bottom: "5px", color: "#eee" }
}
></span>
) : null}
Expand Down
2 changes: 1 addition & 1 deletion src/components/dialogs/aboutDialog/component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ class AboutDialog extends React.Component<AboutDialogProps, AboutDialogState> {
className="sort-by-category-list"
onClick={async () => {
let dictHistory =
(await window.localforage.getItem("dictHistory")) || [];
(await window.localforage.getItem("words")) || [];
if (dictHistory.length > 0) {
exportDictionaryHistory(dictHistory, [
...this.props.books,
Expand Down
12 changes: 8 additions & 4 deletions src/components/dialogs/actionDialog/component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ class ActionDialog extends React.Component<
>
<div
className="action-dialog-edit"
style={{ marginLeft: "-15px" }}
onClick={() => {
BookUtil.fetchBook(
this.props.currentBook.key,
Expand All @@ -283,6 +284,7 @@ class ActionDialog extends React.Component<
</div>
<div
className="action-dialog-edit"
style={{ marginLeft: "-15px" }}
onClick={() => {
if (
this.props.notes.filter(
Expand All @@ -309,6 +311,7 @@ class ActionDialog extends React.Component<
</div>
<div
className="action-dialog-edit"
style={{ marginLeft: "-15px" }}
onClick={() => {
if (
this.props.notes.filter(
Expand All @@ -335,14 +338,13 @@ class ActionDialog extends React.Component<
</div>
<div
className="action-dialog-edit"
style={{ marginLeft: "-15px" }}
onClick={async () => {
let dictHistory =
(await window.localforage.getItem("dictHistory")) || [];
(await window.localforage.getItem("words")) || [];
if (
dictHistory.filter(
(item) =>
item.bookKey === this.props.currentBook.key &&
item.notes === ""
(item) => item.bookKey === this.props.currentBook.key
).length > 0
) {
exportDictionaryHistory(dictHistory, [
Expand All @@ -361,6 +363,7 @@ class ActionDialog extends React.Component<
</div>
<div
className="action-dialog-edit"
style={{ marginLeft: "-15px" }}
onClick={() => {
if (this.props.currentBook.format === "PDF") {
toast(this.props.t("Not supported yet"));
Expand Down Expand Up @@ -397,6 +400,7 @@ class ActionDialog extends React.Component<
</div>
<div
className="action-dialog-edit"
style={{ marginLeft: "-15px" }}
onClick={async () => {
await BookUtil.deleteBook("cache-" + this.props.currentBook.key);
toast.success(this.props.t("Delete Successfully"));
Expand Down
16 changes: 12 additions & 4 deletions src/components/dialogs/detailDialog/component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ class DetailDialog extends React.Component<
paddingTop: "20",
paddingBottom: "20",
height: "430px",
overflow: "scroll",
}}
>
<div style={{ position: "relative" }}>
Expand Down Expand Up @@ -101,7 +100,10 @@ class DetailDialog extends React.Component<
</p>
</p>
</p>
<p className="detail-dialog-book-divider"></p>
<p
className="detail-dialog-book-divider"
style={{ backgroundColor: this.state.textColor }}
></p>
<p className="detail-dialog-book-size">
<p className="detail-sub-title">
<Trans>File size</Trans>
Expand All @@ -119,7 +121,10 @@ class DetailDialog extends React.Component<
</p>
</p>
</p>
<p className="detail-dialog-book-divider"></p>
<p
className="detail-dialog-book-divider"
style={{ backgroundColor: this.state.textColor }}
></p>
<p className="detail-dialog-book-added">
<p className="detail-sub-title">
<Trans>Added at</Trans>
Expand All @@ -132,7 +137,10 @@ class DetailDialog extends React.Component<
</p>
</p>
</p>
<p className="detail-dialog-book-divider"></p>
<p
className="detail-dialog-book-divider"
style={{ backgroundColor: this.state.textColor }}
></p>
<p className="detail-dialog-book-added">
<p className="detail-sub-title">
<Trans>Pages</Trans>
Expand Down
4 changes: 2 additions & 2 deletions src/components/dialogs/detailDialog/updateInfo.css
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
.detail-dialog-book-info {
overflow-y: scroll;
height: 185px;
line-height: 1.25;
text-align: left;
overflow-x: hidden;
width: 100%;
Expand Down Expand Up @@ -137,8 +138,7 @@
height: 60px;
width: 0.5px;
margin-top: 5px;
background-color: #aaa;
opacity: 0.5;
opacity: 0.2;
}
.detail-dialog-book-detail {
/* width: 80%; */
Expand Down
1 change: 1 addition & 0 deletions src/components/dialogs/settingDialog/component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class SettingDialog extends React.Component<
isAutoFullscreen:
StorageUtil.getReaderConfig("isAutoFullscreen") === "yes",
isPreventAdd: StorageUtil.getReaderConfig("isPreventAdd") === "yes",
isLemmatizeWord: StorageUtil.getReaderConfig("isLemmatizeWord") === "yes",
isOpenBook: StorageUtil.getReaderConfig("isOpenBook") === "yes",
isExpandContent: StorageUtil.getReaderConfig("isExpandContent") === "yes",
isDisablePopup: StorageUtil.getReaderConfig("isDisablePopup") === "yes",
Expand Down
1 change: 1 addition & 0 deletions src/components/dialogs/settingDialog/interface.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,6 @@ export interface SettingInfoState {
isAutoFullscreen: boolean;
isHideShelfBook: boolean;
isPreventAdd: boolean;
isLemmatizeWord: boolean;
currentThemeIndex: number;
}
4 changes: 2 additions & 2 deletions src/components/pdfWidget/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
width: 140px;
height: 40px;
border-radius: 20px;
background-color: #fcfcfc;
background-color: #8b8b8b;
z-index: 10;
display: flex;
justify-content: space-around;
Expand Down Expand Up @@ -40,7 +40,7 @@
.back-home-night,
.back-home-eye,
.back-home-dropdown {
color: #8b8b8b;
color: #fcfcfc;
}
.back-home-home:hover,
.back-home-day:hover,
Expand Down
38 changes: 15 additions & 23 deletions src/components/popups/popupDict/component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { getBingDict } from "../../../utils/serviceUtils/bingDictUtil";
import { openExternalUrl } from "../../../utils/serviceUtils/urlUtil";
import RecordLocation from "../../../utils/readUtils/recordLocation";
import DictHistory from "../../../model/DictHistory";

declare var window: any;
class PopupDict extends React.Component<PopupDictProps, PopupDictState> {
constructor(props: PopupDictProps) {
Expand All @@ -21,7 +22,15 @@ class PopupDict extends React.Component<PopupDictProps, PopupDictState> {
};
}
componentDidMount() {
let originalText = this.props.originalText.replace(/(\r\n|\n|\r)/gm, "");
let originalText = this.props.originalText
.replace(/(\r\n|\n|\r)/gm, "")
.replace(/-/gm, "");
if (StorageUtil.getReaderConfig("isLemmatizeWord") === "yes") {
var lemmatize = window.require("wink-lemmatizer");
originalText = lemmatize.verb(originalText);
originalText = lemmatize.noun(originalText);
originalText = lemmatize.adjective(originalText);
}
this.handleDict(originalText);
this.handleRecordHistory(originalText);
}
Expand All @@ -30,10 +39,9 @@ class PopupDict extends React.Component<PopupDictProps, PopupDictState> {
let bookLocation = RecordLocation.getHtmlLocation(bookKey);
let chapter = bookLocation.chapterTitle;
let word = new DictHistory(bookKey, text, chapter);
let dictHistoryArr =
(await window.localforage.getItem("dictHistory")) || [];
let dictHistoryArr = (await window.localforage.getItem("words")) || [];
dictHistoryArr.push(word);
window.localforage.setItem("dictHistory", dictHistoryArr);
window.localforage.setItem("words", dictHistoryArr);
};
handleDict = async (text: string) => {
if (StorageUtil.getReaderConfig("dictService") === "必应词典") {
Expand Down Expand Up @@ -94,8 +102,9 @@ class PopupDict extends React.Component<PopupDictProps, PopupDictState> {
var childElement = childElements[i];
if (
childElement.textContent &&
(childElement.textContent?.indexOf("synonyms") > -1 ||
childElement.textContent?.indexOf('"') > -1)
(childElement.textContent?.indexOf(":") > -1 ||
childElement.textContent?.indexOf('"') > -1 ||
childElement.textContent?.indexOf("「") > -1)
) {
childElement.parentNode &&
childElement.parentNode.removeChild(childElement);
Expand Down Expand Up @@ -142,23 +151,6 @@ class PopupDict extends React.Component<PopupDictProps, PopupDictState> {
});
}
};
handleYandexReturn = (list) => {
let typeList: string[] = [];
list.forEach((item) => {
if (typeList.indexOf(item.pos) === -1) {
typeList.push(item.pos);
}
});
return typeList.map((type) => {
return {
type,
definitions: list
.filter((item) => item.pos === type)
.map((item) => item.text)
.join(","),
};
});
};
render() {
const renderNoteEditor = () => {
return (
Expand Down
39 changes: 28 additions & 11 deletions src/components/popups/popupMenu/component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ class PopupMenu extends React.Component<PopupMenuProps, PopupMenuStates> {
}
);
}
if (nextProps.menuMode !== this.props.menuMode) {
this.showMenu(nextProps.menuMode);
}
}
handleRenderHighlight = () => {
new Promise<void>((resolve, reject) => {
Expand Down Expand Up @@ -107,24 +110,36 @@ class PopupMenu extends React.Component<PopupMenuProps, PopupMenuStates> {
});
};
handleNoteClick = (event: any) => {
let doc = getIframeDoc();
if (!doc) return;
let pageArea = document.getElementById("page-area");
if (!pageArea) return;
let iframe = pageArea.getElementsByTagName("iframe")[0];
if (!iframe || !iframe.contentWindow) return;
this.props.handleMenuMode("note");
let note = this.props.notes.filter(
(item) => item.key === event.currentTarget.dataset.key
)[0];
let temp = JSON.parse(note.range);
temp = [temp];
let doc = iframe.contentDocument;
if (!doc) return;
window.rangy.getSelection(iframe).restoreCharacterRanges(doc, temp);
let sel = doc.getSelection();
if (!sel) return;

let range = sel.getRangeAt(0);
sel.removeAllRanges();
sel.addRange(range);

this.setState({ rect: range.getBoundingClientRect() }, () => {
this.showMenu();
this.showMenu(this.props.menuMode);
this.handleClickHighlighter(event.currentTarget.dataset.key);
event.stopPropagation();
});
};
handlePDFClick = (event: any) => {
this.props.handleMenuMode("note");
this.setState({ rect: event.currentTarget.getBoundingClientRect() }, () => {
this.showMenu();
this.showMenu(this.props.menuMode);
this.handleClickHighlighter(event.currentTarget.getAttribute("key"));
event.stopPropagation();
});
Expand All @@ -143,19 +158,18 @@ class PopupMenu extends React.Component<PopupMenuProps, PopupMenuStates> {
handleShowDelete = (deleteKey: string) => {
this.setState({ deleteKey });
};
showMenu = () => {
showMenu = (menuMode: string) => {
let rect = this.state.rect;
if (!rect) return;
let { posX, posY } =
this.props.currentBook.format !== "PDF"
? this.getHtmlPosition(rect)
: this.getPdfPosition(rect);
? this.getHtmlPosition(rect, menuMode)
: this.getPdfPosition(rect, menuMode);
this.props.handleOpenMenu(true);
let popupMenu = document.querySelector(".popup-menu-container");
popupMenu?.setAttribute("style", `left:${posX}px;top:${posY}px`);
this.setState({ rect: null });
};
getPdfPosition(rect: any) {
getPdfPosition(rect: any, menuMode: string) {
let posY = rect.bottom;
let posX = rect.left + rect.width / 2;
document
Expand All @@ -173,9 +187,12 @@ class PopupMenu extends React.Component<PopupMenuProps, PopupMenuStates> {
posY = posY - rect.height - 188;
}
posX = posX - 80;
if (posX > doc.document.body.scrollWidth - 264 && menuMode !== "menu") {
posX = posX - (264 - 159);
}
return { posX, posY } as any;
}
getHtmlPosition(rect: any) {
getHtmlPosition(rect: any, menuMode: string) {
let posY = rect.bottom - this.props.rendition.getPageSize().scrollTop;
let posX = rect.left + rect.width / 2;
if (
Expand Down Expand Up @@ -288,7 +305,7 @@ class PopupMenu extends React.Component<PopupMenuProps, PopupMenuStates> {
this.props.handleNoteKey("");
return;
}
this.showMenu();
this.showMenu(this.props.menuMode);
this.props.handleMenuMode("menu");
};
//添加高亮
Expand Down
2 changes: 1 addition & 1 deletion src/components/popups/popupMenu/popupMenu.css
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
transform: rotate(180deg);
position: absolute;
bottom: 172px;
margin-left: 59px;
right: 60px;
font-size: 16px;
text-shadow: 0px 8px 8px rgba(0, 0, 0, 0.16);
z-index: 0;
Expand Down
Loading

0 comments on commit 5a619ba

Please sign in to comment.