migrate: convert most components to svelte 5

This commit is contained in:
Xylight committed 2024-10-25 19:33:27 -07:00
1 parent d670f39f0a
commit 10ef4123da
225 files changed
+5441 -3341

No files matched your search

@@ -23,13 +23,22 @@
import { t } from '$lib/translations'
import Entity from '$lib/components/ui/Entity.svelte'
export let community: CommunityView
export let view: 'cozy' | 'compact' = 'compact'
export let showCounts: boolean = true
let showInfo = $state(false)
interface Props {
community: CommunityView
view?: 'cozy' | 'compact'
showCounts?: boolean
class?: string
icon?: import('svelte').Snippet
}
let showInfo = false
let clazz: string = 'py-4 flex flex-col gap-4 text-sm max-w-full relative'
export { clazz as class }
let {
community = $bindable(),
view = 'compact',
showCounts = true,
class: clazz = 'py-4 flex flex-col gap-4 text-sm max-w-full relative',
icon,
}: Props = $props()
</script>
{#if showInfo}
@@ -48,7 +57,7 @@
<a
href="/c/{fullCommunityName(
community.community.name,
community.community.actor_id
community.community.actor_id,
)}"
class="flex-1 w-full overflow-hidden"
data-sveltekit-preload-data="tap"
@@ -58,13 +67,13 @@
? 'flex-col gap-2'
: 'flex-row'} gap-2 items-center"
>
<slot name="icon">
{#if icon}{@render icon()}{:else}
<Avatar
url={community.community.icon}
width={32}
alt={community.community.name}
/>
</slot>
{/if}
<div
class="flex flex-col overflow-hidden whitespace-nowrap flex-1 min-w-0 flex-shrink"
>
@@ -92,50 +101,55 @@
<Button size="square-md" on:click={() => (showInfo = !showInfo)}>
<Icon src={InformationCircle} size="16" micro />
</Button>
<Subscribe {community} let:subscribe let:subscribing>
<Button
disabled={subscribing || !$profile?.jwt}
loading={subscribing}
on:click={async () => {
const res = await subscribe()
<Subscribe {community}>
{#snippet children({ subscribe, subscribing })}
<Button
disabled={subscribing || !$profile?.jwt}
loading={subscribing}
on:click={async () => {
const res = await subscribe()
if (res) {
const newSubscribed =
res.community_view.subscribed != 'NotSubscribed'
? 'Subscribed'
: 'NotSubscribed'
if (res) {
const newSubscribed =
res.community_view.subscribed != 'NotSubscribed'
? 'Subscribed'
: 'NotSubscribed'
community.subscribed = newSubscribed
addSubscription(
community.community,
newSubscribed == 'Subscribed'
)
}
}}
size="custom"
title={isSubscribed(community.subscribed)
? $t('cards.community.subscribed')
: $t('cards.community.subscribe')}
color={isSubscribed(community.subscribed) ? 'elevatedLow' : 'primary'}
class="{isSubscribed(community.subscribed)
? 'text-slate-600 dark:text-zinc-400'
: ''}
aspect-square h-8 @md:px-2 @md:min-w-32 @md:aspect-auto"
>
<Icon
src={isSubscribed(community.subscribed) ? Check : Plus}
size="16"
micro
slot="prefix"
/>
<span class="hidden @md:block">
{#if isSubscribed(community.subscribed)}
{$t('cards.community.subscribed')}
{:else}
{$t('cards.community.subscribe')}
{/if}
</span>
</Button>
community.subscribed = newSubscribed
addSubscription(
community.community,
newSubscribed == 'Subscribed',
)
}
}}
size="custom"
title={isSubscribed(community.subscribed)
? $t('cards.community.subscribed')
: $t('cards.community.subscribe')}
color={isSubscribed(community.subscribed)
? 'elevatedLow'
: 'primary'}
class="{isSubscribed(community.subscribed)
? 'text-slate-600 dark:text-zinc-400'
: ''}
aspect-square h-8 @md:px-2 @md:min-w-32 @md:aspect-auto"
>
{#snippet prefix()}
<Icon
src={isSubscribed(community.subscribed) ? Check : Plus}
size="16"
micro
/>
{/snippet}
<span class="hidden @md:block">
{#if isSubscribed(community.subscribed)}
{$t('cards.community.subscribed')}
{:else}
{$t('cards.community.subscribe')}
{/if}
</span>
</Button>
{/snippet}
</Subscribe>
</div>
</div>