fix: double call and fav on seriesheader KO

This commit is contained in:
2025-02-17 22:25:01 +01:00
parent e9566edad9
commit 0104e04c6b
2 changed files with 20 additions and 10 deletions

View File

@@ -105,10 +105,14 @@ export function Sidebar({ isOpen, onClose }: SidebarProps) {
router.push("/login"); router.push("/login");
}; };
const handleLinkClick = (path: string) => { const handleLinkClick = useCallback((path: string) => {
if (pathname === path) {
onClose(); onClose();
return;
}
router.push(path); router.push(path);
}; onClose();
}, [pathname, router, onClose]);
const navigation = [ const navigation = [
{ {

View File

@@ -19,10 +19,10 @@ export const SeriesHeader = ({ series }: SeriesHeaderProps) => {
// Vérifier si la série est dans les favoris // Vérifier si la série est dans les favoris
const checkFavorite = async () => { const checkFavorite = async () => {
try { try {
const response = await fetch(`/api/komga/series/${series.id}/favorite`); const response = await fetch("/api/komga/favorites");
if (response.ok) { if (response.ok) {
const data = await response.json(); const favoriteIds = await response.json();
setIsFavorite(data.favorite); setIsFavorite(favoriteIds.includes(series.id));
} }
} catch (error) { } catch (error) {
console.error("Erreur lors de la vérification des favoris:", error); console.error("Erreur lors de la vérification des favoris:", error);
@@ -34,16 +34,18 @@ export const SeriesHeader = ({ series }: SeriesHeaderProps) => {
const handleToggleFavorite = async () => { const handleToggleFavorite = async () => {
try { try {
const response = await fetch(`/api/komga/series/${series.id}/favorite`, { const response = await fetch(`/api/komga/favorites`, {
method: "POST", method: isFavorite ? "DELETE" : "POST",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
}, },
body: JSON.stringify({ favorite: !isFavorite }), body: JSON.stringify({ seriesId: series.id }),
}); });
if (response.ok) { if (response.ok) {
setIsFavorite(!isFavorite); setIsFavorite(!isFavorite);
// Déclencher l'événement pour mettre à jour la sidebar
window.dispatchEvent(new Event("favoritesChanged"));
toast({ toast({
title: !isFavorite ? "Ajouté aux favoris" : "Retiré des favoris", title: !isFavorite ? "Ajouté aux favoris" : "Retiré des favoris",
description: series.metadata.title, description: series.metadata.title,
@@ -144,7 +146,11 @@ export const SeriesHeader = ({ series }: SeriesHeaderProps) => {
onClick={handleToggleFavorite} onClick={handleToggleFavorite}
className="text-white hover:text-white" className="text-white hover:text-white"
> >
{isFavorite ? <Star className="w-5 h-5" /> : <StarOff className="w-5 h-5" />} {isFavorite ? (
<Star className="w-5 h-5 fill-yellow-400 text-yellow-400" />
) : (
<StarOff className="w-5 h-5" />
)}
</Button> </Button>
</div> </div>
</div> </div>