migrate: convert most components to svelte 5
This commit is contained in:
1 parent
d670f39f0a
commit
10ef4123da
225 files changed
+5441
-3341
No files matched your search
@@ -1,4 +1,6 @@
|
||||
<script lang="ts">
|
||||
import { run, preventDefault } from 'svelte/legacy'
|
||||
|
||||
import { createEventDispatcher, onDestroy, onMount } from 'svelte'
|
||||
import { client, site } from '$lib/lemmy.js'
|
||||
import type { Community, Post, PostView } from 'lemmy-js-client'
|
||||
@@ -33,46 +35,56 @@
|
||||
import { errorMessage } from '$lib/lemmy/error'
|
||||
import FreeTextInput from '$lib/components/input/FreeTextInput.svelte'
|
||||
|
||||
export let edit = false
|
||||
|
||||
/**
|
||||
* The post to edit
|
||||
*/
|
||||
export let editingPost: Post | undefined = undefined
|
||||
|
||||
export let passedCommunity: Community | undefined = undefined
|
||||
|
||||
export let data: {
|
||||
community: Community | null
|
||||
title: string
|
||||
body: string
|
||||
image: FileList | null
|
||||
thumbnail?: string
|
||||
url?: string
|
||||
nsfw: boolean
|
||||
loading: boolean
|
||||
alt_text?: string
|
||||
language_id?: number
|
||||
} = {
|
||||
community: null,
|
||||
title: '',
|
||||
body: '',
|
||||
image: null,
|
||||
thumbnail: undefined,
|
||||
url: undefined,
|
||||
nsfw: false,
|
||||
loading: false,
|
||||
alt_text: undefined,
|
||||
language_id: undefined,
|
||||
interface Props {
|
||||
edit?: boolean
|
||||
/**
|
||||
* The post to edit
|
||||
*/
|
||||
editingPost?: Post | undefined
|
||||
passedCommunity?: Community | undefined
|
||||
data?: {
|
||||
community: Community | null
|
||||
title: string
|
||||
body: string
|
||||
image: FileList | null
|
||||
thumbnail?: string
|
||||
url?: string
|
||||
nsfw: boolean
|
||||
loading: boolean
|
||||
alt_text?: string
|
||||
language_id?: number
|
||||
}
|
||||
formtitle?: import('svelte').Snippet
|
||||
}
|
||||
|
||||
let {
|
||||
edit = false,
|
||||
editingPost = undefined,
|
||||
passedCommunity = undefined,
|
||||
data = $bindable({
|
||||
community: null,
|
||||
title: '',
|
||||
body: '',
|
||||
image: null,
|
||||
thumbnail: undefined,
|
||||
url: undefined,
|
||||
nsfw: false,
|
||||
loading: false,
|
||||
alt_text: undefined,
|
||||
language_id: undefined,
|
||||
}),
|
||||
formtitle,
|
||||
}: Props = $props()
|
||||
// weird select menu language handling
|
||||
// @ts-ignore
|
||||
$: if (data.language_id === '') data.language_id = undefined
|
||||
run(() => {
|
||||
if (data.language_id === '') data.language_id = undefined
|
||||
})
|
||||
|
||||
let saveDraft = edit ? false : true
|
||||
let communitySearch = passedCommunity?.name ?? ''
|
||||
let communitySearch = $state(passedCommunity?.name ?? '')
|
||||
|
||||
let communities: Community[] = []
|
||||
let communities: Community[] = $state([])
|
||||
|
||||
const dispatcher = createEventDispatcher<{ submit: PostView }>()
|
||||
|
||||
@@ -179,7 +191,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
let uploadingImage = false
|
||||
let uploadingImage = $state(false)
|
||||
|
||||
const generateTitle = async (url: string | undefined) => {
|
||||
if (!url) return
|
||||
@@ -224,15 +236,17 @@
|
||||
return true
|
||||
}
|
||||
|
||||
let generation = {
|
||||
let generation = $state({
|
||||
loading: false,
|
||||
generatable: false,
|
||||
title: '',
|
||||
}
|
||||
})
|
||||
|
||||
let addAltText = false
|
||||
let addAltText = $state(false)
|
||||
|
||||
$: generation.generatable = canGenerateTitle(data.url)
|
||||
run(() => {
|
||||
generation.generatable = canGenerateTitle(data.url)
|
||||
})
|
||||
</script>
|
||||
|
||||
{#if uploadingImage}
|
||||
@@ -248,12 +262,12 @@
|
||||
{/await}
|
||||
{/if}
|
||||
|
||||
<form on:submit|preventDefault={submit} class="flex flex-col gap-4 h-full">
|
||||
<slot name="formtitle">
|
||||
<form onsubmit={preventDefault(submit)} class="flex flex-col gap-4 h-full">
|
||||
{#if formtitle}{@render formtitle()}{:else}
|
||||
<Header class="font-bold text-xl">
|
||||
{edit ? $t('form.post.edit') : $t('form.post.create')}
|
||||
</Header>
|
||||
</slot>
|
||||
{/if}
|
||||
<ErrorContainer scope="post-form" />
|
||||
{#if !edit && data}
|
||||
{#if !data.community}
|
||||
@@ -285,12 +299,13 @@
|
||||
alignment="left"
|
||||
size="sm"
|
||||
>
|
||||
<Avatar
|
||||
url={data.community.icon}
|
||||
alt={data.community.name}
|
||||
width={24}
|
||||
slot="prefix"
|
||||
/>
|
||||
{#snippet prefix()}
|
||||
<Avatar
|
||||
url={data.community.icon}
|
||||
alt={data.community.name}
|
||||
width={24}
|
||||
/>
|
||||
{/snippet}
|
||||
<div class="flex flex-col gap-0">
|
||||
<span class="text-xs">{data.community.name}</span>
|
||||
<span class="text-[10px] leading-3">
|
||||
@@ -326,7 +341,9 @@
|
||||
<div
|
||||
class="border border-slate-100 rounded-xl h-6 w-6 grid place-items-center"
|
||||
>
|
||||
<Icon src={Plus} size="16" micro slot="prefix" />
|
||||
{#snippet prefix()}
|
||||
<Icon src={Plus} size="16" micro />
|
||||
{/snippet}
|
||||
</div>
|
||||
{#if data.url}
|
||||
<Button
|
||||
@@ -336,12 +353,9 @@
|
||||
color="ghost"
|
||||
class="text-xs"
|
||||
>
|
||||
<Icon
|
||||
src={ChatBubbleBottomCenterText}
|
||||
size="15"
|
||||
micro
|
||||
slot="prefix"
|
||||
/>{$t('form.post.altText')}
|
||||
{#snippet prefix()}
|
||||
<Icon src={ChatBubbleBottomCenterText} size="15" micro />
|
||||
{/snippet}{$t('form.post.altText')}
|
||||
</Button>
|
||||
{/if}
|
||||
<Button
|
||||
@@ -351,7 +365,9 @@
|
||||
color="ghost"
|
||||
class="text-xs"
|
||||
>
|
||||
<Icon src={Photo} size="15" micro slot="prefix" />
|
||||
{#snippet prefix()}
|
||||
<Icon src={Photo} size="15" micro />
|
||||
{/snippet}
|
||||
{$t('form.post.uploadImage')}
|
||||
</Button>
|
||||
{#if generation.generatable}
|
||||
@@ -363,7 +379,9 @@
|
||||
color="ghost"
|
||||
class="text-xs"
|
||||
>
|
||||
<Icon src={Sparkles} size="15" micro slot="prefix" />
|
||||
{#snippet prefix()}
|
||||
<Icon src={Sparkles} size="15" micro />
|
||||
{/snippet}
|
||||
{$t('form.post.generateTitle')}
|
||||
</Button>
|
||||
{/if}
|
||||
@@ -433,7 +451,7 @@
|
||||
</div>
|
||||
{/if}
|
||||
{/if}
|
||||
<div class="mt-auto" />
|
||||
<div class="mt-auto"></div>
|
||||
<div class="flex flex-row items-center gap-2 w-full">
|
||||
<Button
|
||||
submit
|
||||
|
||||
Reference in new issue
Block a user