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 { preventDefault } from 'svelte/legacy'
|
||||
|
||||
import { profile } from '$lib/auth.js'
|
||||
import ProgressBar from '$lib/components/ui/ProgressBar.svelte'
|
||||
import { errorMessage } from '$lib/lemmy/error'
|
||||
@@ -11,14 +13,24 @@
|
||||
import { expoOut } from 'svelte/easing'
|
||||
import { slide } from 'svelte/transition'
|
||||
|
||||
export let open: boolean
|
||||
export let image: FileList | null = null
|
||||
export let preview: boolean = true
|
||||
export let multiple: boolean = true
|
||||
let progress = 1
|
||||
interface Props {
|
||||
open: boolean
|
||||
image?: FileList | null
|
||||
preview?: boolean
|
||||
multiple?: boolean
|
||||
}
|
||||
|
||||
$: previewURLs =
|
||||
preview && image ? Array.from(image).map(URL.createObjectURL) : undefined
|
||||
let {
|
||||
open = $bindable(),
|
||||
image = $bindable(null),
|
||||
preview = true,
|
||||
multiple = true,
|
||||
}: Props = $props()
|
||||
let progress = $state(1)
|
||||
|
||||
let previewURLs = $derived(
|
||||
preview && image ? Array.from(image).map(URL.createObjectURL) : undefined,
|
||||
)
|
||||
|
||||
const dispatcher = createEventDispatcher<{ upload: string[] }>()
|
||||
|
||||
@@ -39,8 +51,8 @@
|
||||
.catch((err) => {
|
||||
toast({ content: errorMessage(err), type: 'error' })
|
||||
return 'Failed to upload'
|
||||
})
|
||||
)
|
||||
}),
|
||||
),
|
||||
)
|
||||
).filter((i) => i != undefined)
|
||||
|
||||
@@ -61,13 +73,15 @@
|
||||
</script>
|
||||
|
||||
<Modal bind:open>
|
||||
<div slot="title" class="flex items-center gap-2">Upload image</div>
|
||||
{#snippet title()}
|
||||
<div class="flex items-center gap-2">Upload image</div>
|
||||
{/snippet}
|
||||
{#if progress != 1}
|
||||
<div transition:slide={{ duration: 500, easing: expoOut }} class="w-full">
|
||||
<ProgressBar {progress} />
|
||||
</div>
|
||||
{/if}
|
||||
<form class="flex flex-col gap-4" on:submit|preventDefault={upload}>
|
||||
<form class="flex flex-col gap-4" onsubmit={preventDefault(upload)}>
|
||||
<label
|
||||
for="image-input"
|
||||
class="p-4 border-2 border-dashed rounded-xl cursor-pointer transition-colors
|
||||
@@ -79,10 +93,10 @@
|
||||
{multiple ? 'grid-cols-3 grid-rows-2' : 'grid-cols-1 grid-rows-1'}"
|
||||
>
|
||||
{#each previewURLs as file}
|
||||
<!-- svelte-ignore a11y-missing-attribute -->
|
||||
<!-- svelte-ignore a11y_missing_attribute -->
|
||||
<img
|
||||
src={file}
|
||||
on:load={() => URL.revokeObjectURL(file)}
|
||||
onload={() => URL.revokeObjectURL(file)}
|
||||
alt={file}
|
||||
class="w-full rounded-md h-full object-cover transition-all
|
||||
border border-slate-200 dark:border-zinc-800 ring-1
|
||||
|
||||
Reference in new issue
Block a user