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