From 52faf16837e5be56584a746f6fa99479b6648d74 Mon Sep 17 00:00:00 2001 From: Face <69168154+face-hh@users.noreply.github.com> Date: Sun, 8 Jun 2025 21:20:13 +0300 Subject: [PATCH] comment expansion --- .../lib/components/self/CommentSection.svelte | 49 ++++++++++++++++--- 1 file changed, 43 insertions(+), 6 deletions(-) diff --git a/website/src/lib/components/self/CommentSection.svelte b/website/src/lib/components/self/CommentSection.svelte index a2c89d1..d7af7d6 100644 --- a/website/src/lib/components/self/CommentSection.svelte +++ b/website/src/lib/components/self/CommentSection.svelte @@ -21,8 +21,10 @@ let isSubmitting = $state(false); let isLoading = $state(true); let shouldSignIn = $state(false); + let expandedComments = $state(new Set()); const MAX_COMMENTS = 50; + const MAX_LINES_PREVIEW = 3; $effect(() => { websocketController.setCoin(coinSymbol); @@ -147,6 +149,25 @@ toggleLike(commentId); } + function toggleCommentExpansion(commentId: number) { + if (expandedComments.has(commentId)) { + expandedComments.delete(commentId); + } else { + expandedComments.add(commentId); + } + expandedComments = new Set(expandedComments); + } + + function shouldTruncateComment(content: string): boolean { + const lines = content.split('\n'); + return lines.length > MAX_LINES_PREVIEW; + } + + function getTruncatedContent(content: string): string { + const lines = content.split('\n'); + return lines.slice(0, MAX_LINES_PREVIEW).join('\n'); + } + $effect(() => { loadComments(); }); @@ -216,6 +237,11 @@ {:else}
{#each comments as comment (comment.id)} + {@const isExpanded = expandedComments.has(comment.id)} + {@const shouldTruncate = shouldTruncateComment(comment.content)} + {@const displayContent = + shouldTruncate && !isExpanded ? getTruncatedContent(comment.content) : comment.content} +
-

- {comment.content} -

+
+

+ {displayContent} +

+ + {#if shouldTruncate} + + {/if} +