From aa3d8627dcf261a7192df71980318f7ca8dcafeb Mon Sep 17 00:00:00 2001 From: orionduffy <45501204+orionduffy@users.noreply.github.com> Date: Mon, 23 Dec 2024 13:12:45 -0500 Subject: [PATCH 1/4] Fixed "Continue Reading" button The lastRead chapter object that the "Continue Reading" button uses for everything is now updated on entering and leaving the chapter, instead of never updating when information changes. --- src/screens/reader/hooks/useChapter.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/screens/reader/hooks/useChapter.ts b/src/screens/reader/hooks/useChapter.ts index e509a149a..c08eaf37f 100644 --- a/src/screens/reader/hooks/useChapter.ts +++ b/src/screens/reader/hooks/useChapter.ts @@ -1,4 +1,5 @@ import { + getChapter as getDbChapter, getNextChapter, getPrevChapter, markChapterRead, @@ -194,6 +195,17 @@ export default function useChapter(webViewRef: RefObject) { } }, [chapter]); + useEffect(() => { + if (!incognitoMode) { + getDbChapter(chapter.id).then(result => setLastRead(result)); + } + return () => { + if (!incognitoMode) { + getDbChapter(chapter.id).then(result => setLastRead(result)); + } + }; + }, []); + const refetch = () => { setLoading(true); setError(''); From 740e259f3932fe3ccf69f4314d57f98720c92d33 Mon Sep 17 00:00:00 2001 From: orionduffy <45501204+orionduffy@users.noreply.github.com> Date: Mon, 23 Dec 2024 13:41:24 -0500 Subject: [PATCH 2/4] Fixed bookmark button not saving state Done by passing the bookmark state down from the parent. --- src/screens/reader/ReaderScreen.tsx | 10 ++++++++-- src/screens/reader/components/ReaderAppbar.tsx | 12 +++++++++--- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/screens/reader/ReaderScreen.tsx b/src/screens/reader/ReaderScreen.tsx index 7eb7e0374..763104a03 100644 --- a/src/screens/reader/ReaderScreen.tsx +++ b/src/screens/reader/ReaderScreen.tsx @@ -1,4 +1,4 @@ -import React, { useRef, useCallback } from 'react'; +import React, { useRef, useCallback, useState } from 'react'; import { DrawerLayoutAndroid } from 'react-native'; import { useChapterGeneralSettings, useTheme } from '@hooks/persisted'; @@ -63,6 +63,7 @@ export const ChapterContent = ({ const readerSheetRef = useRef(null); const theme = useTheme(); const { pageReader = false, keepScreenOn } = useChapterGeneralSettings(); + const [bookmarked, setBookmarked] = useState(chapter.bookmark); const { hidden, @@ -146,7 +147,12 @@ export const ChapterContent = ({ {!hidden ? ( <> - + void; } -const ReaderAppbar = ({ goBack, theme }: ReaderAppbarProps) => { +const ReaderAppbar = ({ + goBack, + theme, + bookmarked, + setBookmarked, +}: ReaderAppbarProps) => { const { chapter, novel } = useChapterContext(); - const [bookmarked, setBookmarked] = useState(chapter.bookmark); + useEffect(() => { setBookmarked(chapter.bookmark); }, [chapter]); + return ( Date: Mon, 23 Dec 2024 13:47:29 -0500 Subject: [PATCH 3/4] Fixed bug caused by my own code More thorough testing revealed that lastRead did not update properly on chapter switch --- src/screens/reader/hooks/useChapter.ts | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/screens/reader/hooks/useChapter.ts b/src/screens/reader/hooks/useChapter.ts index c08eaf37f..3574102cd 100644 --- a/src/screens/reader/hooks/useChapter.ts +++ b/src/screens/reader/hooks/useChapter.ts @@ -189,22 +189,18 @@ export default function useChapter(webViewRef: RefObject) { useEffect(() => { setLoading(true); getChapter().finally(() => setLoading(false)); - if (!incognitoMode) { - insertHistory(chapter.id); - setLastRead(chapter); - } - }, [chapter]); - useEffect(() => { if (!incognitoMode) { + insertHistory(chapter.id); getDbChapter(chapter.id).then(result => setLastRead(result)); } + return () => { if (!incognitoMode) { getDbChapter(chapter.id).then(result => setLastRead(result)); } }; - }, []); + }, [chapter]); const refetch = () => { setLoading(true); From c5e50c4ce2899d649d7bbda5d8600f453c0e9435 Mon Sep 17 00:00:00 2001 From: orionduffy <45501204+orionduffy@users.noreply.github.com> Date: Mon, 23 Dec 2024 14:31:55 -0500 Subject: [PATCH 4/4] Fixed issue that rendered previous fix ineffective The original fix caused a new bug when changing chapters, and fixing that caused some of the old bugs to return. It should now be completely fixed. --- src/screens/reader/ReaderScreen.tsx | 6 +++++- src/screens/reader/components/ReaderAppbar.tsx | 6 +----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/screens/reader/ReaderScreen.tsx b/src/screens/reader/ReaderScreen.tsx index 763104a03..1418928e8 100644 --- a/src/screens/reader/ReaderScreen.tsx +++ b/src/screens/reader/ReaderScreen.tsx @@ -1,4 +1,4 @@ -import React, { useRef, useCallback, useState } from 'react'; +import React, { useRef, useCallback, useState, useEffect } from 'react'; import { DrawerLayoutAndroid } from 'react-native'; import { useChapterGeneralSettings, useTheme } from '@hooks/persisted'; @@ -65,6 +65,10 @@ export const ChapterContent = ({ const { pageReader = false, keepScreenOn } = useChapterGeneralSettings(); const [bookmarked, setBookmarked] = useState(chapter.bookmark); + useEffect(() => { + setBookmarked(chapter.bookmark); + }, [chapter]); + const { hidden, loading, diff --git a/src/screens/reader/components/ReaderAppbar.tsx b/src/screens/reader/components/ReaderAppbar.tsx index 01167311c..b3ecff2bd 100644 --- a/src/screens/reader/components/ReaderAppbar.tsx +++ b/src/screens/reader/components/ReaderAppbar.tsx @@ -1,4 +1,4 @@ -import React, { useEffect } from 'react'; +import React from 'react'; import { StatusBar, StyleSheet, View } from 'react-native'; import color from 'color'; @@ -22,10 +22,6 @@ const ReaderAppbar = ({ }: ReaderAppbarProps) => { const { chapter, novel } = useChapterContext(); - useEffect(() => { - setBookmarked(chapter.bookmark); - }, [chapter]); - return (