refactor(reader): update progress tracking with EPUB location data

Simplify and enhance reading progress updates:
- Simplify payload structure by flattening location object
- Add epubcfi field to preserve EPUB reading position
- Add percentage field for normalized progress tracking
- Remove unnecessary nested location structure

This aligns with the updated backend API and provides
better support for reflowable EPUB content position tracking.
This commit is contained in:
2026-04-09 21:16:58 -04:00
parent 9977bbe66b
commit 3499277c2d
+6 -23
View File
@@ -1,9 +1,4 @@
import { apiPut } from "../../api";
interface ReadingProgress {
current_page: number;
total_pages: number;
}
import { apiPut, ReadingProgress } from "../../api";
interface ExtendedProgress {
character?: number;
@@ -20,25 +15,13 @@ export async function updateReadingProgress(
console.warn("Skipping progress update - no valid mediaItemId");
return;
}
const payload: any = {
location: {
page: progress.current_page,
total_pages: progress.total_pages,
},
current_page: progress.current_page,
total_pages: progress.total_pages,
epubcfi: progress.epubcfi || "", // ADD THIS
percentage: extended?.percentage || 0, // ADD THIS
};
if (extended) {
if (extended.character !== undefined) {
payload.location.character = extended.character;
}
if (extended.chapter !== undefined) {
payload.location.chapter = extended.chapter;
}
if (extended.percentage !== undefined) {
payload.location.percentage = extended.percentage;
}
}
const response = await apiPut(
`/media-items/${mediaItemId}/progress`,
payload,