refacto: type mutu

This commit is contained in:
Julien Froidefond
2025-02-26 13:33:40 +01:00
parent 1a0e4d2422
commit 3b2d4cb0d5
7 changed files with 29 additions and 48 deletions

View File

@@ -4,6 +4,7 @@ import { redirect } from "next/navigation";
import { revalidatePath } from "next/cache";
import { withPageTiming } from "@/lib/hoc/withPageTiming";
import { ErrorMessage } from "@/components/ui/ErrorMessage";
import { HomeData } from "@/lib/services/home.service";
async function refreshHome() {
"use server";
@@ -20,7 +21,7 @@ async function refreshHome() {
async function HomePage() {
try {
const data = await HomeService.getHomeData();
const data: HomeData = await HomeService.getHomeData();
return <HomeContent data={data} refreshHome={refreshHome} />;
} catch (error) {

View File

@@ -3,14 +3,7 @@ import { MediaRow } from "./MediaRow";
import { KomgaBook, KomgaSeries } from "@/types/komga";
import { RefreshButton } from "@/components/library/RefreshButton";
import { History, Sparkles, Clock, LibraryBig, BookOpen } from "lucide-react";
interface HomeData {
ongoing: KomgaSeries[];
ongoingBooks: KomgaBook[];
recentlyRead: KomgaBook[];
onDeck: KomgaBook[];
latestSeries: KomgaSeries[];
}
import { HomeData } from "@/lib/services/home.service";
interface HomeContentProps {
data: HomeData;
@@ -30,7 +23,7 @@ export function HomeContent({ data, refreshHome }: HomeContentProps) {
id,
metadata: { title: metadata.title },
booksCount,
booksReadCount
booksReadCount,
}));
};
@@ -39,7 +32,7 @@ export function HomeContent({ data, refreshHome }: HomeContentProps) {
id,
metadata: { title: metadata.title },
booksCount,
booksReadCount
booksReadCount,
}));
};
@@ -51,7 +44,7 @@ export function HomeContent({ data, refreshHome }: HomeContentProps) {
number: metadata.number,
},
readProgress: readProgress || { page: 0 },
media
media,
}));
};

View File

@@ -3,20 +3,7 @@
import React, { createContext, useContext, useEffect, useState } from "react";
import { ERROR_CODES } from "../constants/errorCodes";
import { AppError } from "../utils/errors";
export interface UserPreferences {
showThumbnails: boolean;
cacheMode: "memory" | "file";
showOnlyUnread: boolean;
debug: boolean;
}
const defaultPreferences: UserPreferences = {
showThumbnails: true,
cacheMode: "memory",
showOnlyUnread: false,
debug: false,
};
import { UserPreferences, defaultPreferences } from "@/types/preferences";
interface PreferencesContextType {
preferences: UserPreferences;

View File

@@ -5,9 +5,9 @@ import { getServerCacheService } from "./server-cache.service";
import { ERROR_CODES } from "../../constants/errorCodes";
import { AppError } from "../../utils/errors";
interface HomeData {
export interface HomeData {
ongoing: KomgaSeries[];
ongoingBooks: KomgaBook[]; // Nouveau champ
ongoingBooks: KomgaBook[];
recentlyRead: KomgaBook[];
onDeck: KomgaBook[];
latestSeries: KomgaSeries[];

View File

@@ -2,26 +2,13 @@ import { PreferencesModel } from "@/lib/models/preferences.model";
import { AuthServerService } from "./auth-server.service";
import { ERROR_CODES } from "../../constants/errorCodes";
import { AppError } from "../../utils/errors";
import { UserPreferences, defaultPreferences } from "@/types/preferences";
interface User {
id: string;
email: string;
}
export interface UserPreferences {
showThumbnails: boolean;
cacheMode: "memory" | "file";
showOnlyUnread: boolean;
debug: boolean;
}
const defaultPreferences: UserPreferences = {
showThumbnails: true,
cacheMode: "memory",
showOnlyUnread: false,
debug: false,
};
export class PreferencesService {
static getCurrentUser(): User {
const user = AuthServerService.getCurrentUser();

13
src/types/preferences.ts Normal file
View File

@@ -0,0 +1,13 @@
export interface UserPreferences {
showThumbnails: boolean;
cacheMode: "memory" | "file";
showOnlyUnread: boolean;
debug: boolean;
}
export const defaultPreferences: UserPreferences = {
showThumbnails: true,
cacheMode: "memory",
showOnlyUnread: false,
debug: false,
} as const;