From f174c644506056cf3fdd4d2f579423e0e29831e2 Mon Sep 17 00:00:00 2001 From: Xyphyn Date: Wed, 16 Aug 2023 16:19:35 -0700 Subject: [PATCH] feat: add better community search, close #102 --- src/lib/components/input/SearchInput.svelte | 8 +-- .../lemmy/ObjectAutocomplete.svelte | 54 +++++++++++++++++++ src/lib/components/lemmy/post/PostForm.svelte | 26 +++------ 3 files changed, 67 insertions(+), 21 deletions(-) create mode 100644 src/lib/components/lemmy/ObjectAutocomplete.svelte diff --git a/src/lib/components/input/SearchInput.svelte b/src/lib/components/input/SearchInput.svelte index c2a641f8..4b1dea24 100644 --- a/src/lib/components/input/SearchInput.svelte +++ b/src/lib/components/input/SearchInput.svelte @@ -39,9 +39,11 @@ /> {#each options as option} - extractSelected(option)}> - {extractName(option)} - + + extractSelected(option)}> + {extractName(option)} + + {/each} diff --git a/src/lib/components/lemmy/ObjectAutocomplete.svelte b/src/lib/components/lemmy/ObjectAutocomplete.svelte new file mode 100644 index 00000000..4d73977f --- /dev/null +++ b/src/lib/components/lemmy/ObjectAutocomplete.svelte @@ -0,0 +1,54 @@ + + +{#if type == 'community'} + { + const results = await getClient().search({ + q: q, + auth: jwt, + type_: 'Communities', + limit: 20, + listing_type: listing_type, + sort: 'TopAll', + }) + + items = results.communities.map((c) => c.community) + }} + debounceTime={600} + extractName={(c) => c.title} + bind:query={q} + extractSelected={(c) => { + if (c) dispatcher('select', c) + }} + let:extractName + let:extractSelected + let:option + > + extractSelected(option)}> + +
+ {option.title} + + {new URL(option.actor_id).hostname} + +
+
+
+{/if} diff --git a/src/lib/components/lemmy/post/PostForm.svelte b/src/lib/components/lemmy/post/PostForm.svelte index 6ab10997..4c356395 100644 --- a/src/lib/components/lemmy/post/PostForm.svelte +++ b/src/lib/components/lemmy/post/PostForm.svelte @@ -14,6 +14,8 @@ import { placeholders } from '$lib/util.js' import Checkbox from '$lib/components/input/Checkbox.svelte' import { getSessionStorage, setSessionStorage } from '$lib/session.js' + import MenuButton from '$lib/components/ui/menu/MenuButton.svelte' + import ObjectAutocomplete from '$lib/components/lemmy/ObjectAutocomplete.svelte' export let edit = false @@ -184,24 +186,12 @@ /> {/if} - { - const results = await getClient().search({ - q: communitySearch, - auth: $profile?.jwt, - type_: 'Communities', - limit: 20, - listing_type: 'Subscribed', - sort: 'Active', - }) - - communities = results.communities.map((c) => c.community) - }} - debounceTime={600} - extractName={(c) => c.title} - bind:query={communitySearch} - extractSelected={(c) => { + { + const c = e.detail if (!c) { data.community = null return