-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathMovieCard.jsx
More file actions
89 lines (85 loc) · 2.75 KB
/
Copy pathMovieCard.jsx
File metadata and controls
89 lines (85 loc) · 2.75 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import { memo, useState } from "react";
import { useNavigate } from "react-router-dom";
import styled from "styled-components";
import { IMAGE_BASE_URL } from "../constant/imageBaseUrl";
import FavoriteButton from "./FavoriteButton";
const CardContainer = styled(({ isSwiper, ...rest }) => <div {...rest} />)`
cursor: pointer;
.movie-poster {
overflow: hidden;
width: 100%;
position: relative;
padding-bottom: calc((360 / 240) * 100%);
img {
position: absolute;
top: 0;
}
}
`;
export const MovieCard = memo((props) => {
const {
title,
vote_average,
backdrop_path,
poster_path,
release_date,
id: movieId,
isSwiper = false,
pageType,
onImageLoad,
} = props;
const [isLoaded, setIsLoaded] = useState(false);
const navigate = useNavigate();
const handleToDetail = () => {
window.scrollTo({ top: 0, behavior: "auto" });
navigate(`/detail/${movieId}`);
};
return (
<CardContainer onClick={handleToDetail} isSwiper={isSwiper}>
<div className="movie-poster ">
<img
src={
isSwiper
? `${IMAGE_BASE_URL.backdrop}${backdrop_path}}`
: `${IMAGE_BASE_URL.poster}${poster_path}`
}
alt={title}
onLoad={() => {
setIsLoaded(true);
onImageLoad?.(); // ✅ Main에게 알림
}}
style={{
visibility: isLoaded ? "visible" : "hidden",
width: "100%",
height: "100%",
}}
className="hover:scale-105 transition-transform"
/>
{isSwiper ? null : (
<FavoriteButton movieId={movieId} movieData={props} />
)}
</div>
{isSwiper || pageType ? null : (
<div className="flex flex-col gap-[15px] items-start pt-[15px] max-[768px]:hidden">
<h2
className={`${title} ? leading-none font-[500] text-[20px] text-left min-h-[20px]
max-[1700px]:text-[18px] max-[1024px]:text-[1rem] max-[820px]:text-[16px]
max-[420px]:text-[16px]
max-[1700px]:h-[18px] max-[1024px]:h-[1rem] max-[820px]:h-[16px] max-[420px]:h-[16px]
`}
>
{title}
</h2>
<p className="flex justify-between w-full leading-none text-[gray]">
<span className="text-[18px] max-[1700px]:text-[16px] max-[820px]:text-[14px] max-[420px]:text-[14px]">
{release_date ? release_date.slice(0, 4) : "개봉일 미정"}
</span>
<span className="movie-rating flex gap-[5px] text-[18px] max-[1700px]:text-[16px] max-[820px]:text-[14px] max-[420px]:text-[14px]">
{Number(vote_average).toFixed(1)}
</span>
</p>
</div>
)}
</CardContainer>
);
});