EPUB saved location fix

This commit is contained in:
Richard Roberson 2025-02-14 03:50:53 -07:00
parent 1dcf1b09e3
commit d773f8254c

View file

@ -17,14 +17,6 @@ const ReactReader = dynamic(() => import('react-reader').then(mod => mod.ReactRe
loading: () => <DocumentSkeleton /> loading: () => <DocumentSkeleton />
}); });
const colors = {
background: getComputedStyle(document.documentElement).getPropertyValue('--background'),
foreground: getComputedStyle(document.documentElement).getPropertyValue('--foreground'),
base: getComputedStyle(document.documentElement).getPropertyValue('--base'),
offbase: getComputedStyle(document.documentElement).getPropertyValue('--offbase'),
muted: getComputedStyle(document.documentElement).getPropertyValue('--muted'),
};
const getThemeStyles = (): IReactReaderStyle => { const getThemeStyles = (): IReactReaderStyle => {
const baseStyle = { const baseStyle = {
...ReactReaderStyle, ...ReactReaderStyle,
@ -34,6 +26,14 @@ const getThemeStyles = (): IReactReaderStyle => {
} }
}; };
const colors = {
background: getComputedStyle(document.documentElement).getPropertyValue('--background'),
foreground: getComputedStyle(document.documentElement).getPropertyValue('--foreground'),
base: getComputedStyle(document.documentElement).getPropertyValue('--base'),
offbase: getComputedStyle(document.documentElement).getPropertyValue('--offbase'),
muted: getComputedStyle(document.documentElement).getPropertyValue('--muted'),
};
return { return {
...baseStyle, ...baseStyle,
arrow: { arrow: {
@ -125,14 +125,15 @@ export function EPUBViewer({ className = '' }: EPUBViewerProps) {
} }
} }
locationRef.current = location;
setEPUBPageInChapter(displayed.page, displayed.total, chapter?.label || ''); setEPUBPageInChapter(displayed.page, displayed.total, chapter?.label || '');
// Add a small delay for initial load to ensure rendition is ready // Add a small delay for initial load to ensure rendition is ready
if (initial) { if (initial) {
setInitialPrevLocLoad(true); rendition.current.display(location.toString()).then(() => {
setInitialPrevLocLoad(true);
});
} else { } else {
locationRef.current = location;
extractPageText(bookRef.current, rendition.current); extractPageText(bookRef.current, rendition.current);
} }
} }
@ -148,6 +149,11 @@ export function EPUBViewer({ className = '' }: EPUBViewerProps) {
const updateTheme = useCallback((rendition: Rendition) => { const updateTheme = useCallback((rendition: Rendition) => {
if (!epubTheme) return; // Only apply theme if enabled if (!epubTheme) return; // Only apply theme if enabled
const colors = {
foreground: getComputedStyle(document.documentElement).getPropertyValue('--foreground'),
base: getComputedStyle(document.documentElement).getPropertyValue('--base'),
};
rendition.themes.override('color', colors.foreground); rendition.themes.override('color', colors.foreground);
rendition.themes.override('background', colors.base); rendition.themes.override('background', colors.base);
}, [epubTheme]); }, [epubTheme]);