Skip to content

Commit

Permalink
Fixed last read not updating and bookmark button in reader mode. (#1368)
Browse files Browse the repository at this point in the history
* 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.

* Fixed bookmark button not saving state

Done by passing the bookmark state down from the parent.

* Fixed bug caused by my own code

More thorough testing revealed that lastRead did not update properly on chapter switch

* 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.

---------

Co-authored-by: orionduffy <[email protected]>
  • Loading branch information
jacksin125 and orionduffy authored Jan 13, 2025
1 parent c2c8935 commit 430a067
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 9 deletions.
14 changes: 12 additions & 2 deletions src/screens/reader/ReaderScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useRef, useCallback } from 'react';
import React, { useRef, useCallback, useState, useEffect } from 'react';
import { DrawerLayoutAndroid } from 'react-native';

import { useChapterGeneralSettings, useTheme } from '@hooks/persisted';
Expand Down Expand Up @@ -63,6 +63,11 @@ export const ChapterContent = ({
const readerSheetRef = useRef<BottomSheetModalMethods>(null);
const theme = useTheme();
const { pageReader = false, keepScreenOn } = useChapterGeneralSettings();
const [bookmarked, setBookmarked] = useState(chapter.bookmark);

useEffect(() => {
setBookmarked(chapter.bookmark);
}, [chapter]);

const {
hidden,
Expand Down Expand Up @@ -146,7 +151,12 @@ export const ChapterContent = ({
<ReaderBottomSheetV2 bottomSheetRef={readerSheetRef} />
{!hidden ? (
<>
<ReaderAppbar goBack={navigation.goBack} theme={theme} />
<ReaderAppbar
goBack={navigation.goBack}
theme={theme}
bookmarked={bookmarked}
setBookmarked={setBookmarked}
/>
<ReaderFooter
theme={theme}
nextChapter={nextChapter}
Expand Down
14 changes: 8 additions & 6 deletions src/screens/reader/components/ReaderAppbar.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useState } from 'react';
import React from 'react';
import { StatusBar, StyleSheet, View } from 'react-native';
import color from 'color';

Expand All @@ -14,12 +14,14 @@ interface ReaderAppbarProps {
goBack: () => 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 (
<Animated.View
entering={FadeIn.duration(150)}
Expand Down
10 changes: 9 additions & 1 deletion src/screens/reader/hooks/useChapter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
getChapter as getDbChapter,
getNextChapter,
getPrevChapter,
markChapterRead,
Expand Down Expand Up @@ -188,10 +189,17 @@ export default function useChapter(webViewRef: RefObject<WebView>) {
useEffect(() => {
setLoading(true);
getChapter().finally(() => setLoading(false));

if (!incognitoMode) {
insertHistory(chapter.id);
setLastRead(chapter);
getDbChapter(chapter.id).then(result => setLastRead(result));
}

return () => {
if (!incognitoMode) {
getDbChapter(chapter.id).then(result => setLastRead(result));
}
};
}, [chapter]);

const refetch = () => {
Expand Down

0 comments on commit 430a067

Please sign in to comment.