fix(reader): scale percentage correctly, add 5s init guard
- reader.templ: divide DB percentage (0-1) by 100 was wrong; actually the router multiplies by 100, so template now divides by 100 to get back to 0-1 range for foliate-js savedPercentage - reader.ts: add 5-second initTime guard to prevent overwriting existing progress with initial position on page load
This commit is contained in:
@@ -14,7 +14,7 @@ func readerInitExpr(metadata ReaderMetadata, progress ReadingProgress) string {
|
||||
"mangaType": metadata.MangaType,
|
||||
}
|
||||
if progress.Percentage > 0 {
|
||||
config["savedPercentage"] = progress.Percentage
|
||||
config["savedPercentage"] = progress.Percentage / 100
|
||||
}
|
||||
if progress.EpubCfi != "" {
|
||||
config["savedCfi"] = progress.EpubCfi
|
||||
|
||||
@@ -22,7 +22,7 @@ func readerInitExpr(metadata ReaderMetadata, progress ReadingProgress) string {
|
||||
"mangaType": metadata.MangaType,
|
||||
}
|
||||
if progress.Percentage > 0 {
|
||||
config["savedPercentage"] = progress.Percentage
|
||||
config["savedPercentage"] = progress.Percentage / 100
|
||||
}
|
||||
if progress.EpubCfi != "" {
|
||||
config["savedCfi"] = progress.EpubCfi
|
||||
|
||||
@@ -383,6 +383,7 @@ document.addEventListener("alpine:init", () => {
|
||||
tocItems: [] as any[],
|
||||
mediaItemId: "" as string,
|
||||
saveTimeout: null as ReturnType<typeof setTimeout> | null,
|
||||
initTime: 0 as number,
|
||||
readingTheme: "light" as string,
|
||||
readingMode: "light" as string,
|
||||
readingFont: "literata" as string,
|
||||
@@ -525,9 +526,11 @@ document.addEventListener("alpine:init", () => {
|
||||
} else {
|
||||
await this.view.init({});
|
||||
}
|
||||
this.initTime = Date.now();
|
||||
this.fetchReadingSpeed();
|
||||
},
|
||||
debouncedSaveProgress(fraction: number, location: any, cfi: string) {
|
||||
if (Date.now() - this.initTime < 5000) return;
|
||||
if (this.saveTimeout) clearTimeout(this.saveTimeout);
|
||||
this.saveTimeout = setTimeout(() => {
|
||||
this.saveProgress(fraction, location, cfi);
|
||||
|
||||
Reference in New Issue
Block a user