feat: update progress indicator to use dynamic page calculation
- Import getCurrentPageFromScroll for viewport-based page calculation - Replace spine index with actual calculated page numbers when available - Fix bug where currentPage was assigned to itself (no-op) - Add fallback to estimated pages while calculation is in progress
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import type { ReaderContext } from "../core/reader-context";
|
||||
import { getCurrentPageFromScroll } from "../ebook/page-calculator";
|
||||
interface ProgressDisplay {
|
||||
mode: "pages" | "chapter" | "percentage" | "time-left";
|
||||
text: string;
|
||||
@@ -111,14 +112,27 @@ function updateProgressDisplay(context: ReaderContext): void {
|
||||
let currentPage = 0;
|
||||
let totalPages = 0;
|
||||
if (state.currentReader.type === "ebook") {
|
||||
currentPage = state.currentReader.currentSpineIndex + 1;
|
||||
totalPages = state.currentReader.cif.spine.length;
|
||||
} else if (state.currentReader.type === "pdf") {
|
||||
currentPage = state.currentReader.currentPage;
|
||||
totalPages = state.readerMetadata?.total_pages || 0;
|
||||
} else {
|
||||
currentPage = state.currentReader.currentPage;
|
||||
totalPages = state.currentReader.images.length;
|
||||
const reader = state.currentReader as any;
|
||||
const pageInfo = reader.pageCalculationResult;
|
||||
|
||||
if (pageInfo && pageInfo.totalPages > 0) {
|
||||
const container = document.getElementById("reader-content");
|
||||
const viewportHeight = window.innerHeight;
|
||||
currentPage = getCurrentPageFromScroll(
|
||||
pageInfo,
|
||||
reader.currentSpineIndex,
|
||||
container?.scrollTop || 0,
|
||||
viewportHeight,
|
||||
);
|
||||
totalPages = pageInfo.totalPages;
|
||||
} else {
|
||||
// Fallback to estimated pages while calculating
|
||||
currentPage = reader.currentSpineIndex + 1;
|
||||
totalPages =
|
||||
state.readerMetadata?.total_pages ||
|
||||
state.currentReader.cif.locations?.estimatedPages ||
|
||||
state.currentReader.cif.spine.length;
|
||||
}
|
||||
}
|
||||
getReadingSpeed().then((speed) => {
|
||||
const result = calculateProgress(
|
||||
|
||||
Reference in New Issue
Block a user