feat: Add search to communities

This commit is contained in:
Xyphyn committed 2023-07-01 18:08:55 -07:00
1 parent 699e9e68d1
commit 97748f49a0
4 files changed
+54 -21

No files matched your search

+18 -6
View File
@@ -4,11 +4,23 @@ import type { ListingType } from 'lemmy-js-client'
export function load(req) {
const type = req.url.searchParams.get('listingType') as ListingType
const page = Number(req.url.searchParams.get('page')) || 1
const query = req.url.searchParams.get('q')
return lemmy.listCommunities({
limit: 40,
page: page,
sort: 'Active',
type_: type,
})
if (query) {
return lemmy.search({
limit: 40,
page: page,
sort: 'Active',
type_: 'Communities',
listing_type: type,
q: query,
})
} else {
return lemmy.listCommunities({
limit: 40,
page: page,
sort: 'Active',
type_: type,
})
}
}
+34 -13
View File
@@ -10,23 +10,44 @@
UserGroup,
} from 'svelte-hero-icons'
import CommunityLink from '$lib/components/CommunityLink.svelte'
import Link from '$lib/components/Link.svelte'
import { Color } from '$lib/ui/colors.js'
export let data
let search = ''
</script>
<MultiSelect
options={['Subscribed', 'Local', 'All']}
selected={$page.url.searchParams.get('type') ?? 'Local'}
on:select={(e) => {
const url = $page.url
url.searchParams.set('type', e.detail)
url.searchParams.delete('page')
goto(url, {
invalidateAll: true,
})
}}
/>
<div class="flex flex-col sm:flex-row gap-4">
<MultiSelect
options={['Subscribed', 'Local', 'All']}
selected={$page.url.searchParams.get('type') ?? 'Local'}
on:select={(e) => {
const url = $page.url
url.searchParams.set('type', e.detail)
url.searchParams.delete('page')
goto(url, {
invalidateAll: true,
})
}}
/>
<div class="flex flex-col sm:flex-row gap-2 sm:ml-auto">
<input
class="bg-slate-100 border border-slate-200 dark:border-zinc-800
dark:bg-zinc-900 rounded-md"
bind:value={search}
/>
<Link
href={(function () {
$page.url.searchParams.set('q', search)
return $page.url.toString()
})()}
color={Color.ghost}
>
Search
</Link>
</div>
</div>
<ul class="flex flex-col">
{#each data.communities as community}
<li>