fix: comments not appearing immediately

This commit is contained in:
Xylight committed 2025-09-21 10:18:27 -07:00
1 parent 1a12533fa8
commit 9a27e95a5f
6 files changed
+157 -252

No files matched your search

+6 -33
View File
@@ -14,7 +14,6 @@
interface Props extends HTMLAnchorAttributes {
href: string
highlight?: boolean
nowrap?: boolean
children?: import('svelte').Snippet
class?: string
icon?: import('svelte').Snippet
@@ -23,48 +22,22 @@
let {
href,
highlight = false,
nowrap = false,
children,
class: clazz = '',
icon,
...rest
}: Props = $props()
let richURL = $derived(children ? undefined : parseURL(href))
</script>
<a
{...rest}
{href}
class="{highlight
? 'text-sky-500'
: ''} hover:underline max-w-full inline-flex items-center gap-1 {clazz}"
class={[
'hover:underline max-w-full inline-flex items-center gap-1',
highlight && 'text-blue-600 dark:text-blue-400',
clazz,
]}
>
{@render icon?.()}
{#if children}{@render children()}{:else}
<span
class="flex relative gap-0 {nowrap
? 'w-full whitespace-nowrap overflow-hidden text-ellipsis text-xs'
: ''} {clazz}"
>
{#if richURL}
<span class="text-blue-300 dark:text-blue-800">
{richURL.protocol}//
</span>
<span class="font-medium">
{richURL.hostname}
</span>
<span
class="text-transparent bg-clip-text bg-linear-to-r
from-blue-300 via-blue-300 to-blue-300/0 w-full
dark:from-blue-800 dark:via-blue-800 dark:to-blue-800/0
"
>
{richURL.pathname}
</span>
{:else}
{href}
{/if}
</span>
{/if}
{@render children?.()}
</a>
@@ -1,14 +1,11 @@
<script lang="ts">
import { profile } from '$lib/auth.svelte.js'
import Avatar from '$lib/components/ui/Avatar.svelte'
import LabelStat from '$lib/components/ui/LabelStat.svelte'
import FormattedNumber from '$lib/components/util/FormattedNumber.svelte'
import { t } from '$lib/i18n/translations'
import { client } from '$lib/client/lemmy.svelte'
import { addSubscription } from '$lib/lemmy/user.js'
import { settings } from '$lib/settings.svelte'
import { fullCommunityName } from '$lib/util.svelte.js'
import type { CommunityView } from '$lib/client/types'
import CommonItem from '$lib/components/ui/layout/CommonItem.svelte'
import { locale, t } from '$lib/i18n/translations'
import { addSubscription } from '$lib/lemmy/user.js'
import { fullCommunityName } from '$lib/util.svelte.js'
import { Button, modal } from 'mono-svelte'
import type { Snippet } from 'svelte'
import {
@@ -21,29 +18,23 @@
Plus,
Trash,
} from 'svelte-hero-icons'
import Subscribe from '../../../../routes/communities/Subscribe.svelte'
import { SvelteURL } from 'svelte/reactivity'
import { CommunityCard } from '.'
import Subscribe from '../../../../routes/communities/Subscribe.svelte'
interface Props {
community: CommunityView
view?: 'cozy' | 'compact'
showCounts?: boolean
class?: string
icon?: import('svelte').Snippet
children?: Snippet
resolveObject?: boolean
actions?: boolean
}
let {
community = $bindable(),
view = 'compact',
showCounts = true,
class: clazz = 'flex flex-col gap-4 text-sm max-w-full relative',
icon,
children,
resolveObject,
actions = true,
}: Props = $props()
</script>
@@ -51,194 +42,116 @@
<CommunityCard community_view={community} />
{/snippet}
<div class={clazz}>
<div
class={[
view == 'cozy' ? 'flex-col gap-2' : 'flex-row',
'flex max-w-full w-full',
]}
>
<a
href="/c/{fullCommunityName(
community.community.name,
community.community.actor_id,
)}"
class="flex-1 w-full overflow-hidden group"
data-sveltekit-preload-data="tap"
>
<div class="flex flex-row gap-2 items-center">
{#if icon}
{@render icon()}
{:else if community.community.nsfw && settings.nsfwBlur}
<div class="w-8 h-8 rounded-xl bg-red-400"></div>
{:else}
<Avatar
url={community.community.icon}
width={32}
circle={false}
alt={community.community.name}
class={[
community.community.nsfw && settings.nsfwBlur && 'blur-3xl',
]}
/>
{/if}
<div
class="flex flex-col overflow-hidden whitespace-nowrap flex-1 min-w-0 shrink"
>
<div
class="font-medium text-base overflow-hidden text-ellipsis leading-5"
>
<h3 class="group-hover:underline text-left">
{community.community.title}
</h3>
{#if community.community.deleted}
<Icon
src={Trash}
class="text-red-500 inline"
micro
size="14"
title={$t('post.badges.deleted')}
/>
{/if}
{#if community.community.nsfw}
<Icon
src={ExclamationTriangle}
class="text-red-500 inline"
micro
size="14"
title={$t('post.badges.nsfw')}
/>
{/if}
{#if community.banned_from_community}
<Icon
src={NoSymbol}
class="text-red-500 inline"
micro
size="14"
title={$t('comment.banned')}
/>
{/if}
{#if community.community.visibility == 'LocalOnly'}
<Icon
src={MapPin}
class="text-green-500 inline"
micro
size="14"
title={$t('routes.admin.config.listingType.local')}
/>
{/if}
</div>
<div class="text-sm text-slate-500 dark:text-zinc-500 flex gap-0.5">
<span class="overflow-hidden text-ellipsis">
{new URL(community.community.actor_id).hostname}
</span>
<span class="overflow-hidden text-ellipsis">
{#if !showCounts}
•
<FormattedNumber number={community.counts.subscribers} />
{/if}
</span>
</div>
</div>
</div>
</a>
{#if children || !actions}
{@render children?.()}
{:else}
<div class="flex flex-row items-center gap-2">
<Button
rounding="xl"
color="ghost"
onclick={() =>
modal({ title: $t('form.post.community'), snippet: communityInfo })}
aria-label={$t('common.info')}
size="square-md"
>
<Icon src={InformationCircle} size="16" mini />
</Button>
<Subscribe {community}>
{#snippet children({ subscribe, subscribing })}
{@const subscribed =
community.subscribed == 'Subscribed' ||
community.subscribed == 'Pending'}
<Button
disabled={subscribing || !profile.current?.jwt}
loading={subscribing}
onclick={async () => {
const object =
resolveObject &&
(await client().resolveObject({
q: community.community.actor_id,
}))
const res = object
? await subscribe(object.community?.community.id)
: await subscribe()
if (res) {
const newSubscribed =
res.community_view.subscribed != 'NotSubscribed'
? 'Subscribed'
: 'NotSubscribed'
community.subscribed = newSubscribed
addSubscription(
community.community,
newSubscribed == 'Subscribed',
)
}
}}
size="custom"
title={subscribed
? $t('cards.community.subscribed')
: $t('cards.community.subscribe')}
color={subscribed ? 'secondary' : 'primary'}
rounding="xl"
class={[
subscribed && 'text-slate-600 dark:text-zinc-400',
' h-8.5 rounded-full',
view == 'compact'
? 'aspect-square @md:px-2 @md:min-w-30 @md:aspect-auto'
: 'px-3',
]}
icon={subscribed ? Check : Plus}
>
<span class={[view == 'compact' && 'hidden', '@md:block']}>
{#if subscribed}
{$t('cards.community.subscribed')}
{:else}
{$t('cards.community.subscribe')}
{/if}
</span>
</Button>
{/snippet}
</Subscribe>
</div>
{/if}
</div>
{#if showCounts}
<div class="flex flex-row gap-3 items-center justify-center">
{#if community.counts.posts}
<LabelStat
content={community.counts.posts.toString()}
formatted
label="Posts"
/>
{/if}
{#if community.counts.subscribers}
<LabelStat
content={community.counts.subscribers.toString()}
formatted
label="Members"
/>
{/if}
{#if community.counts.comments}
<LabelStat
content={community.counts.comments.toString()}
formatted
label="Comments"
/>
{/if}
</div>
<CommonItem
icon={community.community.icon}
href="/c/{fullCommunityName(
community.community.name,
community.community.actor_id,
)}"
title={community.community.title}
detail="{new SvelteURL(community.community.actor_id).hostname}{!showCounts
? ` • ${Intl.NumberFormat($locale, { notation: 'compact' }).format(community.counts.subscribers)}`
: ''}"
orientation={view == 'cozy' ? 'vertical' : 'horizontal'}
>
{#if community.community.deleted}
<Icon
src={Trash}
class="text-red-500 inline"
micro
size="14"
title={$t('post.badges.deleted')}
/>
{/if}
</div>
{#if community.community.nsfw}
<Icon
src={ExclamationTriangle}
class="text-red-500 inline"
micro
size="14"
title={$t('post.badges.nsfw')}
/>
{/if}
{#if community.banned_from_community}
<Icon
src={NoSymbol}
class="text-red-500 inline"
micro
size="14"
title={$t('comment.banned')}
/>
{/if}
{#if community.community.visibility == 'LocalOnly'}
<Icon
src={MapPin}
class="text-green-500 inline"
micro
size="14"
title={$t('routes.admin.config.listingType.local')}
/>
{/if}
<Button
rounding="xl"
color="ghost"
onclick={() =>
modal({ title: $t('form.post.community'), snippet: communityInfo })}
aria-label={$t('common.info')}
size="square-md"
>
<Icon src={InformationCircle} size="16" mini />
</Button>
<Subscribe {community}>
{#snippet children({ subscribe, subscribing })}
{@const subscribed =
community.subscribed == 'Subscribed' ||
community.subscribed == 'Pending'}
<Button
disabled={subscribing || !profile.current?.jwt}
loading={subscribing}
onclick={async () => {
const object =
resolveObject &&
(await client().resolveObject({
q: community.community.actor_id,
}))
const res = object
? await subscribe(object.community?.community.id)
: await subscribe()
if (res) {
const newSubscribed =
res.community_view.subscribed != 'NotSubscribed'
? 'Subscribed'
: 'NotSubscribed'
community.subscribed = newSubscribed
addSubscription(community.community, newSubscribed == 'Subscribed')
}
}}
size="custom"
title={subscribed
? $t('cards.community.subscribed')
: $t('cards.community.subscribe')}
color={subscribed ? 'secondary' : 'primary'}
rounding="xl"
class={[
subscribed && 'text-slate-600 dark:text-zinc-400',
' h-8.5 rounded-full',
view == 'compact'
? 'aspect-square @md:px-2 @md:min-w-30 @md:aspect-auto'
: 'px-3',
]}
icon={subscribed ? Check : Plus}
>
<span class={[view == 'compact' && 'hidden', '@md:block']}>
{#if subscribed}
{$t('cards.community.subscribed')}
{:else}
{$t('cards.community.subscribe')}
{/if}
</span>
</Button>
{/snippet}
</Subscribe>
</CommonItem>
+20 -3
View File
@@ -7,13 +7,28 @@
icon?: string
title: string
detail?: string
orientation: 'vertical' | 'horizontal'
children?: Snippet
}
let { href, icon, title, detail, children }: Props = $props()
let {
href,
icon,
title,
detail,
children,
orientation = 'horizontal',
}: Props = $props()
</script>
<div class="flex flex-row gap-2 items-center">
<div
class={[
'flex gap-2 p-5',
orientation == 'horizontal'
? 'flex-row items-center'
: 'flex-col items-staRT',
]}
>
<Avatar url={icon} alt={title} width={detail ? 32 : 24} circle={false} />
<a class="flex-1 flex flex-col group" {href}>
<h3
@@ -25,5 +40,7 @@
{detail}
</p>
</a>
{@render children?.()}
<div class="flex flex-row gap-2 items-center">
{@render children?.()}
</div>
</div>
+5 -10
View File
@@ -28,6 +28,7 @@
import ProfileSelection from './ProfileSelection.svelte'
import Logo from '../Logo.svelte'
import { env } from '$env/dynamic/public'
import Link from '$lib/components/input/Link.svelte'
interface Props {
style?: string
@@ -181,18 +182,12 @@
</span>
</div>
{#if env.PUBLIC_XYLIGHT_MODE?.toLowerCase() == 'true'}
<a
href="https://github.com/xyphyn/photon"
class="text-blue-600 dark:text-blue-400/60 hover:underline"
>
<Link highlight href="https://github.com/xyphyn/photon">
{$t('nav.menu.source')}
</a>
<a
href="https://buymeacoffee.com/xylight"
class="text-blue-600 dark:text-blue-400/60 hover:underline"
>
</Link>
<Link highlight href="https://buymeacoffee.com/xylight">
{$t('nav.menu.donate')}
</a>
</Link>
{/if}
</footer>
</nav>
+2
View File
@@ -18,6 +18,8 @@
$effect(() => {
if (data.filters.value.sort)
settings.defaultSort.sort = data.filters.value.sort
if (data.filters.value.type_)
settings.defaultSort.feed = data.filters.value.type_
})
const FeedComponent = $derived(
@@ -116,7 +116,12 @@
<CommentForm
postId={post.post.id}
oncomment={(comment) => {
comments.unshift(comment.comment_view)
tree.unshift({
children: [],
depth: 1,
expanded: true,
comment_view: comment.comment_view,
})
}}
onfocus={() => (commenting = true)}
tools={commenting}