feat: local store read progress for later sync

This commit is contained in:
Julien Froidefond
2025-03-01 11:37:34 +01:00
parent 13492cea84
commit a3d0094cec
11 changed files with 93 additions and 43 deletions

View File

@@ -0,0 +1,31 @@
import { KomgaBook } from "@/types/komga";
export class ClientOfflineBookService {
static setCurrentPage(book: KomgaBook, page: number) {
localStorage.setItem(`${book.id}-page`, page.toString());
}
static getCurrentPage(book: KomgaBook) {
const readProgressPage = book.readProgress?.page || 0;
if (typeof localStorage !== "undefined") {
const cPageLS = localStorage.getItem(`${book.id}-page`) || "0";
const currentPage = parseInt(cPageLS);
if (currentPage < readProgressPage) {
return readProgressPage;
}
return currentPage;
} else {
return readProgressPage;
}
}
static removeCurrentPage(book: KomgaBook) {
localStorage.removeItem(`${book.id}-page`);
}
static removeCurrentPageById(bookId: string) {
localStorage.removeItem(`${bookId}-page`);
}
}