Skip to content

Commit 7ba807f

Browse files
committed
Pause on page changes + Fix ePub bug when reloading
1 parent 1bbd77f commit 7ba807f

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

src/contexts/EPUBContext.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ export function EPUBProvider({ children }: { children: ReactNode }) {
7171
const tocRef = useRef<NavItem[]>([]);
7272
const locationRef = useRef<string | number>(currDocPage);
7373
const isEPUBSetOnce = useRef(false);
74+
// Should pause ref
75+
const shouldPauseRef = useRef(true);
7476

7577
/**
7678
* Clears all current document state and stops any active TTS
@@ -80,6 +82,11 @@ export function EPUBProvider({ children }: { children: ReactNode }) {
8082
setCurrDocName(undefined);
8183
setCurrDocText(undefined);
8284
setCurrDocPages(undefined);
85+
isEPUBSetOnce.current = false;
86+
bookRef.current = null;
87+
renditionRef.current = undefined;
88+
locationRef.current = 1;
89+
tocRef.current = [];
8390
stop();
8491
}, [setCurrDocPages, stop]);
8592

@@ -341,10 +348,12 @@ export function EPUBProvider({ children }: { children: ReactNode }) {
341348

342349
// Handle special 'next' and 'prev' cases
343350
if (location === 'next' && renditionRef.current) {
351+
shouldPauseRef.current = false;
344352
renditionRef.current.next();
345353
return;
346354
}
347355
if (location === 'prev' && renditionRef.current) {
356+
shouldPauseRef.current = false;
348357
renditionRef.current.prev();
349358
return;
350359
}
@@ -359,7 +368,8 @@ export function EPUBProvider({ children }: { children: ReactNode }) {
359368

360369
locationRef.current = location;
361370
if (bookRef.current && renditionRef.current) {
362-
extractPageText(bookRef.current, renditionRef.current);
371+
extractPageText(bookRef.current, renditionRef.current, shouldPauseRef.current);
372+
shouldPauseRef.current = true;
363373
}
364374
}, [id, skipToLocation, extractPageText, setIsEPUB]);
365375

src/contexts/PDFContext.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ export function PDFProvider({ children }: { children: ReactNode }) {
134134
// This prevents unnecessary resets of the sentence index
135135
if (text !== currDocText || text === '') {
136136
setCurrDocText(text);
137-
setTTSText(text);
137+
setTTSText(text, true);
138138
}
139139
} catch (error) {
140140
console.error('Error loading PDF text:', error);

src/contexts/TTSContext.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ export function TTSProvider({ children }: { children: ReactNode }) {
222222

223223
// Handle within current page bounds
224224
if (nextIndex < sentences.length && nextIndex >= 0) {
225+
console.log('isEPUB', isEPUB!);
225226
setCurrentIndex(nextIndex);
226227
return;
227228
}

0 commit comments

Comments
 (0)