1+ 'use client' ;
2+
3+ import Image from 'next/image' ;
4+ import movieStyles from "./MovieCard.module.css" ;
5+ import { MovieCardProps } from "../../types/movie" ;
6+
7+ /**
8+ * Movie Card Client Component
9+ *
10+ * This component handles the interactive parts of the movie card,
11+ * such as image error handling, while the parent remains a Server Component.
12+ */
13+ export default function MovieCard ( { movie } : MovieCardProps ) {
14+ const handleImageError = ( ) => {
15+ // This will be handled by the Image component's onError prop
16+ console . warn ( `Failed to load poster for: ${ movie . title } ` ) ;
17+ } ;
18+
19+ return (
20+ < div className = { movieStyles . movieCard } >
21+ < div className = { movieStyles . moviePoster } >
22+ { movie . poster ? (
23+ < Image
24+ src = { movie . poster }
25+ alt = { `${ movie . title } poster` }
26+ fill
27+ sizes = "(max-width: 480px) 100vw, (max-width: 768px) 50vw, 280px"
28+ style = { { objectFit : 'cover' } }
29+ onError = { handleImageError }
30+ placeholder = "blur"
31+ blurDataURL = "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAYEBQYFBAYGBQYHBwYIChAKCgkJChQODwwQFxQYGBcUFhYaHSUfGhsjHBYWICwgIyYnKSopGR8tMC0oMCUoKSj/2wBDAQcHBwoIChMKChMoGhYaKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCj/wAARCAABAAEDASIAAhEBAxEB/8QAFQABAQAAAAAAAAAAAAAAAAAAAAv/xAAhEAACAQMDBQAAAAAAAAAAAAABAgMABAUGIWGRkqGx0f/EABUBAQEAAAAAAAAAAAAAAAAAAAMF/8QAGhEAAgIDAAAAAAAAAAAAAAAAAAECEgMRkf/aAAwDAQACEQMRAD8AltJagyeH0AthI5xdrLcNM91BF5pX2HaH9bcfaSXWGaRmknyJckliyjqTzSlT54b6bk+h0R7Dh5zq6esmOk2cWkgaWKJZoSGEa5qKUlPP45++P//Z"
32+ />
33+ ) : (
34+ < div className = { movieStyles . posterPlaceholder } >
35+ No Poster Available
36+ </ div >
37+ ) }
38+ </ div >
39+
40+ < div className = { movieStyles . movieInfo } >
41+ < h3 className = { movieStyles . movieTitle } > { movie . title } </ h3 >
42+ { movie . year && (
43+ < p className = { movieStyles . movieYear } > ({ movie . year } )</ p >
44+ ) }
45+ { movie . imdb ?. rating && (
46+ < p className = { movieStyles . movieRating } > ⭐ { movie . imdb . rating } /10</ p >
47+ ) }
48+ { movie . genres && movie . genres . length > 0 && (
49+ < p className = { movieStyles . movieGenres } >
50+ { movie . genres . slice ( 0 , 3 ) . join ( ', ' ) }
51+ </ p >
52+ ) }
53+ </ div >
54+
55+ < button className = { movieStyles . detailsButton } type = "button" >
56+ Get Details
57+ </ button >
58+ </ div >
59+ ) ;
60+ }
0 commit comments