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
@@ -237,7 +237,7 @@
|
||||
<CommentActions
|
||||
comment={node.comment_view}
|
||||
bind:replying
|
||||
on:edit={() => (editing = true)}
|
||||
onedit={() => (editing = true)}
|
||||
disabled={node.comment_view.banned_from_community ||
|
||||
node.comment_view.post.locked}
|
||||
/>
|
||||
|
||||
@@ -32,18 +32,15 @@
|
||||
comment: CommentView
|
||||
replying?: boolean
|
||||
disabled?: boolean
|
||||
onedit?: (comment: CommentView) => void
|
||||
}
|
||||
|
||||
let {
|
||||
comment = $bindable(),
|
||||
replying = $bindable(false),
|
||||
disabled = false,
|
||||
onedit,
|
||||
}: Props = $props()
|
||||
|
||||
const dispatcher = createEventDispatcher<{ edit: CommentView }>()
|
||||
|
||||
let reply = ''
|
||||
let translating = $state(false)
|
||||
</script>
|
||||
|
||||
<div
|
||||
@@ -97,7 +94,7 @@
|
||||
</MenuButton>
|
||||
{#if $profile?.jwt}
|
||||
{#if comment.creator.id == $profile.user?.local_user_view.person.id}
|
||||
<MenuButton onclick={() => dispatcher('edit', comment)}>
|
||||
<MenuButton onclick={() => onedit?.(comment)}>
|
||||
<Icon src={PencilSquare} mini size="16" />
|
||||
<span>{$t('post.actions.more.edit')}</span>
|
||||
</MenuButton>
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
let { nodes, post, scrollTo }: Props = $props()
|
||||
|
||||
let virtualListEl: HTMLElement | undefined = $state(undefined)
|
||||
let virtualListEl = $state<HTMLElement>()
|
||||
|
||||
let virtualizer = $derived(
|
||||
createWindowVirtualizer({
|
||||
|
||||
@@ -27,7 +27,6 @@ export function buildCommentsTree(
|
||||
baseDepth: number = 0,
|
||||
filter: (c: CommentView) => boolean = (c) => true,
|
||||
): CommentNodeI[] {
|
||||
const start = performance.now()
|
||||
const map = new Map<number, CommentNodeI>()
|
||||
|
||||
let min_depth = Number.MAX_VALUE
|
||||
@@ -69,7 +68,6 @@ export function buildCommentsTree(
|
||||
}
|
||||
}
|
||||
|
||||
console.log(`Built tree in ${performance.now() - start}ms`)
|
||||
return tree
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
<Select
|
||||
{...rest}
|
||||
bind:value={selected}
|
||||
on:change={() => {
|
||||
onchange={() => {
|
||||
if (navigate) searchParam($page.url, 'type', selected, 'page', 'cursor')
|
||||
}}
|
||||
>
|
||||
|
||||
@@ -49,7 +49,7 @@
|
||||
{...rest}
|
||||
class={selected?.startsWith('Top') ? 'rounded-r-none' : ''}
|
||||
bind:value={sort}
|
||||
on:change={(e) => {
|
||||
onchange={() => {
|
||||
setSelected()
|
||||
if (navigate) searchParam($page.url, 'sort', selected, 'page', 'cursor')
|
||||
}}
|
||||
@@ -93,7 +93,7 @@
|
||||
<Select
|
||||
class="border-l-0 rounded-l-none"
|
||||
bind:value={selected}
|
||||
on:change={(e) => {
|
||||
onchange={() => {
|
||||
sort = 'TopAll'
|
||||
if (navigate)
|
||||
searchParam($page.url, 'sort', selected, 'page', 'cursor')
|
||||
|
||||
@@ -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' })
|
||||
|
||||
@@ -19,9 +19,6 @@
|
||||
import Expandable from '$lib/components/ui/Expandable.svelte'
|
||||
import EndPlaceholder from '../EndPlaceholder.svelte'
|
||||
import { t } from '$lib/translations'
|
||||
import { iconOfLink } from '../navbar/link'
|
||||
import { goto } from '$app/navigation'
|
||||
import { page } from '$app/stores'
|
||||
|
||||
interface Props {
|
||||
style?: string
|
||||
|
||||
Reference in new issue
Block a user