feat: add navigation to carousels and fix data loading
- Fix cache issues in home API route - Add navigation to series/books in MediaRow carousels - Improve Hero section visual with overflow handling - Simplify data structure and API responses
This commit is contained in:
69
src/components/home/HeroSection.tsx
Normal file
69
src/components/home/HeroSection.tsx
Normal file
@@ -0,0 +1,69 @@
|
||||
"use client";
|
||||
|
||||
import { KomgaSeries } from "@/types/komga";
|
||||
import Image from "next/image";
|
||||
import { useState } from "react";
|
||||
import { ImageOff } from "lucide-react";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
interface HeroSectionProps {
|
||||
series: KomgaSeries[];
|
||||
}
|
||||
|
||||
export function HeroSection({ series }: HeroSectionProps) {
|
||||
console.log("HeroSection - Séries reçues:", {
|
||||
count: series?.length || 0,
|
||||
firstSeries: series?.[0],
|
||||
});
|
||||
|
||||
return (
|
||||
<div className="relative h-[500px] -mx-4 sm:-mx-8 lg:-mx-14 overflow-hidden">
|
||||
{/* Grille de couvertures en arrière-plan */}
|
||||
<div className="absolute inset-0 grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-6 gap-4 p-4 opacity-10">
|
||||
{series?.map((series) => (
|
||||
<CoverImage key={series.id} series={series} />
|
||||
))}
|
||||
</div>
|
||||
|
||||
{/* Overlay gradient */}
|
||||
<div className="absolute inset-0 bg-gradient-to-b from-background/50 to-background" />
|
||||
|
||||
{/* Contenu */}
|
||||
<div className="relative h-full container flex flex-col items-center justify-center text-center space-y-4">
|
||||
<h1 className="text-4xl sm:text-5xl lg:text-6xl font-bold tracking-tight">
|
||||
Bienvenue sur Paniels
|
||||
</h1>
|
||||
<p className="text-xl text-muted-foreground max-w-[600px]">
|
||||
Votre bibliothèque numérique pour lire vos BD, mangas et comics préférés.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
interface CoverImageProps {
|
||||
series: KomgaSeries;
|
||||
}
|
||||
|
||||
function CoverImage({ series }: CoverImageProps) {
|
||||
const [imageError, setImageError] = useState(false);
|
||||
|
||||
return (
|
||||
<div className="relative aspect-[2/3] bg-muted rounded-lg overflow-hidden">
|
||||
{!imageError ? (
|
||||
<Image
|
||||
src={`/api/komga/images/series/${series.id}/thumbnail`}
|
||||
alt={`Couverture de ${series.metadata.title}`}
|
||||
fill
|
||||
className="object-cover"
|
||||
sizes="(max-width: 640px) 50vw, (max-width: 1024px) 33vw, 16.666vw"
|
||||
onError={() => setImageError(true)}
|
||||
/>
|
||||
) : (
|
||||
<div className="w-full h-full flex items-center justify-center">
|
||||
<ImageOff className="w-8 h-8" />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
71
src/components/home/HomeContent.tsx
Normal file
71
src/components/home/HomeContent.tsx
Normal file
@@ -0,0 +1,71 @@
|
||||
"use client";
|
||||
|
||||
import { HeroSection } from "./HeroSection";
|
||||
import { MediaRow } from "./MediaRow";
|
||||
import { KomgaBook, KomgaSeries } from "@/types/komga";
|
||||
import { useRouter } from "next/navigation";
|
||||
|
||||
interface HomeContentProps {
|
||||
data: {
|
||||
onGoingSeries: KomgaSeries[];
|
||||
recentlyRead: KomgaBook[];
|
||||
popularSeries: KomgaSeries[];
|
||||
};
|
||||
}
|
||||
|
||||
export function HomeContent({ data }: HomeContentProps) {
|
||||
const router = useRouter();
|
||||
|
||||
const handleItemClick = (item: KomgaSeries | KomgaBook) => {
|
||||
// Si c'est une série (a la propriété booksCount), on va vers la page de la série
|
||||
if ("booksCount" in item) {
|
||||
router.push(`/series/${item.id}`);
|
||||
} else {
|
||||
// Si c'est un livre, on va directement vers la page de lecture
|
||||
router.push(`/books/${item.id}`);
|
||||
}
|
||||
};
|
||||
|
||||
// Vérification des données pour le debug
|
||||
console.log("HomeContent - Données reçues:", {
|
||||
onGoingCount: data.onGoingSeries?.length || 0,
|
||||
recentlyReadCount: data.recentlyRead?.length || 0,
|
||||
popularCount: data.popularSeries?.length || 0,
|
||||
});
|
||||
|
||||
return (
|
||||
<main className="container mx-auto px-4 py-8 space-y-12">
|
||||
{/* Hero Section - Afficher uniquement si nous avons des séries populaires */}
|
||||
{data.popularSeries && data.popularSeries.length > 0 && (
|
||||
<HeroSection series={data.popularSeries} />
|
||||
)}
|
||||
|
||||
{/* Sections de contenu */}
|
||||
<div className="space-y-12">
|
||||
{data.onGoingSeries && data.onGoingSeries.length > 0 && (
|
||||
<MediaRow
|
||||
title="Continuer la lecture"
|
||||
items={data.onGoingSeries}
|
||||
onItemClick={handleItemClick}
|
||||
/>
|
||||
)}
|
||||
|
||||
{data.recentlyRead && data.recentlyRead.length > 0 && (
|
||||
<MediaRow
|
||||
title="Dernières lectures"
|
||||
items={data.recentlyRead}
|
||||
onItemClick={handleItemClick}
|
||||
/>
|
||||
)}
|
||||
|
||||
{data.popularSeries && data.popularSeries.length > 0 && (
|
||||
<MediaRow
|
||||
title="Séries populaires"
|
||||
items={data.popularSeries}
|
||||
onItemClick={handleItemClick}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
126
src/components/home/MediaRow.tsx
Normal file
126
src/components/home/MediaRow.tsx
Normal file
@@ -0,0 +1,126 @@
|
||||
"use client";
|
||||
|
||||
import { KomgaBook, KomgaSeries } from "@/types/komga";
|
||||
import { ChevronLeft, ChevronRight, ImageOff } from "lucide-react";
|
||||
import Image from "next/image";
|
||||
import { useRef, useState } from "react";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
interface MediaRowProps {
|
||||
title: string;
|
||||
items: (KomgaSeries | KomgaBook)[];
|
||||
onItemClick?: (item: KomgaSeries | KomgaBook) => void;
|
||||
}
|
||||
|
||||
export function MediaRow({ title, items, onItemClick }: MediaRowProps) {
|
||||
const scrollContainerRef = useRef<HTMLDivElement>(null);
|
||||
const [showLeftArrow, setShowLeftArrow] = useState(false);
|
||||
const [showRightArrow, setShowRightArrow] = useState(true);
|
||||
|
||||
const handleScroll = () => {
|
||||
if (!scrollContainerRef.current) return;
|
||||
|
||||
const { scrollLeft, scrollWidth, clientWidth } = scrollContainerRef.current;
|
||||
setShowLeftArrow(scrollLeft > 0);
|
||||
setShowRightArrow(scrollLeft < scrollWidth - clientWidth - 10);
|
||||
};
|
||||
|
||||
const scroll = (direction: "left" | "right") => {
|
||||
if (!scrollContainerRef.current) return;
|
||||
|
||||
const scrollAmount = direction === "left" ? -400 : 400;
|
||||
scrollContainerRef.current.scrollBy({ left: scrollAmount, behavior: "smooth" });
|
||||
};
|
||||
|
||||
if (!items.length) return null;
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<h2 className="text-2xl font-bold tracking-tight">{title}</h2>
|
||||
<div className="relative group">
|
||||
{/* Bouton de défilement gauche */}
|
||||
{showLeftArrow && (
|
||||
<button
|
||||
onClick={() => scroll("left")}
|
||||
className="absolute left-0 top-1/2 -translate-y-1/2 z-10 p-2 rounded-full bg-background/90 shadow-md border opacity-0 group-hover:opacity-100 transition-opacity"
|
||||
aria-label="Défiler vers la gauche"
|
||||
>
|
||||
<ChevronLeft className="h-6 w-6" />
|
||||
</button>
|
||||
)}
|
||||
|
||||
{/* Conteneur défilant */}
|
||||
<div
|
||||
ref={scrollContainerRef}
|
||||
onScroll={handleScroll}
|
||||
className="flex gap-4 overflow-x-auto scrollbar-hide scroll-smooth pb-4"
|
||||
>
|
||||
{items.map((item) => (
|
||||
<MediaCard key={item.id} item={item} onClick={() => onItemClick?.(item)} />
|
||||
))}
|
||||
</div>
|
||||
|
||||
{/* Bouton de défilement droit */}
|
||||
{showRightArrow && (
|
||||
<button
|
||||
onClick={() => scroll("right")}
|
||||
className="absolute right-0 top-1/2 -translate-y-1/2 z-10 p-2 rounded-full bg-background/90 shadow-md border opacity-0 group-hover:opacity-100 transition-opacity"
|
||||
aria-label="Défiler vers la droite"
|
||||
>
|
||||
<ChevronRight className="h-6 w-6" />
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
interface MediaCardProps {
|
||||
item: KomgaSeries | KomgaBook;
|
||||
onClick?: () => void;
|
||||
}
|
||||
|
||||
function MediaCard({ item, onClick }: MediaCardProps) {
|
||||
const [imageError, setImageError] = useState(false);
|
||||
|
||||
// Déterminer si c'est une série ou un livre
|
||||
const isSeries = "booksCount" in item;
|
||||
const title = isSeries
|
||||
? item.metadata.title
|
||||
: item.metadata.title || `Tome ${item.metadata.number}`;
|
||||
|
||||
return (
|
||||
<button
|
||||
onClick={onClick}
|
||||
className="flex-shrink-0 w-[200px] group relative flex flex-col rounded-lg border bg-card text-card-foreground shadow-sm hover:bg-accent hover:text-accent-foreground transition-colors overflow-hidden"
|
||||
>
|
||||
{/* Image de couverture */}
|
||||
<div className="relative aspect-[2/3] bg-muted">
|
||||
{!imageError ? (
|
||||
<Image
|
||||
src={`/api/komga/images/${isSeries ? "series" : "books"}/${item.id}/thumbnail`}
|
||||
alt={`Couverture de ${title}`}
|
||||
fill
|
||||
className="object-cover"
|
||||
sizes="200px"
|
||||
onError={() => setImageError(true)}
|
||||
/>
|
||||
) : (
|
||||
<div className="w-full h-full flex items-center justify-center">
|
||||
<ImageOff className="w-12 h-12" />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Contenu */}
|
||||
<div className="flex flex-col p-2">
|
||||
<h3 className="font-medium line-clamp-2 text-sm">{title}</h3>
|
||||
{isSeries && (
|
||||
<p className="text-xs text-muted-foreground mt-1">
|
||||
{item.booksCount} tome{item.booksCount > 1 ? "s" : ""}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
</button>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user