feat: Enhance delete icon functionality and sidebar styling

- Added logic to handle bookmark deletion in the DeleteIcon component, checking if the current bookmark matches the recorded location before deletion.
- Updated the mapStateToProps in the DeleteIcon index file to include currentBook from the Redux store.
- Modified DeleteIconProps interface to include currentBook of type BookModel.
- Adjusted padding in the Sidebar component for better UI alignment.
- Updated sidebar CSS to refine height calculation for improved layout.
This commit is contained in:
troyeguo
2026-05-18 17:17:13 +08:00
parent 88e34fd082
commit 4e5fbda8b8
6 changed files with 29 additions and 3 deletions

View File

File diff suppressed because one or more lines are too long

View File

@@ -6,6 +6,7 @@ import toast from "react-hot-toast";
import DatabaseService from "../../utils/storage/databaseService";
import { ConfigService } from "../../assets/lib/kookit-extra-browser.min";
import ConfigUtil from "../../utils/file/configUtil";
import { book } from "../../store/reducers";
class DeleteIcon extends React.Component<DeleteIconProps, DeleteIconStates> {
constructor(props: DeleteIconProps) {
@@ -27,6 +28,28 @@ class DeleteIcon extends React.Component<DeleteIconProps, DeleteIconStates> {
return;
}
if (this.props.mode === "bookmarks") {
let bookLocation: {
text: string;
count: string;
chapterTitle: string;
chapterDocIndex: string;
chapterHref: string;
percentage: string;
cfi: string;
} = ConfigService.getObjectConfig(
this.props.currentBook.key,
"recordLocation",
{}
);
let bookmark = await DatabaseService.getRecord(
this.props.itemKey,
"bookmarks"
);
if (!bookmark) return;
console.log(bookmark, bookLocation);
if (bookLocation.percentage === bookmark.percentage) {
this.props.handleShowBookmark(false);
}
DatabaseService.deleteRecord(this.props.itemKey, "bookmarks").then(() => {
deleteFunc();
toast.success(this.props.t("Deletion successful"));

View File

@@ -10,6 +10,7 @@ import { withTranslation } from "react-i18next";
const mapStateToProps = (state: stateType) => {
return {
htmlBook: state.reader.htmlBook,
currentBook: state.book.currentBook,
};
};
const actionCreator = {

View File

@@ -1,8 +1,10 @@
import BookModel from "../../models/Book";
export interface DeleteIconProps {
mode: string;
index: number;
tagName: string;
itemKey: string;
currentBook: BookModel;
handleFetchNotes: () => void;
handleFetchBookmarks: () => void;
renderHighlighters: () => void;

View File

@@ -437,7 +437,7 @@ class Sidebar extends React.Component<SidebarProps, SidebarState> {
)}
</div>
{/* Stats button at the bottom */}
<div className="side-menu-about" style={{ paddingBottom: 12 }}>
<div className="side-menu-about" style={{ paddingBottom: 8 }}>
<div
className={"side-menu-selector"}
style={{ cursor: "pointer" }}

View File

@@ -14,7 +14,7 @@
position: relative;
top: 85px;
width: 210px;
height: calc(100% - 155px);
height: calc(100% - 145px);
overflow-x: hidden;
overflow-y: scroll;
}