Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] master from troyeguo:master #21

Merged
merged 1 commit into from
Jul 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions public/lib/kookit/kookit.min.js

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions src/assets/locales/cn/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,11 @@
"Export Notes": "导出笔记",
"Export Highlights": "导出高亮",
"Precache": "预缓存",
"Precaching": "预缓存中",
"Delete Precache": "删除预缓存",
"Precache Successfully": "预缓存成功",
"Precache failed": "预缓存失败",
"Precaching Successfully": "预缓存成功",
"Precaching failed": "预缓存失败",
"Nothing to precache": "无需预缓存",
"Auto precache books after import": "自动预缓存导入的图书",
"Precache books after import to increase opening speed, Koodo will generate a precache version of the original book and save it into your library": "预缓存图书以提升图书打开速度,Koodo会在导入图书之后,自动生成图书缓存并存入书库",
"More Actions": "更多操作",
Expand Down
6 changes: 4 additions & 2 deletions src/assets/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,11 @@
"Nothing to export": "Nothing to export",
"More Actions": "More Actions",
"Precache": "Precache",
"Precache Successfully": "Precache Successfully",
"Precache failed": "Precache failed",
"Precaching": "Precaching",
"Precaching Successfully": "Precaching Successfully",
"Precaching failed": "Precaching failed",
"Delete Precache": "Delete Precache",
"Nothing to precache": "Nothing to precache",
"Auto precache books after import": "Auto precache books after import",
"Precache books after import to increase opening speed, Koodo will generate a precache version of the original book and save it into your library": "Precache books after import to increase opening speed, Koodo will generate a precache version of the original book and save it into your library",
"Take effect in a while": "Take effect in a while",
Expand Down
6 changes: 4 additions & 2 deletions src/components/bookCardItem/component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,11 @@ class BookCardItem extends React.Component<BookCardProps, BookCardState> {
handleCancelLoveBook = () => {
AddFavorite.clear(this.props.book.key);
this.setState({ isFavorite: false });
if (Object.keys(AddFavorite.getAllFavorite()).length === 0) {
if (
Object.keys(AddFavorite.getAllFavorite()).length === 0 &&
this.props.mode === "favorite"
) {
this.props.history.push("/manager/empty");
document.title = "Koodo Reader";
}
toast.success(this.props.t("Cancel Successfully"));
};
Expand Down
2 changes: 2 additions & 0 deletions src/components/bookCardItem/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import { stateType } from "../../store";

const mapStateToProps = (state: stateType) => {
return {
mode: state.sidebar.mode,

isOpenActionDialog: state.book.isOpenActionDialog,
dragItem: state.book.dragItem,
currentBook: state.book.currentBook,
Expand Down
2 changes: 2 additions & 0 deletions src/components/bookCardItem/interface.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ export interface BookCardProps extends RouteComponentProps<any> {
isSelected: boolean;
dragItem: string;
selectedBooks: string[];
mode: string;

handleReadingBook: (book: BookModel) => void;
handleActionDialog: (isShowActionDialog: boolean) => void;
t: (title: string) => string;
Expand Down
6 changes: 6 additions & 0 deletions src/components/bookCoverItem/component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ class BookCoverItem extends React.Component<BookCoverProps, BookCoverState> {
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"));
};
//控制按钮的弹出
Expand Down
2 changes: 2 additions & 0 deletions src/components/bookCoverItem/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import { withTranslation } from "react-i18next";

const mapStateToProps = (state: stateType) => {
return {
mode: state.sidebar.mode,

isOpenActionDialog: state.book.isOpenActionDialog,
isCollapsed: state.sidebar.isCollapsed,
dragItem: state.book.dragItem,
Expand Down
2 changes: 2 additions & 0 deletions src/components/bookCoverItem/interface.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ export interface BookCoverProps extends RouteComponentProps<any> {
isOpenActionDialog: boolean;
isCollapsed: boolean;
dragItem: string;
mode: string;

isSelectBook: boolean;
isSelected: boolean;
selectedBooks: string[];
Expand Down
5 changes: 3 additions & 2 deletions src/components/dialogs/actionDialog/component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ class ActionDialog extends React.Component<
<div
className="action-dialog-edit"
onClick={() => {
toast(this.props.t("Precaching"));
BookUtil.fetchBook(
this.props.currentBook.key,
true,
Expand All @@ -353,9 +354,9 @@ class ActionDialog extends React.Component<
"cache-" + this.props.currentBook.key,
cache
);
toast.success(this.props.t("Precache Successfully"));
toast.success(this.props.t("Precaching Successfully"));
} else {
toast.error(this.props.t("Precache failed"));
toast.error(this.props.t("Precaching failed"));
}
});
}}
Expand Down
17 changes: 12 additions & 5 deletions src/components/popups/popupMenu/component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -237,11 +237,18 @@ class PopupMenu extends React.Component<PopupMenuProps, PopupMenuStates> {
let highlighters: any = this.props.notes;
if (!highlighters) return;
let highlightersByChapter = highlighters.filter((item: NoteModel) => {
return (
item.chapter ===
this.props.rendition.getChapterDoc()[this.props.chapterDocIndex]
.title && item.bookKey === this.props.currentBook.key
);
if (this.props.currentBook.format !== "PDF") {
return (
item.chapter ===
this.props.rendition.getChapterDoc()[this.props.chapterDocIndex]
.label && item.bookKey === this.props.currentBook.key
);
} else {
return (
item.chapterIndex === this.props.chapterDocIndex &&
item.bookKey === this.props.currentBook.key
);
}
});
let pageArea = document.getElementById("page-area");
if (!pageArea) return;
Expand Down
67 changes: 67 additions & 0 deletions src/components/selectBook/component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
exportHighlights,
exportNotes,
} from "../../utils/syncUtils/exportUtil";
import BookUtil from "../../utils/fileUtils/bookUtil";
class SelectBook extends React.Component<BookListProps, BookListState> {
constructor(props: BookListProps) {
super(props);
Expand Down Expand Up @@ -141,6 +142,72 @@ class SelectBook extends React.Component<BookListProps, BookListState> {
>
<Trans>Export Highlights</Trans>
</span>
<span
className="book-manage-title"
onClick={async () => {
if (
this.props.books.filter(
(item: BookModel) =>
this.props.selectedBooks.indexOf(item.key) > -1
).length > 0
) {
let selectedBooks = this.props.books.filter(
(item: BookModel) =>
this.props.selectedBooks.indexOf(item.key) > -1
);
if (selectedBooks.length === 0) {
toast(this.props.t("Nothing to precache"));
return;
}
for (let index = 0; index < selectedBooks.length; index++) {
const selectedBook = selectedBooks[index];
toast(this.props.t("Precaching"));
let result = await BookUtil.fetchBook(
selectedBook.key,
true,
selectedBook.path
);
let rendition = BookUtil.getRendtion(
result,
selectedBook.format,
"",
selectedBook.charset
);
let cache = await rendition.preCache(result);
if (cache !== "err") {
BookUtil.addBook("cache-" + selectedBook.key, cache);
toast.success(this.props.t("Precaching Successfully"));
} else {
toast.error(this.props.t("Precaching failed"));
}
}
} else {
toast(this.props.t("Nothing to precache"));
}
}}
>
<Trans>Precache</Trans>
</span>
<span
className="book-manage-title"
onClick={async () => {
let selectedBooks = this.props.books.filter(
(item: BookModel) =>
this.props.selectedBooks.indexOf(item.key) > -1
);
if (selectedBooks.length === 0) {
toast(this.props.t("Nothing to delete"));
return;
}
for (let index = 0; index < selectedBooks.length; index++) {
const selectedBook = selectedBooks[index];
await BookUtil.deleteBook("cache-" + selectedBook.key);
toast.success(this.props.t("Delete Successfully"));
}
}}
>
<Trans>Delete Precache</Trans>
</span>
<span
className="book-manage-title"
onClick={() => {
Expand Down
6 changes: 3 additions & 3 deletions src/containers/htmlViewer/component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ class Viewer extends React.Component<ViewerProps, ViewerState> {
await rendition.goToPosition(
JSON.stringify({
text: bookLocation.text || "",
chapterTitle: bookLocation.chapterTitle || chapterDocs[0].title,
chapterTitle: bookLocation.chapterTitle || chapterDocs[0].label,
page: bookLocation.page || "",
chapterDocIndex: bookLocation.chapterDocIndex || 0,
chapterHref: bookLocation.chapterHref || chapterDocs[0].href,
Expand All @@ -225,7 +225,7 @@ class Viewer extends React.Component<ViewerProps, ViewerState> {
let chapter =
bookLocation.chapterTitle ||
(this.props.htmlBook
? this.props.htmlBook.flattenChapters[0].title
? this.props.htmlBook.flattenChapters[0].label
: "Unknown Chapter");
let chapterDocIndex = 0;
if (bookLocation.chapterDocIndex) {
Expand All @@ -235,7 +235,7 @@ class Viewer extends React.Component<ViewerProps, ViewerState> {
bookLocation.chapterTitle && this.props.htmlBook
? window._.findLastIndex(
this.props.htmlBook.flattenChapters.map((item) => {
item.title = item.title.trim();
item.label = item.label.trim();
return item;
}),
{
Expand Down
4 changes: 2 additions & 2 deletions src/containers/lists/contentList/component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class ContentList extends React.Component<ContentListProps, ContentListState> {
let chapterIndex = window._.findIndex(this.props.htmlBook.flattenChapters, {
href,
});
let title = this.props.htmlBook.flattenChapters[chapterIndex].title;
let title = this.props.htmlBook.flattenChapters[chapterIndex].label;
let index = this.props.htmlBook.flattenChapters[chapterIndex].index;
await this.props.htmlBook.rendition.goToChapter(
index.toString(),
Expand Down Expand Up @@ -71,7 +71,7 @@ class ContentList extends React.Component<ContentListProps, ContentListState> {
onClick={this.handleJump}
className="book-content-name"
>
{item.title}
{item.label}
</a>
{item.subitems &&
item.subitems.length > 0 &&
Expand Down
2 changes: 1 addition & 1 deletion src/containers/panels/progressPanel/component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class ProgressPanel extends React.Component<
await this.props.htmlBook.rendition.goToChapter(
this.props.htmlBook.flattenChapters[chapterIndex].index.toString(),
this.props.htmlBook.flattenChapters[chapterIndex].href,
this.props.htmlBook.flattenChapters[chapterIndex].title
this.props.htmlBook.flattenChapters[chapterIndex].label
);
}
};
Expand Down
8 changes: 4 additions & 4 deletions src/model/HtmlBook.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
class HtmlBook {
key: string;
chapters: { title: string; id: string; href: string; index: number }[];
flattenChapters: { title: string; id: string; href: string; index: number }[];
chapters: { label: string; id: string; href: string; index: number }[];
flattenChapters: { label: string; id: string; href: string; index: number }[];
rendition: any;
constructor(
key: string,
chapters: { title: string; id: string; href: string; index: number }[],
chapters: { label: string; id: string; href: string; index: number }[],
flattenChapters: {
title: string;
label: string;
id: string;
href: string;
index: number;
Expand Down
4 changes: 2 additions & 2 deletions src/utils/readUtils/linkUtil.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const handleLinkJump = async (event: any, rendition: any = {}) => {
await rendition.goToChapter(
chapterInfo.index,
chapterInfo.href,
chapterInfo.title
chapterInfo.label
);
}

Expand All @@ -40,7 +40,7 @@ export const handleLinkJump = async (event: any, rendition: any = {}) => {
await rendition.goToChapter(
chapterInfo.index,
chapterInfo.href,
chapterInfo.title
chapterInfo.label
);
} else if (
href &&
Expand Down
3 changes: 2 additions & 1 deletion src/utils/readUtils/sortUtil.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ const getBookIndex = (nameArr: string[], oldNameArr: string[]) => {
let indexArr: number[] = [];
for (let i = 0; i < nameArr.length; i++) {
//如果索引数组已经包含该索引,就把它放在随后一位,取数组长度为索引
indexArr.push(oldNameArr.indexOf(nameArr[i]));
oldNameArr.indexOf(nameArr[i]) > -1 &&
indexArr.push(oldNameArr.indexOf(nameArr[i]));
}
if (indexArr.length < oldNameArr.length) {
oldNameArr.forEach((item) => {
Expand Down
Loading