File size: 1,362 Bytes
03769d0 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
import { useEffect, useState } from 'react';
import Image from 'next/image';
import apiClient from '@/api/apiClient';
import SkeletonLoader from '@/skeletons/movieCard';
import './MovieCard.css';
const MovieCard = ({ title }) => {
const [movieData, setMovieData] = useState(null);
const [loading, setLoading] = useState(true);
const [error, setError] = useState(null);
useEffect(() => {
const fetchMovieData = async () => {
try {
const data = await apiClient.getMovieCard(title);
setMovieData(data);
} catch (err) {
setError(err.message);
} finally {
setLoading(false);
}
};
fetchMovieData();
}, [title]);
if (loading) {
return <SkeletonLoader />;
}
if (error) {
return <div className="error">Error: {error}</div>;
}
return (
<div className="movie-card">
<div className="image-container">
<Image
src={movieData.image}
alt={`${movieData.title} poster`}
fill
sizes="(max-width: 768px) 100vw, (max-width: 1200px) 50vw, 33vw"
priority
className="poster"
/>
</div>
<div className="movie-info">
<h3 className="movie-title">{movieData.title}</h3>
<p className="movie-year">{movieData.year}</p>
</div>
</div>
);
};
export default MovieCard;
|