From 40f01a77122876a9b9a4df4ce76b278033fb3dce Mon Sep 17 00:00:00 2001 From: Marcel Date: Thu, 26 Mar 2026 12:42:39 +0100 Subject: [PATCH] refactor(comments): extract commentEntry snippet to remove duplicated markup The root-comment and reply rendering blocks were near-identical (view mode with author/time/edit-delete, and edit mode with textarea/save/cancel). Extracted a local {#snippet commentEntry(comment, threadId, showReplyButton)} that handles both states, introducing Svelte 5 snippets to the codebase. Co-Authored-By: Claude Sonnet 4.6 --- .../src/lib/components/CommentThread.svelte | 213 +++++++----------- 1 file changed, 77 insertions(+), 136 deletions(-) diff --git a/frontend/src/lib/components/CommentThread.svelte b/frontend/src/lib/components/CommentThread.svelte index 775f1ef6..3e6f6218 100644 --- a/frontend/src/lib/components/CommentThread.svelte +++ b/frontend/src/lib/components/CommentThread.svelte @@ -189,154 +189,95 @@ onMount(() => { }); + +{#snippet commentEntry(comment: Comment | CommentReply, threadId: string, showReplyButton: boolean)} + {#if editingId === comment.id} +
+ +
+ + +
+
+ {:else} +
+
+
+ {comment.authorName} + {timeAgo(comment.createdAt)} + {#if wasEdited(comment)} + + {m.comment_edited_label()} + {timeAgo(comment.updatedAt)} + + {/if} +
+

{comment.content}

+
+ {#if canModify(comment)} +
+ + +
+ {/if} +
+ {#if showReplyButton && canComment} +
+ +
+ {/if} + {/if} +{/snippet} +
{#each comments as thread, ti (thread.id)}
0 ? 'border-t border-line pt-4' : ''}>
- {#if editingId === thread.id} -
- -
- - -
-
- {:else} -
-
-
- {thread.authorName} - {timeAgo(thread.createdAt)} - {#if wasEdited(thread)} - - {m.comment_edited_label()} - {timeAgo(thread.updatedAt)} - - {/if} -
-

{thread.content}

-
- {#if canModify(thread)} -
- - -
- {/if} -
- - {#if thread.replies.length === 0 && canComment} -
- -
- {/if} - {/if} + {@render commentEntry(thread, thread.id, thread.replies.length === 0)}
{#each thread.replies as reply, ri (reply.id)}
- {#if editingId === reply.id} -
- -
- - -
-
- {:else} -
-
-
- {reply.authorName} - {timeAgo(reply.createdAt)} - {#if wasEdited(reply)} - - {m.comment_edited_label()} - {timeAgo(reply.updatedAt)} - - {/if} -
-

{reply.content}

-
- {#if canModify(reply)} -
- - -
- {/if} -
- - {#if ri === thread.replies.length - 1 && canComment} -
- -
- {/if} - {/if} + {@render commentEntry(reply, thread.id, ri === thread.replies.length - 1)}
{/each} - + {#if replyingTo === thread.id}