Merge pull request #623 from Xyphyn/design-comment

design: improve comment experience
This commit is contained in:
Xylight authored and GitHub committed 2025-08-01 19:56:47 +00:00
commit 5d51128f16
12 files changed
+102 -41

No files matched your search

@@ -116,8 +116,7 @@
{#if meta}
<button
onclick={() => (open = !open)}
class="flex flex-row cursor-pointer gap-2 items-center group text-[13px] flex-wrap w-full
z-0 group relative"
class="flex flex-row cursor-pointer gap-2 items-center group text-[13px] flex-wrap w-full z-0 group"
>
{@render metaSuffix?.()}
<span class:font-bold={op} class="flex flex-row gap-1 items-center">
@@ -178,8 +177,9 @@
>
<Markdown
source={node.comment_view.comment.content}
noStyle
class={[
'text-[15px] text-slate-800 dark:text-zinc-200 leading-[1.3]',
'text-base text-slate-700 dark:text-zinc-300 *:leading-[1.6] break-words space-y-3',
node.comment_view.comment.distinguished
? 'bg-green-400/10 p-1 rounded-lg w-max font-medium'
@@ -221,9 +221,7 @@
/>
</div>
{/if}
<div class="bg-transparent dark:bg-transparent">
{@render children?.()}
</div>
{@render children?.()}
</div>
</div>
</li>
@@ -2,7 +2,7 @@
import VirtualList from '$lib/components/render/VirtualList.svelte'
import type { Post } from 'lemmy-js-client'
import type { CommentNodeI } from './comments.svelte'
import Comments from './Comments.svelte'
import Comments from './CommentTree.svelte'
import { onMount } from 'svelte'
interface Props {
@@ -41,14 +41,19 @@
<div bind:this={offsetEl}>
{#if offsetEl}
<VirtualList
class="divide-y divide-slate-200 dark:divide-zinc-800 w-full"
class="divide-y divide-slate-100 dark:divide-zinc-900 -mx-3 sm:-mx-6"
overscan={5}
estimatedHeight={500}
items={nodes}
{initialOffset}
>
{#snippet item(index)}
<div class="-mx-3 sm:-mx-6 px-3 sm:px-6">
<div
class={[
'px-3 sm:px-6',
index % 2 == 1 && 'bg-slate-25 dark:bg-zinc-950',
]}
>
<Comments
bind:nodes={() => [nodes[index]], v => (nodes[index] = v[0])}
{post}
@@ -9,7 +9,7 @@
import { Button, toast } from 'mono-svelte'
import { ArrowDownCircle, Icon } from 'svelte-hero-icons'
import Comment from './Comment.svelte'
import Comments from './Comments.svelte'
import Comments from './CommentTree.svelte'
import { buildCommentsTree, type CommentNodeI } from './comments.svelte'
interface Props {
@@ -93,10 +93,15 @@
bind:node={nodes[index]}
postId={post.id}
op={post.creator_id == node.comment_view.creator.id}
contentClass="{node.children.length > 0 ||
node.comment_view.counts.child_count > 0
? 'border-l'
: ''} ml-2.5 border-slate-200 dark:border-zinc-800 pl-2.5"
contentClass={[
(node.children.length > 0 ||
node.comment_view.counts.child_count > 0) &&
'border-l',
'ml-2.5 pl-3 sm:pl-4 lg:pl-5',
node.depth % 2 == 0
? 'border-slate-200 dark:border-zinc-800'
: 'border-slate-300/80 dark:border-zinc-700',
]}
bind:open={nodes[index].expanded}
>
{#if node.children?.length > 0}
@@ -106,22 +111,20 @@
{#if node.comment_view.counts.child_count > 0 && node.children.length == 0}
<svelte:element
this={browser ? 'div' : 'a'}
class="w-full h-10 border-y-0! -mt-2 -ml-2.5"
href="/comment/{page.params.instance}/{node.comment_view.comment.id}"
class="w-full h-10 -mt-2 -ml-2.5"
href="/comment/{node.comment_view.comment.id}"
>
<Button
loading={nodes[index].loading}
disabled={nodes[index].loading}
rounding="pill"
color="tertiary"
class="font-normal text-sm! text-slate-600 dark:text-zinc-400"
class="font-normal text-slate-600 dark:text-zinc-400"
shadow="none"
loaderWidth={16}
onclick={() => {
if (nodes[index].depth > 4) {
goto(
`/comment/${page.params.instance}/${nodes[index].comment_view.comment.id}#comments`,
)
goto(`/comment/${nodes[index].comment_view.comment.id}#comments`)
} else {
nodes[index].loading = true
fetchChildren(nodes[index]).then(
@@ -8,6 +8,7 @@
import { backOut } from 'svelte/easing'
import { fly } from 'svelte/transition'
import { shouldShowVoteColor } from '../post/PostVote.svelte'
import { settings } from '$lib/settings.svelte'
interface Props {
vote?: number
@@ -36,13 +37,19 @@
})
;({ upvotes, downvotes } = res.comment_view.counts)
}
let voteRatio = $derived(
Math.floor(((upvotes ?? 0) / ((upvotes ?? 0) + (downvotes ?? 0))) * 100),
)
</script>
<div
class={[
'h-full flex items-center overflow-hidden rounded-full hover:bg-transparent font-medium hover:dark:bg-transparent',
'h-full relative flex items-center overflow-hidden rounded-full hover:bg-transparent font-medium hover:dark:bg-transparent',
buttonColor.ghost,
voteRatio < 85 && settings.voteRatioBar && 'vote-ratio',
]}
style="--vote-ratio: {voteRatio}%;"
>
<button
onclick={() => castVote(vote == 1 ? 0 : 1)}
@@ -92,3 +99,25 @@
</span>
</button>
</div>
<style>
.vote-ratio {
z-index: 0;
}
.vote-ratio::before {
content: '';
position: absolute;
height: 100%;
width: 100%;
opacity: 10%;
z-index: -10;
left: 0;
bottom: 0px;
background: linear-gradient(
to right,
var(--color-indigo-500) calc(var(--vote-ratio) - 5%),
var(--color-red-500) calc(var(--vote-ratio) + 5%)
);
}
</style>
+29 -1
View File
@@ -22,6 +22,7 @@
import { site } from '$lib/lemmy.svelte.js'
import { vote as voteItem } from '$lib/lemmy/contentview.js'
import { errorMessage } from '$lib/lemmy/error'
import { settings } from '$lib/settings.svelte'
import type { Post } from 'lemmy-js-client'
import { buttonColor, toast } from 'mono-svelte'
import { ChevronDown, ChevronUp, Icon } from 'svelte-hero-icons'
@@ -67,16 +68,21 @@
</script>
{#if children}{@render children({ vote, score })}{:else}
{@const voteRatio = Math.floor(
((upvotes ?? 0) / ((upvotes ?? 0) + (downvotes ?? 0))) * 100,
)}
<div
class={[
buttonColor.ghost,
'rounded-full h-full font-medium flex items-center *:p-2',
'rounded-full h-full font-medium flex items-center *:p-2 relative',
'hover:bg-white dark:hover:bg-zinc-900 overflow-hidden transition-colors shrink-0',
'text-inherit! divide-x divide-slate-200 dark:divide-zinc-800 shadow-xs',
loading && 'animate-pulse opacity-75 pointer-events-none',
voteRatio < 85 && settings.voteRatioBar && 'vote-ratio',
]}
role="group"
aria-label={$t('aria.vote.group')}
style="--vote-ratio: {voteRatio}%;"
>
<button
onclick={() => castVote(vote == 1 ? 0 : 1)}
@@ -136,3 +142,25 @@
{/if}
</div>
{/if}
<style>
.vote-ratio {
z-index: 0;
}
.vote-ratio::before {
content: '';
position: absolute;
height: 100%;
opacity: 10%;
width: 100%;
left: 0;
bottom: 0px;
z-index: -10;
background: linear-gradient(
to right,
var(--color-indigo-500) calc(var(--vote-ratio) - 4%),
var(--color-red-500) calc(var(--vote-ratio) + 4%)
);
}
</style>
+1 -1
View File
@@ -230,7 +230,7 @@
{#each visibleItems as item (item.index)}
<div
data-index={item.index}
class="post-container fix-divide"
class="post-container fix-divide group/virtual"
use:resizeObserver
>
{@render itemSnippet(item.index)}
+1 -16
View File
@@ -46,20 +46,15 @@
background-color: var(--color-white);
container-type: inline-size;
border-left: 1px solid var(--color-slate-100);
border-right: 1px solid var(--color-slate-100);
border-radius: var(--radius-md) var(--radius-md);
&:first-child {
border-top-left-radius: var(--radius-2xl);
border-top-right-radius: var(--radius-2xl);
border-top: 1px solid var(--color-slate-100);
}
&:last-child {
border-bottom-left-radius: var(--radius-2xl);
border-bottom-right-radius: var(--radius-2xl);
border-bottom: 1px solid var(--color-slate-100);
}
&:hover {
@@ -77,16 +72,6 @@
:global(.dark) ul > :global(li) {
background-color: var(--color-zinc-950);
border-left: 1px solid var(--color-zinc-900);
border-right: 1px solid var(--color-zinc-900);
&:first-child {
border-top: 1px solid var(--color-zinc-900);
}
&:last-child {
border-bottom: 1px solid var(--color-zinc-900);
}
&:hover {
background-color: var(--color-zinc-900);
}
+4
View File
@@ -850,6 +850,10 @@
"titleOpensUrl": {
"title": "Title opens URL",
"description": "Makes clicking the title open the post's attached URL, rather than the comments."
},
"voteRatioBar": {
"title": "Vote ratio bar",
"description": "When the controversiality of a post reaches greater than 15%, a bar will be displayed in the vote buttons to help visualize sentiment."
}
},
"embeds": {
+1 -1
View File
@@ -41,7 +41,7 @@
transparent:
'border border-slate-200 dark:border-zinc-900 border-b-slate-300 dark:border-t-zinc-800',
uniform:
'bg-white dark:bg-zinc-950 border border-slate-100 dark:border-zinc-900',
'bg-white dark:bg-zinc-950 border border-slate-200 dark:border-zinc-900',
none: '',
}
+2
View File
@@ -104,6 +104,7 @@ interface Settings {
messages: {
fullMarkdown: boolean
}
voteRatioBar: boolean
}
export const defaultSettings: Settings = {
@@ -184,6 +185,7 @@ export const defaultSettings: Settings = {
messages: {
fullMarkdown: toBool(env.PUBLIC_FULL_MARKDOWN) ?? false,
},
voteRatioBar: true,
}
function createSettingsState(initial: Settings): Settings {
@@ -4,7 +4,7 @@
import { profile } from '$lib/auth.svelte'
import CommentForm from '$lib/components/lemmy/comment/CommentForm.svelte'
import CommentListVirtualizer from '$lib/components/lemmy/comment/CommentListVirtualizer.svelte'
import Comments from '$lib/components/lemmy/comment/Comments.svelte'
import Comments from '$lib/components/lemmy/comment/CommentTree.svelte'
import { buildCommentsTree } from '$lib/components/lemmy/comment/comments.svelte'
import EndPlaceholder from '$lib/components/ui/EndPlaceholder.svelte'
import { t } from '$lib/i18n/translations'
+7
View File
@@ -29,6 +29,7 @@
ArrowRight,
ArrowsPointingOut,
ArrowsRightLeft,
ArrowsUpDown,
ArrowTopRightOnSquare,
ArrowTrendingDown,
ArrowUpTray,
@@ -402,6 +403,12 @@
title={$t('settings.app.absoluteDates.title')}
description={$t('settings.app.absoluteDates.description')}
/>
<ToggleSetting
icon={ArrowsUpDown}
bind:checked={settings.voteRatioBar}
title={$t('settings.app.voteRatioBar.title')}
description={$t('settings.app.voteRatioBar.description')}
/>
<ToggleSetting
icon={CubeTransparent}
supportedPlatforms={{ desktop: false, tablet: false, mobile: true }}