migrate: switch to svelte 5 events system for everything

This commit is contained in:
James Xylight committed 2025-02-05 19:29:54 -08:00
1 parent 43a857ed66
commit 53cb0e4f20
27 files changed
+248 -303

No files matched your search

@@ -1,8 +1,9 @@
<script lang="ts">
import Avatar from '$lib/components/ui/Avatar.svelte'
import { getClient } from '$lib/lemmy.js'
import type { Community, ListingType } from 'lemmy-js-client'
import type { Community, CommunityView, ListingType } from 'lemmy-js-client'
import { MenuButton, Search } from 'mono-svelte'
import type { SearchProps } from 'mono-svelte/search/Search.svelte'
import { createEventDispatcher } from 'svelte'
import { Icon, XCircle, ServerStack } from 'svelte-hero-icons'
import { fly } from 'svelte/transition'
@@ -13,6 +14,7 @@
instance?: string | undefined
listing_type?: ListingType
showWhenEmpty?: boolean
onselect?: (item: any) => void
[key: string]: any
}
@@ -45,9 +47,7 @@
return results.communities.map((c) => c.community)
}}
extractName={(c) => `${c.title}@${new URL(c.actor_id).hostname}`}
on:select
bind:query={q}
{showWhenEmpty}
{...rest}
>
{#snippet noresults()}
@@ -90,9 +90,7 @@
: []
}}
extractName={(i) => `${i.domain}`}
on:select
bind:query={q}
{showWhenEmpty}
{...rest}
>
{#snippet noresults()}
@@ -175,9 +175,9 @@
<ImageUploadModal
bind:open={uploading.icon}
multiple={false}
on:upload={(uploaded) => {
onupload={(uploaded) => {
uploading.icon = false
formData.icon = uploaded.detail[0]
formData.icon = uploaded[0]
}}
/>
{/if}
@@ -203,9 +203,9 @@
<ImageUploadModal
bind:open={uploading.banner}
multiple={false}
on:upload={(uploaded) => {
onupload={(uploaded) => {
uploading.banner = false
formData.banner = uploaded.detail[0]
formData.banner = uploaded[0]
}}
/>
{/if}
@@ -1,6 +1,4 @@
<script lang="ts">
import { preventDefault } from 'svelte/legacy'
import { profile } from '$lib/auth.svelte.js'
import ProgressBar from '$lib/components/ui/ProgressBar.svelte'
import { errorMessage } from '$lib/lemmy/error'
@@ -8,7 +6,6 @@
import { uploadImage } from '$lib/util.svelte.js'
import { ImageInput, Spinner, toast } from 'mono-svelte'
import { Button, Modal } from 'mono-svelte'
import { createEventDispatcher } from 'svelte'
import { DocumentPlus, Icon } from 'svelte-hero-icons'
import { expoOut } from 'svelte/easing'
import { slide } from 'svelte/transition'
@@ -18,6 +15,7 @@
image?: FileList | null
preview?: boolean
multiple?: boolean
onupload?: (urls: string[]) => void
}
let {
@@ -25,6 +23,7 @@
image = $bindable(null),
preview = true,
multiple = true,
onupload,
}: Props = $props()
let progress = $state(1)
@@ -32,8 +31,6 @@
preview && image ? Array.from(image).map(URL.createObjectURL) : undefined,
)
const dispatcher = createEventDispatcher<{ upload: string[] }>()
async function upload() {
if (!$profile?.jwt || image == null) return
@@ -58,7 +55,7 @@
if (!uploaded) throw new Error('Image upload returned undefined')
dispatcher('upload', uploaded)
onupload?.(uploaded)
progress = 1
open = false
} catch (err) {
@@ -81,7 +78,13 @@
<ProgressBar {progress} />
</div>
{/if}
<form class="flex flex-col gap-4" onsubmit={preventDefault(upload)}>
<form
class="flex flex-col gap-4"
onsubmit={(e) => {
e.preventDefault()
upload()
}}
>
<label
for="image-input"
class="p-4 border-2 border-dashed rounded-xl cursor-pointer transition-colors
@@ -176,11 +176,6 @@
}
})
// onMount(async () => {
// await tick()
// $virtualizer.measure()
// })
let items = $derived($virtualizer.getVirtualItems())
$effect(() => {
if (virtualItemEls.length)
@@ -195,8 +190,6 @@
})
</script>
<!-- <svelte:window on:keydown={handleKeydown} /> -->
<ul
class="flex flex-col list-none divide-y divide-slate-200 dark:divide-zinc-800"
>
@@ -258,8 +258,8 @@
<UploadModal
bind:open={uploadingImage}
multiple={false}
on:upload={(e) => {
if (e.detail) data.url = e.detail[0]
onupload={(e) => {
if (e) data.url = e[0]
uploadingImage = false
}}
/>
@@ -282,8 +282,8 @@
listing_type="All"
label={$t('form.post.community')}
required
on:select={(e) => {
const c = e.detail
onselect={(e) => {
const c = e
if (!c) {
data.community = null
return
@@ -12,6 +12,7 @@
instance?: string | undefined
listing_type?: ListingType
showWhenEmpty?: boolean
onselect?: (e: any) => void
[key: string]: any
}
@@ -39,9 +40,7 @@
return results.users.map((c) => c.person)
}}
extractName={(c) => `${c.name}@${new URL(c.actor_id).hostname}`}
on:select
bind:query={q}
{showWhenEmpty}
{...rest}
>
{#snippet noresults()}
@@ -125,8 +125,8 @@
<ImageUploadModal
bind:open={uploadingImage}
bind:image
on:upload={(e) => {
e.detail.forEach((i) => {
onupload={(e) => {
e.forEach((i) => {
wrapSelection(`![](${i})\n\n`, '')
})
}}
@@ -1,23 +0,0 @@
<script lang="ts">
import { createEventDispatcher } from 'svelte'
type T = $$Generic
const dispatcher = createEventDispatcher<{ action: any }>()
function action(detail: any) {
dispatcher('action', detail)
}
interface Props {
class?: string
children?: import('svelte').Snippet<[any]>
}
let { class: clazz = '', children }: Props = $props()
</script>
<ul
class="divide-y divide-slate-200 dark:divide-zinc-900 flex flex-col {clazz}"
>
{@render children?.({ action })}
</ul>
@@ -1,13 +0,0 @@
<script>
/**
* @typedef {Object} Props
* @property {import('svelte').Snippet} [children]
*/
/** @type {Props} */
let { children } = $props()
</script>
<div class="p-2 flex flex-row">
{@render children?.()}
</div>