migrate: use svelte 5 event system
This commit is contained in:
1 parent
dd9abe5345
commit
9025f5db18
18 files changed
+70
-60
No files matched your search
@@ -62,6 +62,7 @@
|
||||
style?: string
|
||||
class?: string
|
||||
badges?: import('svelte').Snippet
|
||||
onhide?: (hide: boolean) => void
|
||||
}
|
||||
|
||||
let {
|
||||
@@ -72,6 +73,7 @@
|
||||
style = '',
|
||||
class: clazz = '',
|
||||
badges,
|
||||
onhide,
|
||||
}: Props = $props()
|
||||
|
||||
let tags = $derived(parseTags(post.post.name))
|
||||
@@ -186,7 +188,7 @@
|
||||
/>
|
||||
{/if}
|
||||
{#if actions}
|
||||
<PostActions on:hide bind:post style="grid-area: actions;" {view} />
|
||||
<PostActions {onhide} bind:post style="grid-area: actions;" {view} />
|
||||
{:else if view == 'compact'}
|
||||
<div class="flex flex-row items-center gap-2 text-sm">
|
||||
<Badge>
|
||||
|
||||
@@ -66,13 +66,9 @@
|
||||
formatRelativeDate,
|
||||
} from '$lib/components/util/RelativeDate.svelte'
|
||||
|
||||
const dispatcher = createEventDispatcher<{ edit: PostView; hide: boolean }>()
|
||||
|
||||
let editing = $state(false)
|
||||
let saving = $state(false)
|
||||
|
||||
let translating = $state(false)
|
||||
|
||||
let localShare = $state(false)
|
||||
|
||||
interface Props {
|
||||
@@ -80,6 +76,8 @@
|
||||
view?: View
|
||||
debug?: boolean
|
||||
style?: string
|
||||
onedit?: (post: PostView) => void
|
||||
onhide?: (hide: boolean) => void
|
||||
}
|
||||
|
||||
let {
|
||||
@@ -87,6 +85,8 @@
|
||||
view = 'cozy',
|
||||
debug = $bindable(false),
|
||||
style = '',
|
||||
onedit,
|
||||
onhide,
|
||||
}: Props = $props()
|
||||
let buttonHeight = $derived(view == 'compact' ? 'h-7' : 'h-8')
|
||||
let buttonSquare = $derived(view == 'compact' ? 'w-7 h-7' : 'w-8 h-8')
|
||||
@@ -105,10 +105,10 @@
|
||||
<PostForm
|
||||
edit
|
||||
editingPost={post.post}
|
||||
on:submit={(e) => {
|
||||
onsubmit={(e) => {
|
||||
editing = false
|
||||
post = e.detail
|
||||
dispatcher('edit', e.detail)
|
||||
post = e
|
||||
onedit?.(e)
|
||||
}}
|
||||
>
|
||||
{#snippet formtitle()}
|
||||
@@ -431,9 +431,7 @@
|
||||
$profile?.jwt,
|
||||
)
|
||||
post.hidden = hidden
|
||||
if (hidden) {
|
||||
dispatcher('hide', hidden)
|
||||
}
|
||||
if (hidden) onhide?.(hidden)
|
||||
}}
|
||||
color="danger-subtle"
|
||||
>
|
||||
|
||||
@@ -38,7 +38,6 @@
|
||||
} from '$lib/lemmy/postfeed'
|
||||
import { t } from '$lib/translations'
|
||||
import InfiniteScroll from 'svelte-infinite-scroll'
|
||||
import type { Readable } from 'svelte/motion'
|
||||
import EndPlaceholder from '$lib/components/ui/EndPlaceholder.svelte'
|
||||
|
||||
let virtualItemEls: HTMLElement[] = $state([])
|
||||
@@ -252,7 +251,7 @@
|
||||
: settings.view}
|
||||
{post}
|
||||
class="transition-all duration-250"
|
||||
on:hide={() => {
|
||||
onhide={() => {
|
||||
posts = posts.toSpliced(row.index, 1)
|
||||
}}
|
||||
></Post>
|
||||
|
||||
@@ -56,6 +56,7 @@
|
||||
language_id?: number | string
|
||||
}
|
||||
formtitle?: import('svelte').Snippet
|
||||
onsubmit?: (post: PostView) => void
|
||||
}
|
||||
|
||||
let {
|
||||
@@ -75,10 +76,12 @@
|
||||
language_id: undefined,
|
||||
}),
|
||||
formtitle,
|
||||
onsubmit,
|
||||
}: Props = $props()
|
||||
|
||||
// weird select menu language handling
|
||||
// @ts-ignore
|
||||
run(() => {
|
||||
$effect(() => {
|
||||
if (data.language_id === '') data.language_id = undefined
|
||||
})
|
||||
|
||||
@@ -87,8 +90,6 @@
|
||||
|
||||
let communities: Community[] = $state([])
|
||||
|
||||
const dispatcher = createEventDispatcher<{ submit: PostView }>()
|
||||
|
||||
onMount(async () => {
|
||||
if (editingPost) {
|
||||
data.url = editingPost.url ?? ''
|
||||
@@ -166,7 +167,7 @@
|
||||
|
||||
console.log(`Edited post ${post?.post_view.post.id}`)
|
||||
|
||||
dispatcher('submit', post.post_view)
|
||||
onsubmit?.(post.post_view)
|
||||
} else {
|
||||
const post = await client().createPost({
|
||||
community_id: data.community!.id,
|
||||
@@ -184,7 +185,7 @@
|
||||
console.log(`Uploaded post ${post?.post_view.post.id}`)
|
||||
|
||||
saveDraft = false
|
||||
dispatcher('submit', post.post_view)
|
||||
onsubmit?.(post.post_view)
|
||||
}
|
||||
} catch (err) {
|
||||
pushError({ message: errorMessage(err as any), scope: 'post-form' })
|
||||
|
||||
Reference in new issue
Block a user