diff --git a/src/lib/components/input/SearchInput.svelte b/src/lib/components/input/SearchInput.svelte new file mode 100644 index 00000000..41a9df5d --- /dev/null +++ b/src/lib/components/input/SearchInput.svelte @@ -0,0 +1,49 @@ + + +
+ { + extractSelected(null) + debounceFunc() + }} + {...$$restProps} + /> + + {#each options as option} + extractSelected(option)}> + {extractName(option)} + + {/each} + +
diff --git a/src/lib/components/lemmy/post/PostForm.svelte b/src/lib/components/lemmy/post/PostForm.svelte index 0b4fda4b..d6b0ce4d 100644 --- a/src/lib/components/lemmy/post/PostForm.svelte +++ b/src/lib/components/lemmy/post/PostForm.svelte @@ -10,6 +10,8 @@ import Button from '$lib/components/input/Button.svelte' import { ToastType, toast } from '$lib/components/ui/toasts/toasts.js' import { goto } from '$app/navigation' + import SearchInput from '$lib/components/input/SearchInput.svelte' + import { Check, Icon } from 'svelte-hero-icons' export let edit = false @@ -53,7 +55,7 @@ const placeholder2 = placeholders[Math.floor(Math.random() * placeholders.length)] - let communities: Community[] | undefined + let communities: Community[] = [] const dispatcher = createEventDispatcher<{ submit: PostView }>() @@ -66,8 +68,8 @@ const list = await getClient().listCommunities({ auth: $authData?.token, - type_: 'Subscribed', - sort: 'New', + type_: 'All', + sort: 'Active', limit: 40, }) @@ -75,7 +77,14 @@ }) async function submit() { - if ((!data.community && !edit) || !data.title || !$authData) return + if (!data.community && !edit) { + toast({ + type: ToastType.warning, + content: 'You need to set a community.', + }) + return + } + if (!data.title || !$authData) return data.loading = true @@ -119,24 +128,53 @@ toast({ content: err as any, type: ToastType.error }) } } + + let communitySearch = ''

{edit ? 'Edit' : 'Create'} Post

{#if !edit}
- - Community * - - {#if communities} - c.id)} - optionNames={new Map(communities.map((c) => [c.id, c.title]))} - /> - {:else} - - {/if} +
+ + Community * + + {#if data.community} + + {/if} +
+ { + const results = await getClient().search({ + q: communitySearch, + auth: $authData?.token, + type_: 'Communities', + limit: 20, + sort: 'Active', + }) + + communities = results.communities.map((c) => c.community) + }} + debounceTime={600} + extractName={(c) => c.title} + bind:query={communitySearch} + extractSelected={(c) => { + if (!c) { + data.community = null + return + } + + data.community = c.id + communitySearch = c.name + }} + />
{/if}