|
1 | | -import { Avatar, AvatarFallback } from "@/components/ui/avatar"; |
| 1 | +import PostAvatar from "@/components/common/Card/PostAvatar"; |
| 2 | +import PostTag from "@/components/common/Card/PostTag"; |
2 | 3 | import { CardContent } from "@/components/ui/card"; |
3 | 4 |
|
4 | 5 | import { formatDate } from "@/utils/date"; |
5 | 6 |
|
6 | 7 | import { useMediaStore } from "@/store/useMediaStore"; |
7 | 8 | import { Post } from "@/types/post"; |
8 | 9 |
|
9 | | -const isValidPlatform = (platform: string): boolean => { |
10 | | - const validPlatforms = ["tistory", "velog", "medium"]; |
11 | | - return validPlatforms.includes(platform); |
12 | | -}; |
13 | 10 | interface PostCardContentProps { |
14 | 11 | post: Post; |
15 | 12 | } |
16 | 13 |
|
17 | 14 | export const PostCardContent = ({ post }: PostCardContentProps) => { |
18 | 15 | const isMobile = useMediaStore((state) => state.isMobile); |
19 | | - |
20 | 16 | return isMobile ? <MobileCardContent post={post} /> : <DesktopCardContent post={post} />; |
21 | 17 | }; |
22 | 18 |
|
23 | 19 | const MobileCardContent = ({ post }: PostCardContentProps) => { |
24 | | - const authorInitial = post.author?.charAt(0)?.toUpperCase() || "?"; |
25 | | - |
26 | 20 | return ( |
27 | 21 | <CardContent className="p-0"> |
28 | 22 | <div className="flex items-center ml-4 mb-3 gap-3"> |
29 | | - <Avatar className="h-8 w-8 ring-2 ring-background cursor-pointer"> |
30 | | - {isValidPlatform(post.blogPlatform) ? ( |
31 | | - <img |
32 | | - src={`https://denamu.site/files/${post.blogPlatform}-icon.svg`} |
33 | | - alt={post.author} |
34 | | - className="w-full h-full" |
35 | | - /> |
36 | | - ) : ( |
37 | | - <AvatarFallback className="text-xs bg-slate-200">{authorInitial}</AvatarFallback> |
38 | | - )} |
39 | | - </Avatar> |
| 23 | + <PostAvatar |
| 24 | + blogPlatform={post.blogPlatform} |
| 25 | + className="h-8 w-8 ring-2 ring-background cursor-pointer" |
| 26 | + author={post.author} |
| 27 | + /> |
40 | 28 | <p className="font-bold text-sm">{post.author}</p> |
41 | 29 | </div> |
42 | 30 | <div className="px-4 pb-4"> |
43 | 31 | <p className="h-[48px] font-bold text-md group-hover:text-primary transition-colors line-clamp-2"> |
44 | 32 | {post.title} |
45 | 33 | </p> |
| 34 | + {post.tag && <PostTag tags={post.tag} />} |
| 35 | + |
46 | 36 | <p className="text-[12px] text-gray-400 pt-2">{formatDate(post.createdAt)}</p> |
47 | 37 | </div> |
48 | 38 | </CardContent> |
49 | 39 | ); |
50 | 40 | }; |
51 | 41 |
|
52 | 42 | const DesktopCardContent = ({ post }: PostCardContentProps) => { |
53 | | - const authorInitial = post.author?.charAt(0)?.toUpperCase() || "?"; |
54 | | - |
55 | 43 | return ( |
56 | 44 | <CardContent className="p-0"> |
57 | | - <div className="relative -mt-6 ml-4 mb-3"> |
58 | | - <Avatar className="h-8 w-8 ring-2 ring-background cursor-pointer"> |
59 | | - {isValidPlatform(post.blogPlatform) ? ( |
60 | | - <img |
61 | | - src={`https://denamu.site/files/${post.blogPlatform}-icon.svg`} |
62 | | - alt={post.author} |
63 | | - className="w-full h-full" |
64 | | - /> |
65 | | - ) : ( |
66 | | - <AvatarFallback className="text-xs bg-slate-200">{authorInitial}</AvatarFallback> |
67 | | - )} |
68 | | - </Avatar> |
| 45 | + <div className="relative -mt-4 ml-4 mb-3"> |
| 46 | + <PostAvatar |
| 47 | + blogPlatform={post.blogPlatform} |
| 48 | + className="h-8 w-8 ring-2 ring-background cursor-pointer" |
| 49 | + author={post.author} |
| 50 | + /> |
69 | 51 | </div> |
70 | 52 | <div className="px-4 pb-4"> |
71 | 53 | <p className="font-bold text-xs text-gray-400 pb-1 line-clamp-1">{post.author}</p> |
72 | 54 | <p className="h-[40px] font-bold text-sm group-hover:text-primary transition-colors line-clamp-2"> |
73 | 55 | {post.title} |
74 | 56 | </p> |
75 | 57 | <p className="text-[10px] text-gray-400 pt-2">{formatDate(post.createdAt)}</p> |
| 58 | + {post.tag && <PostTag tags={post.tag} />} |
76 | 59 | </div> |
77 | 60 | </CardContent> |
78 | 61 | ); |
|
0 commit comments