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:
@@ -1,9 +1,4 @@
|
|||||||
import { apiPut } from "../../api";
|
import { apiPut, ReadingProgress } from "../../api";
|
||||||
|
|
||||||
interface ReadingProgress {
|
|
||||||
current_page: number;
|
|
||||||
total_pages: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface ExtendedProgress {
|
interface ExtendedProgress {
|
||||||
character?: number;
|
character?: number;
|
||||||
@@ -20,25 +15,13 @@ export async function updateReadingProgress(
|
|||||||
console.warn("Skipping progress update - no valid mediaItemId");
|
console.warn("Skipping progress update - no valid mediaItemId");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const payload: any = {
|
const payload: any = {
|
||||||
location: {
|
current_page: progress.current_page,
|
||||||
page: progress.current_page,
|
total_pages: progress.total_pages,
|
||||||
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(
|
const response = await apiPut(
|
||||||
`/media-items/${mediaItemId}/progress`,
|
`/media-items/${mediaItemId}/progress`,
|
||||||
payload,
|
payload,
|
||||||
|
|||||||
Reference in New Issue
Block a user