@@ -8,10 +8,24 @@ import { Button } from "@/components/ui/button";
88import { twMerge } from "tailwind-merge" ;
99import { likeArtist } from "@/lib/artists/artists" ;
1010import { toast } from "sonner" ;
11+ import React from "react" ;
12+
13+ // TODO:
14+ // - 아티스트 좋아요(팔로우) 상태를 서버에서 함께 내려받아 초기 상태로 관리해야 함
15+ // - 좋아요 상태에 따라 하트 아이콘을 빨간색(fill-red-500)으로 표시
16+ // - 이미 좋아요된 상태에서 버튼 클릭 시 좋아요 취소(unlike) API 호출하도록 분기 처리
17+ // - 좋아요/취소 시 optimistic update 적용 검토
1118
1219export default function ArtistListItems ( { artists } : { artists : ArtistListItem [ ] } ) {
13- const handleLike = async ( id : number ) => {
20+ // TODO:
21+ // - 현재는 likeArtist만 호출 중
22+ // - 추후 isLiked 상태에 따라
23+ // - true -> unlikeArtist(id) 호출
24+ // - false -> likeArtist(id) 호출
25+ // - 서버에서 내려주는 msg에 따라 toast 메시지 분기 처리
26+ const likeArtistAction = async ( id : number ) => {
1427 try {
28+ // TODO: isLiked 상태에 따라 like / unlike 분기 필요
1529 await likeArtist ( id ) ;
1630 toast . success ( "아티스트를 좋아요 했어요!" ) ;
1731 } catch ( err ) {
@@ -22,12 +36,23 @@ export default function ArtistListItems({ artists }: { artists: ArtistListItem[]
2236 }
2337 }
2438 } ;
39+
40+ const handleLikeClick = async ( e : React . MouseEvent < HTMLButtonElement > , id : number ) => {
41+ e . preventDefault ( ) ;
42+ e . stopPropagation ( ) ;
43+
44+ // TODO:
45+ // - 중복 클릭 방지를 위한 loading 상태 추가
46+ // - 요청 중에는 버튼 disabled 처리
47+ await likeArtistAction ( id ) ;
48+ } ;
49+
2550 return (
2651 < div className = "grid gap-x-8 gap-y-12 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-5" >
2752 { artists . map ( ( artist ) => (
2853 < Link
2954 key = { artist . id }
30- href = { `/concerts /${ artist . id } ` }
55+ href = { `/artists /${ artist . id } ` }
3156 className = "group flex flex-col gap-5 transition hover:opacity-90"
3257 >
3358 < div className = "border-border/60 relative aspect-square overflow-hidden rounded-lg border" >
@@ -39,19 +64,17 @@ export default function ArtistListItems({ artists }: { artists: ArtistListItem[]
3964 className = "object-cover"
4065 />
4166 < Button
42- onClick = { async ( e ) => {
43- e . preventDefault ( ) ;
44- e . stopPropagation ( ) ;
45- await handleLike ( artist . id ) ;
46- } }
67+ onClick = { ( e ) => handleLikeClick ( e , artist . id ) }
4768 type = "button"
4869 aria-label = "아티스트 좋아요"
4970 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"
5071 >
5172 < Heart
5273 className = { twMerge (
53- "h-5 w-5 fill-white text-white transition" ,
54- artist . id % 2 === 0 && "fill-red-500 text-red-500"
74+ "h-5 w-5 transition" ,
75+ // TODO: isLiked === true 일 때 fill-red-500 text-red-500 적용
76+ // TODO: isLiked === false 일 때 fill-white text-white 적용
77+ "fill-white text-white"
5578 ) }
5679 strokeWidth = { 0 }
5780 />
0 commit comments