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} +