impr: rewrite PostForm component to be stabler and more sustainable (#684)

* impr: rewrite PostForm component into extracted state class

* fix: use base community as PostFormState

* fix: add else clause to ensure 'unset' unsets the language
This commit is contained in:
xylight authored and GitHub committed 2025-11-15 23:12:52 +00:00
1 parent 6f7501ffc5
commit e4507cbf91
16 files changed
+506 -586

No files matched your search

@@ -16,6 +16,7 @@
placeholder?: string
onselect?: (item: any) => void
label?: string
required?: boolean
}
let {
@@ -24,6 +25,7 @@
instance = undefined,
listing_type = 'Subscribed',
showWhenEmpty = false,
required,
...rest
}: Props = $props()
@@ -49,6 +51,7 @@
extractName={(c) =>
`${c.community.name}@${new URL(c.community.actor_id).hostname}`}
bind:query={q}
{required}
{...rest}
>
{#snippet noresults()}
+6 -2
View File
@@ -26,17 +26,18 @@
})
interface Props {
scope?: string | undefined | null
message?: string
class?: string
}
let { scope = undefined, class: clazz = '' }: Props = $props()
let { scope, message, class: clazz = '' }: Props = $props()
let scopedErrors = $derived(
errors.filter((e) => e.scope == scope || e.scope == 'global'),
)
</script>
{#if scopedErrors.length > 0}
{#if scopedErrors.length > 0 || message}
<div
class={['flex flex-col gap-4', clazz]}
in:slide={{ duration: 400, easing: expoOut }}
@@ -59,6 +60,9 @@
micro
class="inline-block rounded-lg clear-both float-left mr-2"
/>
{#if message}
{message}
{/if}
{#each scopedErrors as error}
<p>{error.message}</p>
{/each}
+1
View File
@@ -58,6 +58,7 @@
xl: 'rounded-xl',
lg: 'rounded-lg',
md: 'rounded-md',
inherit: 'rounded-[inherit]',
none: '',
}
type ButtonRoundness = keyof typeof buttonRounding
+10 -8
View File
@@ -35,16 +35,18 @@
.btn-group.btn-group-horizontal {
flex-direction: row;
}
:global(*) {
position: relative;
&:first-child {
border-radius: 24px 8px 8px 24px !important;
}
.btn-group.btn-group-horizontal :global(> *) {
position: relative;
border-radius: 8px 8px 8px 8px !important;
&:last-child {
border-radius: 8px 24px 24px 8px !important;
}
&:first-child {
border-radius: 24px 12px 12px 24px !important;
}
&:last-child {
border-radius: 12px 24px 24px 12px !important;
}
}
</style>
+2 -1
View File
@@ -101,6 +101,7 @@
{disabled}
bind:value
bind:this={element}
{required}
{...rest}
class={[
sizeClass[size],
@@ -118,7 +119,7 @@
{#if suffix}
<div
class={[
'rounded-xl rounded-l-none text-slate-600 dark:text-zinc-400',
'rounded-xl rounded-l-none text-slate-600 dark:text-zinc-400 h-full',
inlineAffixes && 'bg-white dark:bg-zinc-900 pl-0',
]}
>
@@ -12,7 +12,7 @@
bind:open={$shownModal}
>
{#if $shownModal.snippet}
{@render $shownModal.snippet()}
{@render $shownModal.snippet?.()}
{/if}
{#if $shownModal.body}
<p>{$shownModal.body}</p>
+3
View File
@@ -12,6 +12,7 @@
select?: (item: T) => void
input?: import('svelte').Snippet
noresults?: import('svelte').Snippet
required?: boolean
children?: import('svelte').Snippet<
[
{
@@ -47,6 +48,7 @@
query = extractName(item)
onselect?.(item)
},
required,
input,
noresults,
children,
@@ -82,6 +84,7 @@
oninput?.(e)
debounceFunc()
}}
{required}
{...rest}
inlineAffixes
>