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) { export function load(req) {
const type = req.url.searchParams.get('listingType') as ListingType const type = req.url.searchParams.get('listingType') as ListingType
const page = Number(req.url.searchParams.get('page')) || 1 const page = Number(req.url.searchParams.get('page')) || 1
const query = req.url.searchParams.get('q')
return lemmy.listCommunities({ if (query) {
limit: 40, return lemmy.search({
page: page, limit: 40,
sort: 'Active', page: page,
type_: type, 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, UserGroup,
} from 'svelte-hero-icons' } from 'svelte-hero-icons'
import CommunityLink from '$lib/components/CommunityLink.svelte' import CommunityLink from '$lib/components/CommunityLink.svelte'
import Link from '$lib/components/Link.svelte'
import { Color } from '$lib/ui/colors.js'
export let data export let data
let search = ''
</script> </script>
<MultiSelect <div class="flex flex-col sm:flex-row gap-4">
options={['Subscribed', 'Local', 'All']} <MultiSelect
selected={$page.url.searchParams.get('type') ?? 'Local'} options={['Subscribed', 'Local', 'All']}
on:select={(e) => { selected={$page.url.searchParams.get('type') ?? 'Local'}
const url = $page.url on:select={(e) => {
url.searchParams.set('type', e.detail) const url = $page.url
url.searchParams.delete('page') url.searchParams.set('type', e.detail)
goto(url, { url.searchParams.delete('page')
invalidateAll: true, 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"> <ul class="flex flex-col">
{#each data.communities as community} {#each data.communities as community}
<li> <li>
+1 -1
View File
@@ -119,5 +119,5 @@
optionNames={['Hot', 'New', 'Top']} optionNames={['Hot', 'New', 'Top']}
selected="hot" selected="hot"
/> />
<Comments nodes={buildCommentsTree(comments, false)} isParent={true} />
</div> </div>
<Comments nodes={buildCommentsTree(comments, false)} isParent={true} />
+1 -1
View File
@@ -9,7 +9,7 @@
export let open = true export let open = true
</script> </script>
<li class="py-2"> <li class="py-3">
<details {open} class="flex flex-col gap-1"> <details {open} class="flex flex-col gap-1">
<summary class="flex flex-row cursor-pointer arrow gap-2 items-center"> <summary class="flex flex-row cursor-pointer arrow gap-2 items-center">
<Avatar <Avatar