fix: Correct progress indicator pagination data access and improve type safety
BUG FIXES:
1. Fix incorrect property access causing page counter to show wrong totals
- Changed: reader.pageCalculationResult → reader.pagination
- The pageCalculationResult property doesn't exist on UniversalReader
- This caused fallback to metadata.total_pages (299) instead of
calculated pagination.totalPages (119)
2. Fix non-existent chapterMap property access
- chapterMap doesn't exist on PaginationData interface
- Changed to use spineMap which provides the same information
- Calculate chapter start page from spine.pages[0].pageIndex
- Calculate chapter pages from spine.pages.length
TYPE SAFETY IMPROVEMENTS:
3. Remove 'as any' type cast for ebook reader
- Changed: const reader = state.currentReader as any
- To: const reader = state.currentReader
- TypeScript already knows the type after type check
4. Remove 'as any' type casts for comic/manga readers
- Added proper type narrowing with if statement
- Changed: (state.currentReader as any).currentPage
- To: reader.currentPage with type guard
- Improves type safety and enables better IDE autocomplete
IMPACT:
✅ Page counter shows correct total (119 instead of 299)
✅ Chapter progress displays accurately
✅ No TypeScript errors for missing properties
✅ Better type safety prevents similar bugs in the future
✅ IDE autocomplete works correctly for reader properties
This fix resolves the pagination data access issues that caused the
page counter to display incorrect totals and improves overall type
safety in the progress indicator component.
Related to: Page counter display, type safety improvements
This commit is contained in:
@@ -113,7 +113,7 @@ function updateProgressDisplay(context: ReaderContext): void {
|
||||
let currentChapterPage = 0;
|
||||
let chapterPages = 0;
|
||||
if (state.currentReader.type === "ebook") {
|
||||
const reader = state.currentReader as any;
|
||||
const reader = state.currentReader;
|
||||
|
||||
// Use currentPage directly if available (page-based navigation)
|
||||
if (reader.currentPage) {
|
||||
@@ -123,15 +123,16 @@ function updateProgressDisplay(context: ReaderContext): void {
|
||||
}
|
||||
|
||||
// Get total pages from calculation result
|
||||
const pageInfo = reader.pageCalculationResult;
|
||||
const pageInfo = reader.pagination;
|
||||
if (pageInfo && pageInfo.totalPages > 0) {
|
||||
totalPages = pageInfo.totalPages;
|
||||
|
||||
// Get chapter progress
|
||||
const chapter = pageInfo.chapterMap.get(reader.currentSpineIndex);
|
||||
if (chapter) {
|
||||
currentChapterPage = currentPage - chapter.startPage + 1;
|
||||
chapterPages = chapter.pagesInChapter;
|
||||
// Get chapter progress from spine info
|
||||
const spine = pageInfo.spineMap.get(reader.currentSpineIndex);
|
||||
if (spine && spine.pages.length > 0) {
|
||||
const chapterStartPage = spine.pages[0].pageIndex;
|
||||
currentChapterPage = currentPage - chapterStartPage + 1;
|
||||
chapterPages = spine.pages.length;
|
||||
}
|
||||
} else {
|
||||
// Fallback
|
||||
@@ -145,8 +146,11 @@ function updateProgressDisplay(context: ReaderContext): void {
|
||||
totalPages = state.readerMetadata?.total_pages || 0;
|
||||
} else {
|
||||
// Comic/manga
|
||||
currentPage = (state.currentReader as any).currentPage + 1;
|
||||
totalPages = (state.currentReader as any).images?.length || 0;
|
||||
const reader = state.currentReader;
|
||||
if (reader.type === "comic" || reader.type === "manga") {
|
||||
currentPage = reader.currentPage + 1;
|
||||
totalPages = reader.images?.length || 0;
|
||||
}
|
||||
}
|
||||
getReadingSpeed().then((speed) => {
|
||||
const result = calculateProgress(
|
||||
|
||||
Reference in New Issue
Block a user