Pause on page changes + Fix ePub bug when reloading
This commit is contained in:
parent
1bbd77f93b
commit
7ba807fd95
3 changed files with 13 additions and 2 deletions
|
|
@ -71,6 +71,8 @@ export function EPUBProvider({ children }: { children: ReactNode }) {
|
||||||
const tocRef = useRef<NavItem[]>([]);
|
const tocRef = useRef<NavItem[]>([]);
|
||||||
const locationRef = useRef<string | number>(currDocPage);
|
const locationRef = useRef<string | number>(currDocPage);
|
||||||
const isEPUBSetOnce = useRef(false);
|
const isEPUBSetOnce = useRef(false);
|
||||||
|
// Should pause ref
|
||||||
|
const shouldPauseRef = useRef(true);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clears all current document state and stops any active TTS
|
* Clears all current document state and stops any active TTS
|
||||||
|
|
@ -80,6 +82,11 @@ export function EPUBProvider({ children }: { children: ReactNode }) {
|
||||||
setCurrDocName(undefined);
|
setCurrDocName(undefined);
|
||||||
setCurrDocText(undefined);
|
setCurrDocText(undefined);
|
||||||
setCurrDocPages(undefined);
|
setCurrDocPages(undefined);
|
||||||
|
isEPUBSetOnce.current = false;
|
||||||
|
bookRef.current = null;
|
||||||
|
renditionRef.current = undefined;
|
||||||
|
locationRef.current = 1;
|
||||||
|
tocRef.current = [];
|
||||||
stop();
|
stop();
|
||||||
}, [setCurrDocPages, stop]);
|
}, [setCurrDocPages, stop]);
|
||||||
|
|
||||||
|
|
@ -341,10 +348,12 @@ export function EPUBProvider({ children }: { children: ReactNode }) {
|
||||||
|
|
||||||
// Handle special 'next' and 'prev' cases
|
// Handle special 'next' and 'prev' cases
|
||||||
if (location === 'next' && renditionRef.current) {
|
if (location === 'next' && renditionRef.current) {
|
||||||
|
shouldPauseRef.current = false;
|
||||||
renditionRef.current.next();
|
renditionRef.current.next();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (location === 'prev' && renditionRef.current) {
|
if (location === 'prev' && renditionRef.current) {
|
||||||
|
shouldPauseRef.current = false;
|
||||||
renditionRef.current.prev();
|
renditionRef.current.prev();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -359,7 +368,8 @@ export function EPUBProvider({ children }: { children: ReactNode }) {
|
||||||
|
|
||||||
locationRef.current = location;
|
locationRef.current = location;
|
||||||
if (bookRef.current && renditionRef.current) {
|
if (bookRef.current && renditionRef.current) {
|
||||||
extractPageText(bookRef.current, renditionRef.current);
|
extractPageText(bookRef.current, renditionRef.current, shouldPauseRef.current);
|
||||||
|
shouldPauseRef.current = true;
|
||||||
}
|
}
|
||||||
}, [id, skipToLocation, extractPageText, setIsEPUB]);
|
}, [id, skipToLocation, extractPageText, setIsEPUB]);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -134,7 +134,7 @@ export function PDFProvider({ children }: { children: ReactNode }) {
|
||||||
// This prevents unnecessary resets of the sentence index
|
// This prevents unnecessary resets of the sentence index
|
||||||
if (text !== currDocText || text === '') {
|
if (text !== currDocText || text === '') {
|
||||||
setCurrDocText(text);
|
setCurrDocText(text);
|
||||||
setTTSText(text);
|
setTTSText(text, true);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error loading PDF text:', error);
|
console.error('Error loading PDF text:', error);
|
||||||
|
|
|
||||||
|
|
@ -222,6 +222,7 @@ export function TTSProvider({ children }: { children: ReactNode }) {
|
||||||
|
|
||||||
// Handle within current page bounds
|
// Handle within current page bounds
|
||||||
if (nextIndex < sentences.length && nextIndex >= 0) {
|
if (nextIndex < sentences.length && nextIndex >= 0) {
|
||||||
|
console.log('isEPUB', isEPUB!);
|
||||||
setCurrentIndex(nextIndex);
|
setCurrentIndex(nextIndex);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue