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

@@ -1,4 +1,4 @@
<script lang="ts" context="module">
<script lang="ts" module>
export async function block(id: number, block: boolean) {
try {
const loading = toast({
@@ -111,13 +111,10 @@
import Entity from '$lib/components/ui/Entity.svelte'
import { userSettings } from '$lib/settings'
export let community_view: CommunityView
export let moderators: CommunityModeratorView[] = []
let loading = {
let loading = $state({
blocking: false,
subscribing: false,
}
})
async function subscribe() {
if (!$profile?.jwt) return
@@ -140,8 +137,17 @@
loading.subscribing = false
}
let clazz: string = ''
export { clazz as class }
interface Props {
community_view: CommunityView
moderators?: CommunityModeratorView[]
class?: string
}
let {
community_view = $bindable(),
moderators = [],
class: clazz = '',
}: Props = $props()
</script>
<StickyCard class="min-w-full pt-0 text-slate-600 dark:text-zinc-400 {clazz}">
@@ -149,34 +155,39 @@
name={community_view.community.title}
label="!{fullCommunityName(
community_view.community.name,
community_view.community.actor_id
community_view.community.actor_id,
)}"
>
<Avatar
width={32}
url={community_view.community.icon}
alt={community_view.community.name}
circle={false}
slot="icon"
/>
{#snippet customIcon()}
<Avatar
width={32}
url={community_view.community.icon}
alt={community_view.community.name}
circle={false}
/>
{/snippet}
</Entity>
<div class="flex flex-col gap-1">
<hr class="border-slate-200 dark:border-zinc-900 my-1" />
<Expandable bind:open={$userSettings.expand.about} class="!pt-0">
<span slot="title" class="py-1 px-1 flex gap-1 items-center">
<Icon src={InformationCircle} size="15" mini />
{$t('cards.site.about')}
</span>
{#snippet title()}
<span class="py-1 px-1 flex gap-1 items-center">
<Icon src={InformationCircle} size="15" mini />
{$t('cards.site.about')}
</span>
{/snippet}
<Markdown source={community_view.community.description} />
</Expandable>
<hr class="border-slate-200 dark:border-zinc-900 my-1" />
<Expandable bind:open={$userSettings.expand.stats}>
<span slot="title" class="py-1 px-1 flex gap-1 items-center">
<Icon src={ChartBar} size="15" mini />
{$t('cards.site.stats')}
</span>
{#snippet title()}
<span class="py-1 px-1 flex gap-1 items-center">
<Icon src={ChartBar} size="15" mini />
{$t('cards.site.stats')}
</span>
{/snippet}
<div class="flex flex-row gap-4 flex-wrap">
<LabelStat
label={$t('cards.community.members')}
@@ -194,10 +205,12 @@
{#if moderators && moderators.length > 0}
<hr class="border-slate-200 dark:border-zinc-900 my-1" />
<Expandable bind:open={$userSettings.expand.team}>
<span slot="title" class="py-1 px-1 flex gap-1 items-center">
<ShieldIcon width={15} filled />
{$t('cards.community.moderators')}
</span>
{#snippet title()}
<span class="py-1 px-1 flex gap-1 items-center">
<ShieldIcon width={15} filled />
{$t('cards.community.moderators')}
</span>
{/snippet}
<ItemList
items={moderators.map((m) => ({
id: m.moderator.id,
@@ -224,12 +237,13 @@
on:click={subscribe}
class="flex-1 relative z-[inherit]"
>
<Icon
src={community_view.subscribed == 'Subscribed' ? Check : Plus}
mini
size="16"
slot="prefix"
/>
{#snippet prefix()}
<Icon
src={community_view.subscribed == 'Subscribed' ? Check : Plus}
mini
size="16"
/>
{/snippet}
{community_view.subscribed == 'Subscribed' ||
community_view.subscribed == 'Pending'
? $t('cards.community.subscribed')
@@ -240,17 +254,23 @@
<Button
href="/c/{fullCommunityName(
community_view.community.name,
community_view.community.actor_id
community_view.community.actor_id,
)}/settings"
size="square-md"
>
<Icon src={Cog6Tooth} mini size="16" slot="prefix" />
{#snippet prefix()}
<Icon src={Cog6Tooth} mini size="16" />
{/snippet}
</Button>
{/if}
<Menu placement="top-end">
<Button size="square-md" slot="target" class="ml-auto">
<Icon src={EllipsisHorizontal} size="16" mini slot="prefix" />
</Button>
{#snippet target()}
<Button size="square-md" class="ml-auto">
{#snippet prefix()}
<Icon src={EllipsisHorizontal} size="16" mini />
{/snippet}
</Button>
{/snippet}
<MenuButton href="/modlog?community={community_view.community.id}">
<Icon src={Newspaper} size="16" mini />
{$t('cards.community.modlog')}
@@ -262,7 +282,9 @@
on:click={() =>
block(community_view.community.id, !community_view.blocked)}
>
<Icon src={NoSymbol} size="16" mini slot="prefix" />
{#snippet prefix()}
<Icon src={NoSymbol} size="16" mini />
{/snippet}
{community_view.blocked
? $t('cards.community.unblock')
: $t('cards.community.block')}
@@ -273,7 +295,9 @@
size="lg"
on:click={() => blockInstance(community_view.community.instance_id)}
>
<Icon src={BuildingOffice2} size="16" mini slot="prefix" />
{#snippet prefix()}
<Icon src={BuildingOffice2} size="16" mini />
{/snippet}
{$t('cards.community.blockInstance')}
</MenuButton>
{/if}
@@ -301,7 +325,9 @@
type: 'error',
})}
>
<Icon src={Fire} size="16" mini slot="prefix" />
{#snippet prefix()}
<Icon src={Fire} size="16" mini />
{/snippet}
{$t('admin.purge')}
</MenuButton>
{/if}
@@ -1,4 +1,6 @@
<script lang="ts">
import { preventDefault } from 'svelte/legacy'
import { goto } from '$app/navigation'
import { profile } from '$lib/auth.js'
import MarkdownEditor from '$lib/components/markdown/MarkdownEditor.svelte'
@@ -15,31 +17,39 @@
import ImageUploadModal from '../modal/ImageUploadModal.svelte'
import Select from 'mono-svelte/forms/Select.svelte'
/**
* The community ID to edit.
*/
export let edit: number | undefined = undefined
export let formData: {
name: string
displayName: string
icon?: string
banner?: string
sidebar?: string
nsfw: boolean
postsLockedToModerators: boolean
submitting: boolean
visibility: 'Public' | 'LocalOnly'
} = {
name: '',
displayName: '',
sidebar: '',
nsfw: false,
postsLockedToModerators: false,
submitting: false,
visibility: 'Public',
interface Props {
/**
* The community ID to edit.
*/
edit?: number | undefined
formData?: {
name: string
displayName: string
icon?: string
banner?: string
sidebar?: string
nsfw: boolean
postsLockedToModerators: boolean
submitting: boolean
visibility: 'Public' | 'LocalOnly'
}
formtitle?: import('svelte').Snippet
}
let {
edit = undefined,
formData = $bindable({
name: '',
displayName: '',
sidebar: '',
nsfw: false,
postsLockedToModerators: false,
submitting: false,
visibility: 'Public',
}),
formtitle,
}: Props = $props()
async function submit() {
if (!$profile?.jwt) return
if ((!edit && formData.name == '') || formData.displayName == '') return
@@ -103,7 +113,7 @@
goto(
`/c/${res.community_view.community.name}@${
new URL(res.community_view.community.actor_id).hostname
}`
}`,
)
} catch (err) {
toast({
@@ -115,19 +125,19 @@
formData.submitting = false
}
let uploading = {
let uploading = $state({
banner: false,
icon: false,
}
})
</script>
<form
on:submit|preventDefault={submit}
onsubmit={preventDefault(submit)}
class="flex flex-col gap-4 h-full w-full"
>
<slot name="formtitle">
{#if formtitle}{@render formtitle()}{:else}
<Header>{$t('routes.createCommunity')}</Header>
</slot>
{/if}
<TextInput
required
label={$t('form.name')}
@@ -147,7 +157,7 @@
<Label>{$t('routes.admin.config.icon')}</Label>
<button
type="button"
on:click={() => (uploading.icon = !uploading.icon)}
onclick={() => (uploading.icon = !uploading.icon)}
class="flex flex-col gap-4 bg-white dark:bg-black border border-slate-300 dark:border-zinc-800 p-4 w-full h-32 rounded-xl"
>
{#if formData.icon}
@@ -175,7 +185,7 @@
<Label>{$t('routes.admin.config.banner')}</Label>
<button
type="button"
on:click={() => (uploading.banner = !uploading.banner)}
onclick={() => (uploading.banner = !uploading.banner)}
class="flex flex-col gap-4 bg-white dark:bg-black border border-slate-300 dark:border-zinc-800 p-4 w-full h-32 rounded-xl"
>
{#if formData.banner}
@@ -31,13 +31,23 @@
import { isAdmin } from '../moderation/moderation'
import { block, blockInstance, purgeCommunity } from './CommunityCard.svelte'
export let community: Community
export let subscribed: SubscribedType
export let counts: CommunityAggregates | undefined = undefined
export let moderators: CommunityModeratorView[] = []
export let blocked: boolean = false
let clazz: string = ''
export { clazz as class }
interface Props {
community: Community
subscribed: SubscribedType
counts?: CommunityAggregates | undefined
moderators?: CommunityModeratorView[]
blocked?: boolean
class?: string
}
let {
community = $bindable(),
subscribed = $bindable(),
counts = undefined,
moderators = [],
blocked = false,
class: clazz = '',
}: Props = $props()
</script>
<EntityHeader
@@ -71,27 +81,28 @@
bio={community.description}
class={clazz}
>
<button
on:click={() => {
navigator?.clipboard?.writeText?.(
`!${fullCommunityName(community.name, community.actor_id)}`
)
toast({ content: $t('toast.copied') })
}}
class="text-sm flex gap-0 items-center"
slot="nameDetail"
>
!{fullCommunityName(community.name, community.actor_id)}
</button>
{#snippet nameDetail()}
<button
onclick={() => {
navigator?.clipboard?.writeText?.(
`!${fullCommunityName(community.name, community.actor_id)}`,
)
toast({ content: $t('toast.copied') })
}}
class="text-sm flex gap-0 items-center"
>
!{fullCommunityName(community.name, community.actor_id)}
</button>
{/snippet}
{#if moderators.length > 0}
<Expandable
class="border rounded-xl bg-white/50 dark:bg-zinc-900/50 w-full p-3 px-4
dark:border-zinc-800 border-slate-300 border-opacity-50 text-slate-700 dark:text-zinc-300 transition-colors"
>
<svelte:fragment slot="title">
{#snippet title()}
<ShieldIcon width={15} filled />
{$t('cards.community.moderators')}
</svelte:fragment>
{/snippet}
<ItemList
items={moderators.map((m) => ({
id: m.moderator.id,
@@ -114,30 +125,32 @@ dark:border-zinc-800 border-slate-300 border-opacity-50 text-slate-700 dark:text
counts: counts ?? {},
subscribed: subscribed,
}}
let:subscribe
let:subscribing
>
<Button
disabled={subscribing}
loading={subscribing}
size="lg"
color={subscribed == 'NotSubscribed' ? 'primary' : 'secondary'}
on:click={async () => {
subscribed =
(await subscribe())?.community_view.subscribed ?? 'NotSubscribed'
}}
class="flex-1 relative z-[inherit]"
>
<Icon
src={subscribed != 'NotSubscribed' ? Check : Plus}
micro
size="16"
slot="prefix"
/>
{subscribed == 'Subscribed' || subscribed == 'Pending'
? $t('cards.community.subscribed')
: $t('cards.community.subscribe')}
</Button>
{#snippet children({ subscribe, subscribing })}
<Button
disabled={subscribing}
loading={subscribing}
size="lg"
color={subscribed == 'NotSubscribed' ? 'primary' : 'secondary'}
on:click={async () => {
subscribed =
(await subscribe())?.community_view.subscribed ??
'NotSubscribed'
}}
class="flex-1 relative z-[inherit]"
>
{#snippet prefix()}
<Icon
src={subscribed != 'NotSubscribed' ? Check : Plus}
micro
size="16"
/>
{/snippet}
{subscribed == 'Subscribed' || subscribed == 'Pending'
? $t('cards.community.subscribed')
: $t('cards.community.subscribe')}
</Button>
{/snippet}
</Subscribe>
{/if}
@@ -150,7 +163,7 @@ dark:border-zinc-800 border-slate-300 border-opacity-50 text-slate-700 dark:text
rounding="xl"
href="/c/{fullCommunityName(
community.name,
community.actor_id
community.actor_id,
)}/settings"
style="height: 38px; width: 38px;"
>
@@ -158,14 +171,13 @@ dark:border-zinc-800 border-slate-300 border-opacity-50 text-slate-700 dark:text
</Button>
{/if}
<Menu placement="top-end">
<Button
rounding="xl"
size="custom"
slot="target"
style="height: 38px; width: 38px;"
>
<Icon src={EllipsisHorizontal} size="16" mini slot="prefix" />
</Button>
{#snippet target()}
<Button rounding="xl" size="custom" style="height: 38px; width: 38px;">
{#snippet prefix()}
<Icon src={EllipsisHorizontal} size="16" mini />
{/snippet}
</Button>
{/snippet}
<MenuButton href="/modlog?community={community.id}">
<Icon src={Newspaper} size="16" mini />
{$t('cards.community.modlog')}
@@ -176,7 +188,9 @@ dark:border-zinc-800 border-slate-300 border-opacity-50 text-slate-700 dark:text
size="lg"
on:click={() => block(community.id, !blocked)}
>
<Icon src={NoSymbol} size="16" mini slot="prefix" />
{#snippet prefix()}
<Icon src={NoSymbol} size="16" mini />
{/snippet}
{blocked
? $t('cards.community.unblock')
: $t('cards.community.block')}
@@ -187,7 +201,9 @@ dark:border-zinc-800 border-slate-300 border-opacity-50 text-slate-700 dark:text
size="lg"
on:click={() => blockInstance(community.instance_id)}
>
<Icon src={BuildingOffice2} size="16" mini slot="prefix" />
{#snippet prefix()}
<Icon src={BuildingOffice2} size="16" mini />
{/snippet}
{$t('cards.community.blockInstance')}
</MenuButton>
{/if}
@@ -215,7 +231,9 @@ dark:border-zinc-800 border-slate-300 border-opacity-50 text-slate-700 dark:text
type: 'error',
})}
>
<Icon src={Fire} size="16" mini slot="prefix" />
{#snippet prefix()}
<Icon src={Fire} size="16" mini />
{/snippet}
{$t('admin.purge')}
</MenuButton>
{/if}
@@ -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>
@@ -5,25 +5,37 @@
import type { Community } from 'lemmy-js-client'
import { ExclamationTriangle, Icon } from 'svelte-hero-icons'
export let community: Community
export let avatar: boolean = false
export let name: boolean = true
export let avatarSize: number = 24
export let showInstance: boolean = $userSettings.showInstances.community
export let displayName: boolean = true
export let badges = {
nsfw: false,
interface Props {
community: Community
avatar?: boolean
name?: boolean
avatarSize?: number
showInstance?: boolean
displayName?: boolean
badges?: any
class?: string
instanceClass?: string
[key: string]: any
}
let clazz: string = ''
export let instanceClass: string = ''
export { clazz as class }
let {
community,
avatar = false,
name = true,
avatarSize = 24,
showInstance = $userSettings.showInstances.community,
displayName = true,
badges = {
nsfw: false,
},
class: clazz = '',
instanceClass = '',
...rest
}: Props = $props()
</script>
<a
{...$$restProps}
{...rest}
class="items-center flex flex-row gap-2 hover:underline max-w-full min-w-0 {clazz}"
href="/c/{community.name}@{new URL(community.actor_id).hostname}"
data-sveltekit-preload-data="tap"
@@ -2,7 +2,11 @@
import Avatar from '$lib/components/ui/Avatar.svelte'
import type { Community } from 'lemmy-js-client'
export let community: Community
interface Props {
community: Community
}
let { community }: Props = $props()
</script>
<div class="flex flex-row gap-3 items-center">