Skip to content

Commit 8b22a45

Browse files
committed
refactor: apply PR review comments (style props, performance optimization)
1 parent 77b905b commit 8b22a45

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

apps/blog/web/src/components/home/PostCard.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ interface PostCardProps {
88
}
99

1010
export function PostCard({ post, rank }: PostCardProps) {
11+
const rankStyleProps =
12+
rank === 1
13+
? { bg: 'yellow.100', color: 'yellow.700' }
14+
: rank === 2
15+
? { bg: 'gray.100', color: 'gray.700' }
16+
: { bg: 'orange.100', color: 'orange.700' };
17+
1118
return (
1219
<Link
1320
href={`/posts/${post.slug}`}
@@ -37,18 +44,17 @@ export function PostCard({ post, rank }: PostCardProps) {
3744
w: '8',
3845
h: '8',
3946
rounded: 'full',
40-
bg: rank === 1 ? 'yellow.100' : rank === 2 ? 'gray.100' : 'orange.100',
41-
color: rank === 1 ? 'yellow.700' : rank === 2 ? 'gray.700' : 'orange.700',
4247
fontWeight: 'bold',
4348
fontSize: 'sm',
49+
...rankStyleProps,
4450
})}
4551
>
4652
{rank}
4753
</span>
4854
)}
4955
{post.date && (
5056
<time className={css({ fontSize: 'sm', color: 'gray.400' })}>
51-
{new Date(post.date).toLocaleDateString()}
57+
{new Date(post.date).toLocaleDateString('ko-KR')}
5258
</time>
5359
)}
5460
</div>

apps/blog/web/src/components/home/TopPosts.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,11 @@ export function TopPosts({ posts }: TopPostsProps) {
3232
return;
3333
}
3434

35+
const postsBySlug = new Map(posts.map(p => [p.slug, p]));
36+
3537
const rankedPosts = data
3638
.map(view => {
37-
const post = posts.find(p => p.slug === view.slug);
39+
const post = postsBySlug.get(view.slug);
3840
if (!post) return null;
3941
return { ...post, viewCount: view.view_count };
4042
})

0 commit comments

Comments
 (0)