1+ "use client" ;
2+
13import Link from "next/link" ;
24import { ArtistListItem } from "@/types/artists" ;
35import Image from "next/image" ;
46import { Heart } from "lucide-react" ;
57import { Button } from "@/components/ui/button" ;
6-
7- {
8- /*TODO: 나중에 바로 아래 div에서 api로 불러온 콘서트 목록 map으로 돌리기*/
9- }
8+ import { twMerge } from "tailwind-merge" ;
9+ import { likeArtist } from "@/lib/artists/artists" ;
10+ import { toast } from "sonner" ;
1011
1112export default function ArtistListItems ( { artists } : { artists : ArtistListItem [ ] } ) {
13+ const handleLike = async ( id : number ) => {
14+ try {
15+ await likeArtist ( id ) ;
16+ toast . success ( "아티스트를 좋아요 했어요!" ) ;
17+ } catch ( err ) {
18+ if ( err instanceof Error ) {
19+ toast . error ( err . message ) ;
20+ } else {
21+ toast . error ( "알 수 없는 오류가 발생했습니다." ) ;
22+ }
23+ }
24+ } ;
1225 return (
13- < div className = "grid grid-cols-5 gap-x-8 gap-y-12" >
26+ < div className = "grid gap-x-8 gap-y-12 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-5 " >
1427 { artists . map ( ( artist ) => (
1528 < Link
1629 key = { artist . id }
1730 href = { `/concerts/${ artist . id } ` }
18- className = "flex cursor-pointer flex-col gap-5"
31+ className = "group flex flex-col gap-5 transition hover:opacity-90 "
1932 >
20- < div className = "relative aspect-square w-full overflow-hidden rounded-lg border" >
33+ < div className = "border-border/60 relative aspect-square overflow-hidden rounded-lg border" >
2134 < Image
2235 src = { artist . imageUrl || "/images/artist-placeholder.png" }
2336 alt = "Concert Poster"
@@ -26,11 +39,22 @@ export default function ArtistListItems({ artists }: { artists: ArtistListItem[]
2639 className = "object-cover"
2740 />
2841 < Button
42+ onClick = { async ( e ) => {
43+ e . preventDefault ( ) ;
44+ e . stopPropagation ( ) ;
45+ await handleLike ( artist . id ) ;
46+ } }
2947 type = "button"
3048 aria-label = "아티스트 좋아요"
31- className = "absolute top-2 right-2 z-10 h-10 w-10 cursor-pointer rounded-full bg-black/50 opacity-80 backdrop-blur-sm"
49+ className = "absolute top-2 right-2 h-9 w-9 scale-90 rounded-full bg-black/20 opacity-0 backdrop-blur-sm transition-all duration-200 group-hover:scale-100 group-hover:opacity-100 "
3250 >
33- < Heart />
51+ < Heart
52+ className = { twMerge (
53+ "h-5 w-5 fill-white text-white transition" ,
54+ artist . id % 2 === 0 && "fill-red-500 text-red-500"
55+ ) }
56+ strokeWidth = { 0 }
57+ />
3458 </ Button >
3559 </ div >
3660 < strong className = "line-clamp-1 text-2xl" > { artist . artistName } </ strong >
0 commit comments