From 8a85f4eaf13bc288a4aad7adaf1e917561a6f752 Mon Sep 17 00:00:00 2001 From: Rajarshee Chatterjee Date: Sun, 7 Jan 2024 18:38:57 +0530 Subject: [PATCH] Add Setting to Jump to Last Read Chapter --- src/screens/novel/NovelScreen.js | 13 +++++++++++++ .../SettingsGeneralScreen/SettingsGeneralScreen.tsx | 13 +++++++++++++ strings/languages/en/strings.json | 3 ++- strings/types/index.ts | 1 + 4 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/screens/novel/NovelScreen.js b/src/screens/novel/NovelScreen.js index 266f92112..e6aaa7381 100644 --- a/src/screens/novel/NovelScreen.js +++ b/src/screens/novel/NovelScreen.js @@ -98,6 +98,7 @@ const Novel = ({ route, navigation }) => { useFabForContinueReading = false, defaultChapterSort = 'ORDER BY chapterId ASC', disableHapticFeedback = false, + jumpToLastReadChapter = false, } = useSettings(); const { @@ -651,6 +652,18 @@ const Novel = ({ route, navigation }) => { { + if (jumpToLastReadChapter) { + const lastReadChapterIdx = chapters.findIndex( + chapter => chapter.chapterId === lastReadChapter.chapterId, + ); + + flatlistRef.current.scrollToIndex({ + animated: true, + index: lastReadChapterIdx, + }); + } + }} ref={flatlistRef} estimatedItemSize={64} data={chapters} diff --git a/src/screens/settings/SettingsGeneralScreen/SettingsGeneralScreen.tsx b/src/screens/settings/SettingsGeneralScreen/SettingsGeneralScreen.tsx index 289edbac7..951a848f7 100644 --- a/src/screens/settings/SettingsGeneralScreen/SettingsGeneralScreen.tsx +++ b/src/screens/settings/SettingsGeneralScreen/SettingsGeneralScreen.tsx @@ -62,6 +62,7 @@ const GenralSettings: React.FC = ({ navigation }) => { refreshNovelMetadata = false, disableHapticFeedback = false, useLibraryFAB = false, + jumpToLastReadChapter = false, } = useSettings(); const { showLastUpdateTime = true } = useSelector( @@ -215,6 +216,18 @@ const GenralSettings: React.FC = ({ navigation }) => { onPress={defaultChapterSortModal.setTrue} theme={theme} /> + + dispatch( + setAppSettings('jumpToLastReadChapter', !jumpToLastReadChapter), + ) + } + theme={theme} + /> {getString( diff --git a/strings/languages/en/strings.json b/strings/languages/en/strings.json index f1d701293..39f1bdf4d 100644 --- a/strings/languages/en/strings.json +++ b/strings/languages/en/strings.json @@ -169,7 +169,8 @@ "epubLocation": "EPUB Location", "epubLocationDescription": "The place where you open and export your EPUB files.", "downloadNewChapters": "Download new chapters", - "disableHapticFeedback": "Disable haptic feedback" + "disableHapticFeedback": "Disable haptic feedback", + "jumpToLastReadChapter": "Jump to last read chapter in list" }, "readerSettings": { "title": "Reader", diff --git a/strings/types/index.ts b/strings/types/index.ts index 4586a7764..44f0f924f 100644 --- a/strings/types/index.ts +++ b/strings/types/index.ts @@ -137,6 +137,7 @@ export interface StringMap { 'moreScreen.settingsScreen.generalSettingsScreen.epubLocationDescription': 'string'; 'moreScreen.settingsScreen.generalSettingsScreen.downloadNewChapters': 'string'; 'moreScreen.settingsScreen.generalSettingsScreen.disableHapticFeedback': 'string'; + 'moreScreen.settingsScreen.generalSettingsScreen.jumpToLastReadChapter': 'string'; 'moreScreen.settingsScreen.readerSettings.title': 'string'; 'moreScreen.settingsScreen.readerSettings.readerTheme': 'string'; 'moreScreen.settingsScreen.readerSettings.preset': 'string';