feat: enhance home and library pages by integrating new data fetching methods, improving error handling, and refactoring components for better structure
All checks were successful
Deploy with Docker Compose / deploy (push) Successful in 4m17s
All checks were successful
Deploy with Docker Compose / deploy (push) Successful in 4m17s
This commit is contained in:
@@ -2,30 +2,52 @@ import type { KomgaBook } from "@/types/komga";
|
||||
|
||||
export class ClientOfflineBookService {
|
||||
static setCurrentPage(book: KomgaBook, page: number) {
|
||||
localStorage.setItem(`${book.id}-page`, page.toString());
|
||||
if (typeof window !== "undefined" && typeof localStorage !== "undefined" && localStorage.setItem) {
|
||||
try {
|
||||
localStorage.setItem(`${book.id}-page`, page.toString());
|
||||
} catch {
|
||||
// Ignore localStorage errors in SSR
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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 (typeof window !== "undefined" && typeof localStorage !== "undefined" && localStorage.getItem) {
|
||||
try {
|
||||
const cPageLS = localStorage.getItem(`${book.id}-page`) || "0";
|
||||
const currentPage = parseInt(cPageLS);
|
||||
|
||||
if (currentPage < readProgressPage) {
|
||||
if (currentPage < readProgressPage) {
|
||||
return readProgressPage;
|
||||
}
|
||||
|
||||
return currentPage;
|
||||
} catch {
|
||||
return readProgressPage;
|
||||
}
|
||||
|
||||
return currentPage;
|
||||
} else {
|
||||
return readProgressPage;
|
||||
}
|
||||
}
|
||||
|
||||
static removeCurrentPage(book: KomgaBook) {
|
||||
localStorage.removeItem(`${book.id}-page`);
|
||||
if (typeof window !== "undefined" && typeof localStorage !== "undefined" && localStorage.removeItem) {
|
||||
try {
|
||||
localStorage.removeItem(`${book.id}-page`);
|
||||
} catch {
|
||||
// Ignore localStorage errors in SSR
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static removeCurrentPageById(bookId: string) {
|
||||
localStorage.removeItem(`${bookId}-page`);
|
||||
if (typeof window !== "undefined" && typeof localStorage !== "undefined" && localStorage.removeItem) {
|
||||
try {
|
||||
localStorage.removeItem(`${bookId}-page`);
|
||||
} catch {
|
||||
// Ignore localStorage errors in SSR
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
39
src/lib/services/favorites.service.ts
Normal file
39
src/lib/services/favorites.service.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import { FavoriteService } from "./favorite.service";
|
||||
import { SeriesService } from "./series.service";
|
||||
import type { KomgaSeries } from "@/types/komga";
|
||||
import logger from "@/lib/logger";
|
||||
|
||||
export class FavoritesService {
|
||||
static async getFavorites(): Promise<KomgaSeries[]> {
|
||||
try {
|
||||
const favoriteIds = await FavoriteService.getAllFavoriteIds();
|
||||
|
||||
if (favoriteIds.length === 0) {
|
||||
return [];
|
||||
}
|
||||
|
||||
// Fetch toutes les séries en parallèle
|
||||
const promises = favoriteIds.map(async (id: string) => {
|
||||
try {
|
||||
return await SeriesService.getSeries(id);
|
||||
} catch (error) {
|
||||
logger.error({ err: error, seriesId: id }, "Error fetching favorite series");
|
||||
// Si la série n'existe plus, la retirer des favoris
|
||||
try {
|
||||
await FavoriteService.removeFromFavorites(id);
|
||||
} catch {
|
||||
// Ignore cleanup errors
|
||||
}
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
const results = await Promise.all(promises);
|
||||
return results.filter((series): series is KomgaSeries => series !== null);
|
||||
} catch (error) {
|
||||
logger.error({ err: error }, "Error fetching favorites");
|
||||
return [];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user