style: amélioration de la visibilité des toasts
This commit is contained in:
@@ -4,6 +4,7 @@ import { HomeContent } from "@/components/home/HomeContent";
|
|||||||
import { useState, useEffect } from "react";
|
import { useState, useEffect } from "react";
|
||||||
import { useRouter } from "next/navigation";
|
import { useRouter } from "next/navigation";
|
||||||
import { KomgaBook, KomgaSeries } from "@/types/komga";
|
import { KomgaBook, KomgaSeries } from "@/types/komga";
|
||||||
|
import { useToast } from "@/components/ui/use-toast";
|
||||||
|
|
||||||
interface HomeData {
|
interface HomeData {
|
||||||
ongoing: KomgaSeries[];
|
ongoing: KomgaSeries[];
|
||||||
@@ -13,6 +14,7 @@ interface HomeData {
|
|||||||
|
|
||||||
export default function HomePage() {
|
export default function HomePage() {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
const { toast } = useToast();
|
||||||
const [data, setData] = useState<HomeData | null>(null);
|
const [data, setData] = useState<HomeData | null>(null);
|
||||||
const [isLoading, setIsLoading] = useState(true);
|
const [isLoading, setIsLoading] = useState(true);
|
||||||
const [error, setError] = useState<string | null>(null);
|
const [error, setError] = useState<string | null>(null);
|
||||||
@@ -27,7 +29,6 @@ export default function HomePage() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const jsonData = await response.json();
|
const jsonData = await response.json();
|
||||||
// Transformer les données pour correspondre à l'interface HomeData
|
|
||||||
setData({
|
setData({
|
||||||
ongoing: jsonData.ongoing || [],
|
ongoing: jsonData.ongoing || [],
|
||||||
recentlyRead: jsonData.recentlyRead || [],
|
recentlyRead: jsonData.recentlyRead || [],
|
||||||
@@ -35,14 +36,25 @@ export default function HomePage() {
|
|||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Erreur lors de la récupération des données:", error);
|
console.error("Erreur lors de la récupération des données:", error);
|
||||||
setError(error instanceof Error ? error.message : "Une erreur est survenue");
|
const errorMessage = error instanceof Error ? error.message : "Une erreur est survenue";
|
||||||
|
setError(errorMessage);
|
||||||
|
|
||||||
|
// Si l'erreur indique une configuration manquante, rediriger vers les préférences
|
||||||
|
if (errorMessage.includes("Configuration Komga manquante")) {
|
||||||
|
toast({
|
||||||
|
title: "Configuration requise",
|
||||||
|
description: "Veuillez configurer votre serveur Komga pour continuer",
|
||||||
|
variant: "destructive",
|
||||||
|
});
|
||||||
|
router.push("/settings");
|
||||||
|
}
|
||||||
} finally {
|
} finally {
|
||||||
setIsLoading(false);
|
setIsLoading(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
fetchHomeData();
|
fetchHomeData();
|
||||||
}, []);
|
}, [router, toast]);
|
||||||
|
|
||||||
if (isLoading) {
|
if (isLoading) {
|
||||||
return (
|
return (
|
||||||
@@ -66,7 +78,7 @@ export default function HomePage() {
|
|||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
return (
|
return (
|
||||||
<main className="container mx-auto px-4 py-8 space-y-12">
|
<main className="container mx-auto px-4 py-8">
|
||||||
<div className="rounded-md bg-destructive/15 p-4">
|
<div className="rounded-md bg-destructive/15 p-4">
|
||||||
<p className="text-sm text-destructive">{error}</p>
|
<p className="text-sm text-destructive">{error}</p>
|
||||||
</div>
|
</div>
|
||||||
@@ -74,8 +86,5 @@ export default function HomePage() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!data) return null;
|
return data ? <HomeContent data={data} /> : null;
|
||||||
console.log("PAGE", data);
|
|
||||||
|
|
||||||
return <HomeContent data={data} />;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,9 +27,9 @@ const toastVariants = cva(
|
|||||||
{
|
{
|
||||||
variants: {
|
variants: {
|
||||||
variant: {
|
variant: {
|
||||||
default: "border bg-background text-foreground",
|
default: "border bg-primary text-primary-foreground shadow-lg",
|
||||||
destructive:
|
destructive:
|
||||||
"destructive group border-destructive bg-destructive text-destructive-foreground",
|
"destructive group border-destructive bg-destructive text-destructive-foreground font-medium",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
defaultVariants: {
|
defaultVariants: {
|
||||||
@@ -89,7 +89,11 @@ const ToastTitle = React.forwardRef<
|
|||||||
React.ElementRef<typeof ToastPrimitives.Title>,
|
React.ElementRef<typeof ToastPrimitives.Title>,
|
||||||
React.ComponentPropsWithoutRef<typeof ToastPrimitives.Title>
|
React.ComponentPropsWithoutRef<typeof ToastPrimitives.Title>
|
||||||
>(({ className, ...props }, ref) => (
|
>(({ className, ...props }, ref) => (
|
||||||
<ToastPrimitives.Title ref={ref} className={cn("text-sm font-semibold", className)} {...props} />
|
<ToastPrimitives.Title
|
||||||
|
ref={ref}
|
||||||
|
className={cn("text-base font-semibold", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
));
|
));
|
||||||
ToastTitle.displayName = ToastPrimitives.Title.displayName;
|
ToastTitle.displayName = ToastPrimitives.Title.displayName;
|
||||||
|
|
||||||
@@ -99,7 +103,7 @@ const ToastDescription = React.forwardRef<
|
|||||||
>(({ className, ...props }, ref) => (
|
>(({ className, ...props }, ref) => (
|
||||||
<ToastPrimitives.Description
|
<ToastPrimitives.Description
|
||||||
ref={ref}
|
ref={ref}
|
||||||
className={cn("text-sm opacity-90", className)}
|
className={cn("text-sm opacity-100", className)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
));
|
));
|
||||||
|
|||||||
Reference in New Issue
Block a user