fix: double call and fav on seriesheader KO
This commit is contained in:
@@ -105,10 +105,14 @@ export function Sidebar({ isOpen, onClose }: SidebarProps) {
|
||||
router.push("/login");
|
||||
};
|
||||
|
||||
const handleLinkClick = (path: string) => {
|
||||
const handleLinkClick = useCallback((path: string) => {
|
||||
if (pathname === path) {
|
||||
onClose();
|
||||
return;
|
||||
}
|
||||
router.push(path);
|
||||
};
|
||||
onClose();
|
||||
}, [pathname, router, onClose]);
|
||||
|
||||
const navigation = [
|
||||
{
|
||||
|
||||
@@ -19,10 +19,10 @@ export const SeriesHeader = ({ series }: SeriesHeaderProps) => {
|
||||
// Vérifier si la série est dans les favoris
|
||||
const checkFavorite = async () => {
|
||||
try {
|
||||
const response = await fetch(`/api/komga/series/${series.id}/favorite`);
|
||||
const response = await fetch("/api/komga/favorites");
|
||||
if (response.ok) {
|
||||
const data = await response.json();
|
||||
setIsFavorite(data.favorite);
|
||||
const favoriteIds = await response.json();
|
||||
setIsFavorite(favoriteIds.includes(series.id));
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Erreur lors de la vérification des favoris:", error);
|
||||
@@ -34,16 +34,18 @@ export const SeriesHeader = ({ series }: SeriesHeaderProps) => {
|
||||
|
||||
const handleToggleFavorite = async () => {
|
||||
try {
|
||||
const response = await fetch(`/api/komga/series/${series.id}/favorite`, {
|
||||
method: "POST",
|
||||
const response = await fetch(`/api/komga/favorites`, {
|
||||
method: isFavorite ? "DELETE" : "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({ favorite: !isFavorite }),
|
||||
body: JSON.stringify({ seriesId: series.id }),
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
setIsFavorite(!isFavorite);
|
||||
// Déclencher l'événement pour mettre à jour la sidebar
|
||||
window.dispatchEvent(new Event("favoritesChanged"));
|
||||
toast({
|
||||
title: !isFavorite ? "Ajouté aux favoris" : "Retiré des favoris",
|
||||
description: series.metadata.title,
|
||||
@@ -144,7 +146,11 @@ export const SeriesHeader = ({ series }: SeriesHeaderProps) => {
|
||||
onClick={handleToggleFavorite}
|
||||
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>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user