style: improve comments overall styling

This commit is contained in:
2026-06-21 23:24:15 -04:00
parent 6cadc0b74d
commit 1bfc5dbbc4
3 changed files with 98 additions and 61 deletions
@@ -5,7 +5,7 @@
import { escapeHtml } from '$lib/utils/html';
import { user } from '$lib/stores/user';
import PasteCommentItem from '$lib/components/PasteCommentItem.svelte';
import { ThumbsUp, ThumbsDown, Trash2, Shredder } from '@lucide/svelte';
import { ThumbsUp, ThumbsDown, Trash2, Shredder, Reply, Quote } from '@lucide/svelte';
import { resolve } from '$app/paths';
import RichTextEditor from './RichTextEditor.svelte';
import { hasRole, roles } from '$lib/utils/auth';
@@ -93,9 +93,9 @@
}
</script>
<div class="p-3">
<div class="rounded border border-transparent p-3">
<div class="mb-2 flex items-center justify-between gap-3 text-xs text-neutral-400">
<div class="flex min-w-0 items-center gap-2 text-lg">
<div class="flex min-w-0 items-center gap-2 text-sm">
{#if node.author}
{#if node.author.isBanned}
<span class="text-red-500">BANNED</span>
@@ -113,7 +113,7 @@
{/if}
{#if node.updatedAt}
<span
class="text-sm text-neutral-500"
class="text-xs text-neutral-400"
use:tooltip={`Edited on ${new Date(node.updatedAt * 1000).toLocaleString()} • ${dateToRelativeString(new Date(node.updatedAt * 1000), true, true, now, 3)}`}
>edited</span
>
@@ -127,7 +127,7 @@
</div>
<div class="text-sm leading-relaxed text-neutral-200">
<div class="wrap-break-word" class:italic={isDeleted} class:text-neutral-800={isDeleted}>
<div class="wrap-break-word" class:italic={isDeleted} class:text-neutral-500={isDeleted}>
{#if expanded || !isLongComment}
<!-- eslint-disable-next-line svelte/no-at-html-tags -->
{@html parsedHtml}
@@ -151,54 +151,53 @@
{/if}
</div>
<div class="mt-3 flex flex-wrap items-center gap-2">
<div class="mt-3 flex flex-wrap items-center gap-1.5">
<button
type="button"
class="h-7 min-w-12 rounded border px-2 py-1 text-xs {node.userReaction !== 1
? 'hover:bg-neutral-800 active:bg-neutral-700'
: 'hover:bg-green-800 active:bg-green-700'} disabled:cursor-not-allowed disabled:hover:bg-transparent"
class="flex h-7 min-w-10 items-center justify-center gap-1 rounded px-2 text-xs {node.userReaction !==
1
? 'text-neutral-300 hover:bg-neutral-700 hover:text-neutral-100 active:bg-neutral-600'
: 'bg-green-950 text-green-200 hover:bg-green-900 active:bg-green-800'} disabled:cursor-not-allowed disabled:hover:bg-transparent"
class:border-green-700={node.userReaction === 1}
class:bg-green-900={node.userReaction === 1}
class:text-green-200={node.userReaction === 1}
class:border-neutral-700={node.userReaction !== 1}
class:text-neutral-300={node.userReaction !== 1}
onclick={() => onReact(node.id, 1, node.userReaction)}
disabled={reactingIds[node.id] || !$user}
aria-label="Like comment"
title="Like"
>
<ThumbsUp class="mr-1 inline h-3.5 w-3.5" />
<ThumbsUp class="h-3.5 w-3.5" />
{node.likes}
</button>
<button
type="button"
class="h-7 min-w-12 rounded border px-2 py-1 text-xs {node.userReaction !== 2
? 'hover:bg-neutral-800 active:bg-neutral-700'
: 'hover:bg-red-800 active:bg-red-700'} disabled:cursor-not-allowed disabled:hover:bg-transparent"
class="flex h-7 min-w-10 items-center justify-center gap-1 rounded px-2 text-xs {node.userReaction !==
2
? 'text-neutral-300 hover:bg-neutral-700 hover:text-neutral-100 active:bg-neutral-600'
: 'bg-red-950 text-red-200 hover:bg-red-900 active:bg-red-800'} disabled:cursor-not-allowed disabled:hover:bg-transparent"
class:border-red-700={node.userReaction === 2}
class:bg-red-900={node.userReaction === 2}
class:text-red-200={node.userReaction === 2}
class:border-neutral-700={node.userReaction !== 2}
class:text-neutral-300={node.userReaction !== 2}
onclick={() => onReact(node.id, 2, node.userReaction)}
disabled={reactingIds[node.id] || !$user}
aria-label="Dislike comment"
title="Dislike"
>
<ThumbsDown class="mr-1 inline h-3.5 w-3.5" />
<ThumbsDown class="h-3.5 w-3.5" />
{node.dislikes}
</button>
{#if $user}
{#if !replyOpen}
<button
type="button"
class="h-7 min-w-12 rounded border border-neutral-700 px-2 py-1 text-xs text-neutral-300 hover:bg-neutral-800 hover:text-neutral-100 active:bg-neutral-700"
class="flex h-7 items-center gap-1 rounded px-2 text-xs text-neutral-300 hover:bg-neutral-700 hover:text-neutral-100 active:bg-neutral-600"
onclick={() => {
openReply(node.content ? `> ${node.content.replace(/\n/g, '\n> ')}\n\n` : '');
}}
>
<Quote class="h-3.5 w-3.5" />
Quote
</button>
{/if}
<button
type="button"
class="h-7 min-w-12 rounded border border-neutral-700 px-2 py-1 text-xs text-neutral-300 hover:bg-neutral-800 hover:text-neutral-100 active:bg-neutral-700"
class="flex h-7 items-center gap-1 rounded px-2 text-xs text-neutral-300 hover:bg-neutral-700 hover:text-neutral-100 active:bg-neutral-600"
onclick={() => {
if (replyOpen) {
replyOpen = false;
@@ -209,26 +208,31 @@
openReply('');
}}
>
<Reply class="h-3.5 w-3.5" />
{replyOpen ? 'Cancel' : 'Reply'}
</button>
{#if node.author?.uuid === $user.uuid || hasRole($user.roles, 4) || hasRole($user.roles, 2)}
<div class="ml-auto">
<div class="ml-auto flex items-center gap-1">
<button
type="button"
class="h-7 rounded border border-neutral-700 px-2 py-1 text-xs text-neutral-300 hover:bg-neutral-800 hover:text-neutral-100 active:bg-neutral-700"
class="flex h-7 w-7 items-center justify-center rounded text-neutral-300 hover:bg-neutral-700 hover:text-neutral-100 active:bg-neutral-600"
onclick={() => handleDelete(false)}
disabled={deleting}
aria-label="Delete comment"
title="Delete"
>
<Trash2 class="inline h-3.5 w-3.5" />
<Trash2 class="h-3.5 w-3.5" />
</button>
{#if hasRole($user.roles, roles.Moderator) || hasRole($user.roles, roles.Admin)}
<button
type="button"
class="h-7 rounded border border-neutral-700 px-2 py-1 text-xs text-neutral-300 hover:bg-neutral-800 hover:text-neutral-100 active:bg-neutral-700"
class="flex h-7 w-7 items-center justify-center rounded text-neutral-300 hover:bg-neutral-700 hover:text-neutral-100 active:bg-neutral-600"
onclick={() => handleDelete(true)}
disabled={deleting}
aria-label="Hard delete comment"
title="Hard delete"
>
<Shredder class="inline h-3.5 w-3.5" />
<Shredder class="h-3.5 w-3.5" />
</button>
{/if}
</div>
@@ -245,6 +249,9 @@
onSubmit={submitReply}
disabled={replySubmitting}
submitting={replySubmitting}
submitLabel="Reply"
submittingLabel="Replying..."
compact
/>
{#if replyError}
<p class="mt-2 text-xs text-red-400">{replyError}</p>
@@ -252,7 +259,7 @@
{/if}
{#if node.children.length > 0}
<div class="mt-3 border-l border-neutral-800 pl-3">
<div class="mt-3 border-l border-neutral-700 pl-3">
{#if depth >= 3 && !showDeepReplies}
<button
type="button"
@@ -12,6 +12,7 @@
import { SvelteMap } from 'svelte/reactivity';
import RichTextEditor from './RichTextEditor.svelte';
import { openModal } from '$lib/stores/modal';
import { RefreshCw } from '@lucide/svelte';
interface Props {
pasteId: string;
@@ -236,29 +237,41 @@
}
</script>
<section id="comments-section" class="mt-6 rounded border border-neutral-800 p-4">
<section id="comments-section" class="mt-6 rounded border border-neutral-700 bg-neutral-900 p-4">
<div class="mb-4 flex flex-wrap items-center justify-between gap-3">
<h2 class="text-xl font-semibold text-neutral-100">Comments ({comments.length})</h2>
<div class="flex items-center gap-2">
<h2 class="text-lg font-semibold text-neutral-100">Comments</h2>
<span
class="rounded border border-neutral-700 bg-neutral-800 px-2 py-0.5 text-xs text-neutral-300"
>
{comments.length}
</span>
</div>
<button
type="button"
class="rounded border border-neutral-700 px-2 py-1 text-xs text-neutral-300 hover:text-neutral-100"
class="flex h-8 items-center gap-2 rounded px-2 text-xs text-neutral-300 hover:bg-neutral-800 hover:text-neutral-100 disabled:cursor-not-allowed disabled:text-neutral-500"
onclick={refreshComments}
disabled={loading}
aria-label="Refresh comments"
>
{loading ? 'Refreshing...' : 'Refresh'}
<RefreshCw class="h-3.5 w-3.5 {loading ? 'animate-spin' : ''}" />
{loading ? 'Refreshing' : 'Refresh'}
</button>
</div>
{#if $user}
<div class="mb-5">
<RichTextEditor
bind:value={newComment}
placeholder="Write a comment..."
placeholder="Add a comment..."
onSubmit={submitTopLevelComment}
disabled={posting}
submitting={posting}
compact
/>
</div>
{:else}
<div class="mb-4 rounded border border-neutral-800 p-3 text-sm text-neutral-400">
<div class="mb-4 rounded border border-neutral-700 bg-neutral-800 p-3 text-sm text-neutral-300">
Sign in to post comments and reactions.
</div>
{/if}
@@ -270,15 +283,15 @@
{/if}
{#if loading && comments.length === 0}
<div class="rounded border border-neutral-800 p-3 text-sm text-neutral-400">
<div class="rounded border border-neutral-700 bg-neutral-800 p-3 text-sm text-neutral-300">
Loading comments...
</div>
{:else if threadedComments.length === 0}
<div class="rounded border border-neutral-800 p-3 text-sm text-neutral-400">
<div class="rounded border border-neutral-700 bg-neutral-800 p-3 text-sm text-neutral-300">
No comments yet.
</div>
{:else}
<div class="space-y-3">
<div class="space-y-2">
{#each threadedComments as node (node.id)}
<PasteCommentItem
{node}
@@ -1,5 +1,5 @@
<script lang="ts">
import { Bold, Italic, CodeXml, Quote } from '@lucide/svelte';
import { Bold, Italic, CodeXml, Quote, Send, Eye, Pencil } from '@lucide/svelte';
import { parseCommentMarkdown } from '$lib/utils/markdown';
interface Props {
@@ -8,6 +8,7 @@
placeholder?: string;
disabled?: boolean;
submitting?: boolean;
compact?: boolean;
submitLabel?: string;
submittingLabel?: string;
onSubmit?: (value: string) => void | Promise<void>;
@@ -19,6 +20,7 @@
placeholder = 'Write a comment...',
disabled = false,
submitting = false,
compact = false,
submitLabel = 'Post comment',
submittingLabel = 'Posting...',
onSubmit
@@ -30,6 +32,7 @@
const isDisabled = $derived(disabled || submitting);
const canSubmit = $derived(!isDisabled && value.trim().length > 0);
const parsedHtml = $derived(parseCommentMarkdown(value));
const editorMinHeight = $derived(compact ? 'min-h-20' : 'min-h-24');
function focusEditor() {
editor?.focus();
@@ -133,11 +136,13 @@
}
</script>
<div class="mb-4 flex flex-col rounded {className}">
<div
class="mb-4 overflow-hidden rounded border border-neutral-700 bg-neutral-900 shadow-sm {className}"
>
{#if mode === 'raw'}
<textarea
bind:this={editor}
class="min-h-24 w-full rounded-t border border-b-0 border-neutral-700 bg-neutral-900 p-2 font-mono text-sm text-neutral-100 outline-none"
class="{editorMinHeight} w-full resize-y border-0 bg-neutral-900 p-3 font-mono text-sm text-neutral-100 placeholder:text-neutral-400 focus:bg-neutral-800/60"
{placeholder}
maxlength={5000}
disabled={isDisabled}
@@ -145,11 +150,9 @@
onkeydown={handleKeydown}
></textarea>
{:else}
<div
class="min-h-24 w-full rounded-t border border-b-0 border-neutral-700 bg-neutral-900 p-2 text-sm text-neutral-100"
>
<div class="{editorMinHeight} w-full overflow-auto bg-neutral-900 p-3 text-sm text-neutral-100">
{#if value.trim().length === 0}
<div class="text-neutral-500">{placeholder}</div>
<div class="text-neutral-400">{placeholder}</div>
{:else}
<div class="text-sm leading-relaxed wrap-break-word text-neutral-200">
<!-- eslint-disable-next-line svelte/no-at-html-tags -->
@@ -159,57 +162,71 @@
</div>
{/if}
<div
class="flex w-full flex-col gap-2 rounded-b border border-neutral-700 bg-neutral-800 p-2 md:flex-row md:gap-0"
class="flex w-full flex-col gap-2 border-t border-neutral-700 bg-neutral-800 p-2 md:flex-row md:items-center md:gap-0"
>
<div class="flex items-center gap-1">
<button
type="button"
class="rounded px-2 py-1 text-sm text-neutral-300 hover:text-neutral-100 disabled:cursor-not-allowed disabled:text-neutral-600"
class="flex h-8 w-8 items-center justify-center rounded text-neutral-300 hover:bg-neutral-700 hover:text-neutral-100 disabled:cursor-not-allowed disabled:text-neutral-500"
onclick={addBold}
disabled={isDisabled || mode === 'preview'}
aria-label="Bold"
title="Bold"
>
<Bold class="h-4 w-4" />
</button>
<button
type="button"
class="rounded px-2 py-1 text-sm text-neutral-300 hover:text-neutral-100 disabled:cursor-not-allowed disabled:text-neutral-600"
class="flex h-8 w-8 items-center justify-center rounded text-neutral-300 hover:bg-neutral-700 hover:text-neutral-100 disabled:cursor-not-allowed disabled:text-neutral-500"
onclick={addItalic}
disabled={isDisabled || mode === 'preview'}
aria-label="Italic"
title="Italic"
>
<Italic class="h-4 w-4" />
</button>
<button
type="button"
class="rounded px-2 py-1 text-sm text-neutral-300 hover:text-neutral-100 disabled:cursor-not-allowed disabled:text-neutral-600"
class="flex h-8 w-8 items-center justify-center rounded text-neutral-300 hover:bg-neutral-700 hover:text-neutral-100 disabled:cursor-not-allowed disabled:text-neutral-500"
onclick={addQuote}
disabled={isDisabled || mode === 'preview'}
aria-label="Quote"
title="Quote"
>
<Quote class="h-4 w-4" />
</button>
<button
type="button"
class="rounded px-2 py-1 text-sm text-neutral-300 hover:text-neutral-100 disabled:cursor-not-allowed disabled:text-neutral-600"
class="flex h-8 w-8 items-center justify-center rounded text-neutral-300 hover:bg-neutral-700 hover:text-neutral-100 disabled:cursor-not-allowed disabled:text-neutral-500"
onclick={addCode}
disabled={isDisabled || mode === 'preview'}
aria-label="Inline code"
title="Inline code"
>
<CodeXml class="h-5 w-5" />
<CodeXml class="h-4 w-4" />
</button>
</div>
<div class="flex flex-col items-center gap-2 md:ml-auto md:flex-row">
<div class="flex flex-col items-stretch gap-2 md:ml-auto md:flex-row md:items-center">
<button
type="button"
class="ml-auto w-full rounded border border-neutral-600 px-3 py-1 text-sm text-neutral-200 hover:border-neutral-500 hover:text-neutral-100 md:w-auto"
class="flex h-8 w-full items-center justify-center gap-2 rounded px-3 text-sm text-neutral-200 hover:bg-neutral-700 hover:text-neutral-100 disabled:cursor-not-allowed disabled:text-neutral-500 md:w-auto"
onclick={toggleMode}
disabled={isDisabled}
>
{#if mode === 'preview'}
<Pencil class="h-4 w-4" />
{:else}
<Eye class="h-4 w-4" />
{/if}
{mode === 'preview' ? 'Raw' : 'Preview'}
</button>
<button
type="button"
class="w-full rounded border border-neutral-600 px-3 py-1 text-sm text-neutral-100 hover:bg-neutral-600 disabled:cursor-not-allowed disabled:border-neutral-700 disabled:text-neutral-500 md:ml-2 md:w-auto"
class="flex h-8 w-full items-center justify-center gap-2 rounded border border-neutral-600 bg-neutral-700 px-3 text-sm font-medium text-neutral-100 hover:border-neutral-500 hover:bg-neutral-600 disabled:cursor-not-allowed disabled:border-neutral-700 disabled:bg-neutral-800 disabled:text-neutral-500 md:w-auto"
onclick={submit}
disabled={!canSubmit}
>
<Send class="h-4 w-4" />
{submitting ? submittingLabel : submitLabel}
</button>
</div>