# Unused Variables and Imports in Refactor Plan Found 3 issues in the refactor plan that need fixing: --- ## Issue 1: Unused Constant in `page-calculator.ts` **File:** `web/src/reader/formats/reflowable/page-calculator.ts` **Line:** 201 **Issue:** `AVG_WORD_LENGTH` is declared but never used ```typescript // REMOVE THIS LINE: const AVG_WORD_LENGTH = 5; // For char count estimation ``` **Reason:** This constant is declared with a comment saying "For char count estimation" but is never actually used in the code. All character counting is done with `.length` on strings. --- ## Issue 2: Unused Import in `navigation.ts` **File:** `web/src/reader/formats/reflowable/navigation.ts` **Line:** 413 **Issue:** `shouldRecalculate` is imported but never used ```typescript // BEFORE (line 413): import { getPageContent, findPageByCFI, shouldRecalculate } from "./page-calculator"; // AFTER: import { getPageContent, findPageByCFI } from "./page-calculator"; ``` **Reason:** `shouldRecalculate` is used in `reader-shell.ts` (line 1197) but not in `navigation.ts`. It doesn't need to be imported here. --- ## Issue 3: Inconsistent Import Style in `progress-tracker.ts` **File:** `web/src/reader/formats/reflowable/progress-tracker.ts` **Lines:** 601, 608 **Issue:** Uses `require()` inline instead of ES6 imports at top ```typescript // BEFORE (lines 544-604): import type { ReflowableBook, ReadingPosition } from "./types"; export function restorePosition( book: ReflowableBook, savedCFI: string, savedPage?: number ): ReadingPosition { if (!book.pagination) { return book.position; } // If we have saved CFI, try to find exact position if (savedCFI) { const { findPageByCFI, createPositionFromPage } = require("./page-calculator"); const pageNum = findPageByCFI(book.pagination, savedCFI); return createPositionFromPage(book, pageNum); } // Otherwise use saved page number if (savedPage && savedPage > 0) { const { createPositionFromPage } = require("./page-calculator"); return createPositionFromPage(book, savedPage); } return book.position; } // AFTER: import type { ReflowableBook, ReadingPosition } from "./types"; import { findPageByCFI } from "./page-calculator"; import { createPositionFromPage } from "./navigation"; export function restorePosition( book: ReflowableBook, savedCFI: string, savedPage?: number ): ReadingPosition { if (!book.pagination) { return book.position; } // If we have saved CFI, try to find exact position if (savedCFI) { const pageNum = findPageByCFI(book.pagination, savedCFI); return createPositionFromPage(book, pageNum); } // Otherwise use saved page number if (savedPage && savedPage > 0) { return createPositionFromPage(book, savedPage); } return book.position; } ``` **Wait, there's a circular dependency issue here!** - `progress-tracker.ts` imports from `navigation.ts` (for `createPositionFromPage`) - `navigation.ts` imports from `progress-tracker.ts` (for `updateCurrentPosition`) **Better fix:** Move `createPositionFromPage` to `page-calculator.ts` where it's used: ```typescript // In page-calculator.ts, ADD at the end: export function createPositionFromPage( book: ReflowableBook, page: number ): ReadingPosition { if (!book.pagination) { return { currentPage: 1, spineIndex: 0, localPageIndex: 0, cfi: "", progress: 0, }; } const pageIndex = page - 1; const pageData = book.pagination.pageMap.get(pageIndex); if (!pageData) { return { currentPage: 1, spineIndex: 0, localPageIndex: 0, cfi: "", progress: 0, }; } // Find which spine this page belongs to let spineIndex = 0; for (const spine of book.pagination.spines) { if (pageData.localPageIndex < spine.pages.length) { spineIndex = spine.spineIndex; break; } } return { currentPage: page, spineIndex, localPageIndex: pageData.localPageIndex, cfi: pageData.cfi, progress: book.pagination.totalPages > 0 ? page / book.pagination.totalPages : 0, }; } ``` Then update `progress-tracker.ts`: ```typescript import type { ReflowableBook, ReadingPosition } from "./types"; import { findPageByCFI, createPositionFromPage } from "./page-calculator"; ``` And update `navigation.ts` to import it from page-calculator: ```typescript import type { PaginationData, ReadingPosition, ReflowableBook } from "./types"; import { getPageContent, findPageByCFI, createPositionFromPage } from "./page-calculator"; ``` --- ## Summary of Fixes 1. **Delete** `AVG_WORD_LENGTH` constant from `page-calculator.ts` (line 201) 2. **Remove** `shouldRecalculate` from import in `navigation.ts` (line 413) 3. **Move** `createPositionFromPage` from `navigation.ts` to `page-calculator.ts` 4. **Update** imports in `progress-tracker.ts` to use ES6 imports instead of require() 5. **Update** imports in `navigation.ts` to import `createPositionFromPage` from page-calculator --- ## Updated File Changes ### page-calculator.ts - Remove line 201 (`AVG_WORD_LENGTH`) - Add `createPositionFromPage` function at the end (before the `shouldRecalculate` function) ### navigation.ts - Remove `shouldRecalculate` from import on line 413 - Change import of `createPositionFromPage` to come from `page-calculator` - Remove the `createPositionFromPage` function definition (lines 470-507) ### progress-tracker.ts - Change lines 544-545 to add proper imports - Remove `require()` statements on lines 601 and 608 These changes will fix all unused variables/imports and resolve the circular dependency issue.