design: implement more intuitive all comments/show context buttons

This commit is contained in:
Xylight committed 2025-10-25 18:21:31 -07:00
1 parent ca48d31c98
commit 81a5998b8a
5 files changed
+84 -62

No files matched your search

+2 -2
View File
@@ -12,7 +12,7 @@ import { DEFAULT_INSTANCE_URL } from './instance.svelte'
import { instanceToURL, moveItem } from './util.svelte'
function getFromStorage<T>(key: string): T | undefined {
if (typeof localStorage == 'undefined') return undefined
if (!browser) return
const lc = localStorage.getItem(key)
if (!lc) return undefined
@@ -20,7 +20,7 @@ function getFromStorage<T>(key: string): T | undefined {
}
function setFromStorage(key: string, item: any, stringify: boolean = true) {
if (typeof localStorage == 'undefined') return
if (!browser) return
return localStorage.setItem(key, stringify ? JSON.stringify(item) : item)
}
-2
View File
@@ -301,8 +301,6 @@
"commentCount": "Comments",
"addComment": "Add a comment",
"scrollToTop": "Scroll to top",
"remoteView": "Remote View",
"localView": "Local View",
"thread": {
"single": "You're viewing a single thread.",
"allComments": "All comments",
+33 -12
View File
@@ -23,11 +23,17 @@
none: '',
}
const alignments = {
default: '',
center: '',
}
interface Props {
class?: ClassValue
size?: keyof typeof sizes
color?: keyof typeof colors
margin?: keyof typeof margins
alignment?: keyof typeof alignments
border?: boolean
children?: import('svelte').Snippet
action?: import('svelte').Snippet
@@ -43,9 +49,19 @@
color = 'subtle',
margin = 'none',
element = 'h3',
alignment = 'default',
}: Props = $props()
</script>
{#snippet divider()}
<div
class={[
'flex-1 border-slate-200/70 dark:border-zinc-800 border-b',
!border && 'opacity-0',
]}
></div>
{/snippet}
<div
class={[
'flex flex-row items-center gap-2 flex-wrap',
@@ -55,17 +71,22 @@
clazz,
]}
>
<svelte:element
this={element}
class="font-medium text-left flex flex-row gap-1 items-center"
>
{@render children?.()}
</svelte:element>
<div
class={[
'flex-1 border-slate-200/70 dark:border-zinc-800 border-b',
!border && 'opacity-0',
]}
></div>
{#if alignment == 'center'}
{@render divider()}
{/if}
{#if children}
<svelte:element
this={element}
class="font-medium text-left flex flex-row gap-1 items-center"
>
{@render children?.()}
</svelte:element>
{/if}
{#if alignment == 'default'}
{@render divider()}
{/if}
{@render action?.()}
{#if alignment == 'center'}
{@render divider()}
{/if}
</div>
@@ -11,12 +11,10 @@
parseTags,
PostActions,
PostItem,
postLink,
PostMedia,
PostMeta,
type Tag,
} from '$lib/feature/post'
import Fixate from '$lib/ui/generic/Fixate.svelte'
import Placeholder from '$lib/ui/info/Placeholder.svelte'
import { CommonList } from '$lib/ui/layout'
import EndPlaceholder from '$lib/ui/layout/EndPlaceholder.svelte'
@@ -24,12 +22,7 @@
import FormattedNumber from '$lib/ui/util/FormattedNumber.svelte'
import { Button, Expandable, toast } from 'mono-svelte'
import { onMount } from 'svelte'
import {
ArrowRight,
ChatBubbleLeftRight,
ChevronDoubleUp,
Icon,
} from 'svelte-hero-icons/dist'
import { ChatBubbleLeftRight, ChevronDoubleUp } from 'svelte-hero-icons/dist'
import { expoOut } from 'svelte/easing'
import { fly } from 'svelte/transition'
import CommentProvider from './CommentProvider.svelte'
@@ -59,10 +52,7 @@
}
})
let loading = $state(false)
async function reloadComments() {
loading = true
data.data.value.comments = client()
.getComments({
page: 1,
@@ -73,7 +63,6 @@
max_depth: data.data.value.post.counts.comments > 100 ? 1 : 3,
})
.then((i) => i.comments)
loading = false
data.data.value.params.thread.singleThread = false
}
@@ -214,34 +203,6 @@
{/if}
{/await}
</article>
{#await data.data.value.comments then comments}
{#if data.data.value.params.thread.showContext || data.data.value.params.thread.singleThread}
<Fixate placement="top">
<Button
color="primary"
rounding="pill"
{loading}
disabled={loading}
href={data.data.value.params.thread.showContext
? `/comment/${
// split first comment path to get 5 before
comments[0].comment.path.split('.').slice(-5)[1]
}`
: data.data.value.params.thread.singleThread
? postLink(data.data.value.post.post)
: undefined}
class="w-max mx-auto sticky lg:top-20 z-50"
>
{data.data.value.params.thread.showContext
? $t('routes.post.thread.context')
: $t('routes.post.thread.allComments')}
{#snippet suffix()}
<Icon src={ArrowRight} size="16" micro />
{/snippet}
</Button>
</Fixate>
{/if}
{/await}
<section class="flex flex-col gap-2 w-full" id="comments">
<header class="mt-4">
<EndPlaceholder size="md" color="none">
@@ -288,6 +249,8 @@
onupdate={reloadComments}
bind:sort={data.data.value.params.comments.sort}
virtualize={!page.url.searchParams.get('noVirtualize')}
showContext={data.data.value.params.thread.showContext}
singleThread={data.data.value.params.thread.singleThread}
/>
{#if comments.length == 0}
<Placeholder
@@ -9,6 +9,7 @@
import CommentListVirtualizer from '$lib/feature/comment/CommentListVirtualizer.svelte'
import { buildCommentsTree } from '$lib/feature/comment/comments.svelte'
import CommentTree from '$lib/feature/comment/CommentTree.svelte'
import { postLink } from '$lib/feature/post'
import EndPlaceholder from '$lib/ui/layout/EndPlaceholder.svelte'
import { Button, Option, Select } from 'mono-svelte'
import { onMount } from 'svelte'
@@ -19,6 +20,7 @@
Clock,
Fire,
Icon,
PlusCircle,
Star,
Trophy,
} from 'svelte-hero-icons/dist'
@@ -30,6 +32,8 @@
onupdate?: () => void
focus?: string
virtualize?: boolean
showContext?: boolean
singleThread?: boolean
}
let {
@@ -39,6 +43,8 @@
onupdate,
focus,
virtualize = true,
showContext,
singleThread,
}: Props = $props()
let commenting = $state(false)
@@ -65,12 +71,7 @@
color="primary"
rounding="xl"
disabled={(post.post.locked || post.banned_from_community) &&
!(
profile.current?.user?.local_user_view.local_user.admin ||
profile.current?.user?.moderates
.map((c) => c.community.id)
.includes(post.community.id)
)}
!(profile.isAdmin || profile.isMod(post.community))}
onclick={() => (commenting = true)}
>
<Icon src={ChatBubbleOvalLeft} size="16" micro />
@@ -155,6 +156,41 @@
></Button>
</div>
{/if}
{#snippet allCommentsPlaceholder()}
<EndPlaceholder alignment="center">
{#snippet action()}
<Button href={postLink(post.post)} icon={PlusCircle} rounding="pill">
{$t('routes.post.thread.allComments')}
</Button>
{/snippet}
</EndPlaceholder>
{/snippet}
{#if singleThread && !showContext}
{@render allCommentsPlaceholder()}
{/if}
{#if showContext && tree[0]}
<Button
color="secondary"
alignment="left"
rounding="pill"
href={`/comment/${
// split first comment path to get 5 before
comments[0].comment.path.split('.').slice(-5)[1]
}`}
class="mt-2 -mb-2 -mx-2.5 w-max"
>
<Icon src={PlusCircle} size="16" micro />
{$t('comment.more', {
comments: tree[0].comment_view.comment.path.split('.').length - 2,
})}
</Button>
<div
class="border-l h-4 -mb-5 ml-2.5 border-slate-200 dark:border-zinc-800"
></div>
{/if}
{#if virtualize}
<CommentListVirtualizer post={post.post} nodes={tree} scrollTo={focus} />
{:else}
@@ -164,3 +200,7 @@
</div>
</div>
{/if}
{#if singleThread && !showContext}
{@render allCommentsPlaceholder()}
{/if}