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
+36 -3

No files matched your search

+12
View File
@@ -4,7 +4,18 @@ 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')
if (query) {
return lemmy.search({
limit: 40,
page: page,
sort: 'Active',
type_: 'Communities',
listing_type: type,
q: query,
})
} else {
return lemmy.listCommunities({ return lemmy.listCommunities({
limit: 40, limit: 40,
page: page, page: page,
@@ -12,3 +23,4 @@ export function load(req) {
type_: type, type_: type,
}) })
} }
}
+22 -1
View File
@@ -10,10 +10,15 @@
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>
<div class="flex flex-col sm:flex-row gap-4">
<MultiSelect <MultiSelect
options={['Subscribed', 'Local', 'All']} options={['Subscribed', 'Local', 'All']}
selected={$page.url.searchParams.get('type') ?? 'Local'} selected={$page.url.searchParams.get('type') ?? 'Local'}
@@ -26,7 +31,23 @@
}) })
}} }}
/> />
<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"
/> />
</div>
<Comments nodes={buildCommentsTree(comments, false)} isParent={true} /> <Comments nodes={buildCommentsTree(comments, false)} isParent={true} />
</div>
+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