Skip to content

Commit

Permalink
added auto focus chapter in list in manga reader
Browse files Browse the repository at this point in the history
  • Loading branch information
mienaiyami committed Nov 17, 2023
1 parent 6641a3c commit a8de941
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 23 deletions.
14 changes: 10 additions & 4 deletions src/renderer/Components/ReaderSideListItem.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useContext, memo, useEffect, useState } from "react";
import { AppContext } from "../App";
import { useAppSelector } from "../store/hooks";
// import { setContextMenu } from "../store/contextMenu";
// import { useAppDispatch } from "../store/hooks";

Expand All @@ -23,6 +24,8 @@ const ReaderSideListItem = memo(
current: boolean;
focused: boolean;
}) => {
const appSettings = useAppSelector((state) => state.appSettings);

const { openInReader, setContextMenuData, contextMenuData } = useContext(AppContext);
const [contextMenuFocused, setContextMenuFocused] = useState(false);
useEffect(() => {
Expand All @@ -40,16 +43,19 @@ const ReaderSideListItem = memo(
}`}
data-focused={focused}
ref={(node) => {
// todo, not working
if (node && focused) node.scrollIntoView({ block: "nearest" });
}}
>
<a
onClick={() => openInReader(link)}
title={name}
ref={(node) => {
if (current && node !== null) node.scrollIntoView({ block: "nearest" });
}}
ref={
appSettings.readerSettings.focusChapterInList
? (node) => {
if (current && node !== null) node.scrollIntoView({ block: "nearest" });
}
: undefined
}
data-url={link}
onContextMenu={(e) => {
const items = [
Expand Down
53 changes: 34 additions & 19 deletions src/renderer/Components/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1271,6 +1271,40 @@ const Settings = (): ReactElement => {
stuttering while scrolling.
</div>
</div>
<div className="toggleItem">
<InputCheckbox
// todo impl
checked={appSettings.readerSettings.focusChapterInList}
className="noBG"
onChange={(e) => {
dispatch(
setReaderSettings({
focusChapterInList: e.currentTarget.checked,
})
);
}}
labelAfter="Focus current chapter in side-list "
/>
<div className="desc">
Automatically focus/scroll to current chapter entry in side-list when
changing chapter. Can cause huge performance loss in case of epub with
large number (&gt; 500) of chapters.
</div>
</div>
<div className="toggleItem">
<InputCheckbox
checked={appSettings.epubReaderSettings.focusChapterInList}
className="noBG"
onChange={(e) => {
dispatch(
setEpubReaderSettings({
focusChapterInList: e.currentTarget.checked,
})
);
}}
labelAfter="EPUB: Focus current chapter in side-list "
/>
</div>
<div className="toggleItem">
<InputCheckbox
checked={appSettings.epubReaderSettings.loadOneChapter}
Expand Down Expand Up @@ -1307,25 +1341,6 @@ const Settings = (): ReactElement => {
zen mode.
</div>
</div>
<div className="toggleItem">
<InputCheckbox
checked={!appSettings.epubReaderSettings.focusChapterInList}
className="noBG"
onChange={(e) => {
dispatch(
setEpubReaderSettings({
focusChapterInList: !e.currentTarget.checked,
})
);
}}
labelAfter="EPUB: Focus current chapter in side-list "
/>
<div className="desc">
Automatically focus/scroll to current chapter entry in side-list when
changing chapter. Can cause huge performance loss in case of epub with
large number (&gt; 500) of chapters
</div>
</div>
<div className="toggleItem">
<InputCheckbox
checked={!HAValue}
Expand Down
2 changes: 2 additions & 0 deletions src/renderer/MainImports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ const settingSchema = z
customColorFilter: z.boolean(),
others: z.boolean(),
}),
focusChapterInList: z.boolean(),
hideSideList: z.boolean(),
}),
epubReaderSettings: z.object({
Expand Down Expand Up @@ -362,6 +363,7 @@ const settingSchema = z
customColorFilter: true,
others: false,
},
focusChapterInList: true,
hideSideList: false,
},
epubReaderSettings: {
Expand Down

0 comments on commit a8de941

Please sign in to comment.