Pause on page changes + Fix ePub bug when reloading

This commit is contained in:
Richard Roberson 2025-03-23 17:18:21 -06:00
parent 1bbd77f93b
commit 7ba807fd95
3 changed files with 13 additions and 2 deletions

View file

@ -71,6 +71,8 @@ export function EPUBProvider({ children }: { children: ReactNode }) {
const tocRef = useRef<NavItem[]>([]);
const locationRef = useRef<string | number>(currDocPage);
const isEPUBSetOnce = useRef(false);
// Should pause ref
const shouldPauseRef = useRef(true);
/**
* Clears all current document state and stops any active TTS
@ -80,6 +82,11 @@ export function EPUBProvider({ children }: { children: ReactNode }) {
setCurrDocName(undefined);
setCurrDocText(undefined);
setCurrDocPages(undefined);
isEPUBSetOnce.current = false;
bookRef.current = null;
renditionRef.current = undefined;
locationRef.current = 1;
tocRef.current = [];
stop();
}, [setCurrDocPages, stop]);
@ -341,10 +348,12 @@ export function EPUBProvider({ children }: { children: ReactNode }) {
// Handle special 'next' and 'prev' cases
if (location === 'next' && renditionRef.current) {
shouldPauseRef.current = false;
renditionRef.current.next();
return;
}
if (location === 'prev' && renditionRef.current) {
shouldPauseRef.current = false;
renditionRef.current.prev();
return;
}
@ -359,7 +368,8 @@ export function EPUBProvider({ children }: { children: ReactNode }) {
locationRef.current = location;
if (bookRef.current && renditionRef.current) {
extractPageText(bookRef.current, renditionRef.current);
extractPageText(bookRef.current, renditionRef.current, shouldPauseRef.current);
shouldPauseRef.current = true;
}
}, [id, skipToLocation, extractPageText, setIsEPUB]);

View file

@ -134,7 +134,7 @@ export function PDFProvider({ children }: { children: ReactNode }) {
// This prevents unnecessary resets of the sentence index
if (text !== currDocText || text === '') {
setCurrDocText(text);
setTTSText(text);
setTTSText(text, true);
}
} catch (error) {
console.error('Error loading PDF text:', error);

View file

@ -222,6 +222,7 @@ export function TTSProvider({ children }: { children: ReactNode }) {
// Handle within current page bounds
if (nextIndex < sentences.length && nextIndex >= 0) {
console.log('isEPUB', isEPUB!);
setCurrentIndex(nextIndex);
return;
}