Skip to content

Commit 3d9e884

Browse files
Yushin-Lclaude
andcommitted
Add parent comment quote preview on all reply depths
- Show truncated parent comment body with author name above each reply - Helps identify which comment a reply is responding to, especially at deeper nesting levels where indentation caps out Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent c976584 commit 3d9e884

2 files changed

Lines changed: 40 additions & 18 deletions

File tree

src/components/comments/CommentItem.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ interface CommentItemProps {
1010
currentUserId: string | null;
1111
isAdmin: boolean;
1212
depth: number;
13+
parentAuthorName?: string | null;
14+
parentBody?: string | null;
1315
onEdit: (commentId: string, body: string) => Promise<unknown>;
1416
onDelete: (commentId: string) => Promise<unknown>;
1517
onReply: (body: string, parentId: string) => Promise<unknown>;
@@ -23,6 +25,8 @@ export default function CommentItem({
2325
currentUserId,
2426
isAdmin,
2527
depth,
28+
parentAuthorName,
29+
parentBody,
2630
onEdit,
2731
onDelete,
2832
onReply,
@@ -52,6 +56,12 @@ export default function CommentItem({
5256

5357
return (
5458
<div className={`py-4 ${depth > 0 ? "border-l-2 border-zinc-100 pl-4 dark:border-zinc-800" : ""}`} style={depth > 0 ? { marginLeft: `${Math.min(depth, MAX_INDENT) * 1.5}rem` } : undefined}>
59+
{depth > 0 && parentAuthorName && parentBody && (
60+
<div className="mb-2 flex items-start gap-1.5 rounded-md bg-stone-100/60 px-3 py-1.5 text-xs text-stone-500">
61+
<span className="shrink-0 font-medium text-stone-600">{parentAuthorName}:</span>
62+
<span className="line-clamp-1">{parentBody}</span>
63+
</div>
64+
)}
5565
<div className="flex items-center gap-2 text-sm">
5666
<span className="font-medium">
5767
{authorProfile?.display_name ?? "알 수 없음"}

src/components/comments/CommentSection.tsx

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -49,27 +49,39 @@ export default function CommentSection({ postSlug }: CommentSectionProps) {
4949
return comments.filter((c) => c.parent_id === parentId);
5050
}
5151

52+
function getCommentById(id: string) {
53+
return comments.find((c) => c.id === id) ?? null;
54+
}
55+
5256
function renderThread(parentId: string, depth: number) {
5357
const children = getChildren(parentId);
5458
if (children.length === 0) return null;
55-
return children.map((child) => (
56-
<div key={child.id}>
57-
<CommentItem
58-
comment={child}
59-
authorProfile={profiles[child.user_id] ?? null}
60-
currentUserId={user?.id ?? null}
61-
isAdmin={isAdmin}
62-
depth={depth}
63-
onEdit={edit}
64-
onDelete={remove}
65-
onReply={async (body, pid) => {
66-
if (!user) return;
67-
await add(user.id, body, pid);
68-
}}
69-
/>
70-
{renderThread(child.id, depth + 1)}
71-
</div>
72-
));
59+
return children.map((child) => {
60+
const parent = child.parent_id ? getCommentById(child.parent_id) : null;
61+
const parentAuthorName = parent
62+
? (profiles[parent.user_id]?.display_name ?? "알 수 없음")
63+
: null;
64+
return (
65+
<div key={child.id}>
66+
<CommentItem
67+
comment={child}
68+
authorProfile={profiles[child.user_id] ?? null}
69+
currentUserId={user?.id ?? null}
70+
isAdmin={isAdmin}
71+
depth={depth}
72+
parentAuthorName={parentAuthorName}
73+
parentBody={parent?.body ?? null}
74+
onEdit={edit}
75+
onDelete={remove}
76+
onReply={async (body, pid) => {
77+
if (!user) return;
78+
await add(user.id, body, pid);
79+
}}
80+
/>
81+
{renderThread(child.id, depth + 1)}
82+
</div>
83+
);
84+
});
7385
}
7486

7587
return (

0 commit comments

Comments
 (0)