feat: add better community search, close #102
This commit is contained in:
1 parent
5b79dc9c50
commit
f174c64450
3 files changed
+64
-18
No files matched your search
@@ -39,9 +39,11 @@
|
|||||||
/>
|
/>
|
||||||
<Menu open={options.length != 0} alignment="bottom-left">
|
<Menu open={options.length != 0} alignment="bottom-left">
|
||||||
{#each options as option}
|
{#each options as option}
|
||||||
|
<slot {extractName} {extractSelected} {option}>
|
||||||
<MenuButton on:click={() => extractSelected(option)}>
|
<MenuButton on:click={() => extractSelected(option)}>
|
||||||
{extractName(option)}
|
{extractName(option)}
|
||||||
</MenuButton>
|
</MenuButton>
|
||||||
|
</slot>
|
||||||
{/each}
|
{/each}
|
||||||
</Menu>
|
</Menu>
|
||||||
</div>
|
</div>
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import SearchInput from '$lib/components/input/SearchInput.svelte'
|
||||||
|
import Avatar from '$lib/components/ui/Avatar.svelte'
|
||||||
|
import MenuButton from '$lib/components/ui/menu/MenuButton.svelte'
|
||||||
|
import { getClient } from '$lib/lemmy.js'
|
||||||
|
import type { Community, ListingType } from 'lemmy-js-client'
|
||||||
|
import { createEventDispatcher } from 'svelte'
|
||||||
|
|
||||||
|
let type: 'community' = 'community'
|
||||||
|
export let q: string = ''
|
||||||
|
|
||||||
|
export let jwt: string | undefined = undefined
|
||||||
|
export let listing_type: ListingType = 'Subscribed'
|
||||||
|
export let items: Community[] | undefined = undefined
|
||||||
|
|
||||||
|
const dispatcher = createEventDispatcher<{ select: Community }>()
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{#if type == 'community'}
|
||||||
|
<SearchInput
|
||||||
|
options={items || []}
|
||||||
|
on:search={async () => {
|
||||||
|
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
|
||||||
|
>
|
||||||
|
<MenuButton on:click={() => extractSelected(option)}>
|
||||||
|
<Avatar url={option.icon} alt={option.title} width={24} />
|
||||||
|
<div class="flex flex-col text-left">
|
||||||
|
<span>{option.title}</span>
|
||||||
|
<span class="text-xs opacity-80">
|
||||||
|
{new URL(option.actor_id).hostname}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</MenuButton>
|
||||||
|
</SearchInput>
|
||||||
|
{/if}
|
||||||
@@ -14,6 +14,8 @@
|
|||||||
import { placeholders } from '$lib/util.js'
|
import { placeholders } from '$lib/util.js'
|
||||||
import Checkbox from '$lib/components/input/Checkbox.svelte'
|
import Checkbox from '$lib/components/input/Checkbox.svelte'
|
||||||
import { getSessionStorage, setSessionStorage } from '$lib/session.js'
|
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
|
export let edit = false
|
||||||
|
|
||||||
@@ -184,24 +186,12 @@
|
|||||||
/>
|
/>
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
<SearchInput
|
<ObjectAutocomplete
|
||||||
options={communities}
|
bind:q={communitySearch}
|
||||||
on:search={async () => {
|
bind:items={communities}
|
||||||
const results = await getClient().search({
|
jwt={$profile?.jwt}
|
||||||
q: communitySearch,
|
on:select={(e) => {
|
||||||
auth: $profile?.jwt,
|
const c = e.detail
|
||||||
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) => {
|
|
||||||
if (!c) {
|
if (!c) {
|
||||||
data.community = null
|
data.community = null
|
||||||
return
|
return
|
||||||
|
|||||||
Reference in new issue
Block a user