feat: add community filters

This commit is contained in:
Xyphyn committed 2023-08-23 17:10:41 -07:00
1 parent 693f2f9a08
commit 5507cf8254
6 files changed
+178 -33

No files matched your search

+13 -8
View File
@@ -12,6 +12,7 @@
export let options: T[]
export let extractSelected: (item: T | null) => any
export let extractName: (item: T) => string
export let showWhenEmpty: boolean = false
const debounce = (fn: Function, ms = 300) => {
let timeoutId: ReturnType<typeof setTimeout>
@@ -37,13 +38,17 @@
}}
{...$$restProps}
/>
<Menu open={options.length != 0} alignment="bottom-left">
{#each options as option}
<slot {extractName} {extractSelected} {option}>
<MenuButton on:click={() => extractSelected(option)}>
{extractName(option)}
</MenuButton>
</slot>
{/each}
<Menu open={options.length != 0 || showWhenEmpty} alignment="bottom-left">
{#if query == ''}
<slot {extractName} {extractSelected} {query} />
{:else}
{#each options as option}
<slot {extractName} {extractSelected} {option} {query}>
<MenuButton on:click={() => extractSelected(option)}>
{extractName(option)}
</MenuButton>
</slot>
{/each}
{/if}
</Menu>
</div>
@@ -5,6 +5,7 @@
import { getClient } from '$lib/lemmy.js'
import type { Community, ListingType } from 'lemmy-js-client'
import { createEventDispatcher } from 'svelte'
import { Icon, XCircle } from 'svelte-hero-icons'
let type: 'community' = 'community'
export let q: string = ''
@@ -12,6 +13,7 @@
export let jwt: string | undefined = undefined
export let listing_type: ListingType = 'Subscribed'
export let items: Community[] | undefined = undefined
let showNone: boolean = false
const dispatcher = createEventDispatcher<{ select: Community }>()
</script>
@@ -20,8 +22,11 @@
<SearchInput
options={items || []}
on:search={async () => {
if (q == '') showNone = true
else showNone = false
const results = await getClient().search({
q: q,
q: q || ' ',
auth: jwt,
type_: 'Communities',
limit: 20,
@@ -40,15 +45,27 @@
let:extractName
let:extractSelected
let:option
showWhenEmpty
{...$$restProps}
let:query
>
<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>
{#if query == ''}
<MenuButton on:click={() => dispatcher('select', undefined)}>
<Icon src={XCircle} size="16" mini />
<div class="flex flex-col text-left">
<span>None</span>
</div>
</MenuButton>
{:else if 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>
{/if}
</SearchInput>
{/if}