feat: Add search to communities
This commit is contained in:
1 parent
699e9e68d1
commit
97748f49a0
4 files changed
+54
-21
No files matched your search
@@ -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,
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -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>
|
||||
|
||||
@@ -119,5 +119,5 @@
|
||||
optionNames={['Hot', 'New', 'Top']}
|
||||
selected="hot"
|
||||
/>
|
||||
<Comments nodes={buildCommentsTree(comments, false)} isParent={true} />
|
||||
</div>
|
||||
<Comments nodes={buildCommentsTree(comments, false)} isParent={true} />
|
||||
@@ -9,7 +9,7 @@
|
||||
export let open = true
|
||||
</script>
|
||||
|
||||
<li class="py-2">
|
||||
<li class="py-3">
|
||||
<details {open} class="flex flex-col gap-1">
|
||||
<summary class="flex flex-row cursor-pointer arrow gap-2 items-center">
|
||||
<Avatar
|
||||
|
||||
Reference in new issue
Block a user