feat: add sort to community search page
This commit is contained in:
1 parent
d3ba6d969c
commit
e9168d055e
7 files changed
+79
-55
No files matched your search
@@ -4,6 +4,7 @@
|
||||
import { page } from '$app/stores'
|
||||
import {
|
||||
ChatBubbleOvalLeftEllipsis,
|
||||
GlobeAmericas,
|
||||
Icon,
|
||||
PencilSquare,
|
||||
QuestionMarkCircle,
|
||||
@@ -17,7 +18,8 @@
|
||||
import { addSubscription } from '$lib/lemmy/user.js'
|
||||
import { LINKED_INSTANCE_URL } from '$lib/instance.js'
|
||||
import { profile } from '$lib/auth.js'
|
||||
import { Button } from 'mono-svelte'
|
||||
import { Button, Select } from 'mono-svelte'
|
||||
import Sort from '$lib/components/lemmy/Sort.svelte'
|
||||
|
||||
export let data
|
||||
|
||||
@@ -39,13 +41,21 @@
|
||||
page, and search with this syntax:
|
||||
<code>!community@instance.com</code>
|
||||
</p>
|
||||
<div class="flex flex-col sm:flex-row gap-4 mt-4">
|
||||
<MultiSelect
|
||||
options={['Subscribed', 'Local', 'All']}
|
||||
selected={$page.url.searchParams.get('type') ??
|
||||
(LINKED_INSTANCE_URL ? 'Local' : 'All')}
|
||||
on:select={(e) => searchParam($page.url, 'type', e.detail, 'page')}
|
||||
/>
|
||||
<div class="flex flex-row flex-wrap gap-4 mt-4">
|
||||
<Select
|
||||
class="w-48"
|
||||
bind:value={data.type}
|
||||
on:change={() => searchParam($page.url, 'type', data.type ?? 'All', 'page')}
|
||||
>
|
||||
<span slot="label" class="flex items-center gap-1">
|
||||
<Icon src={GlobeAmericas} mini size="15" />
|
||||
Location
|
||||
</span>
|
||||
<option value="All">All</option>
|
||||
<option value="Local">Local</option>
|
||||
<option value="Subscribed">Subscribed</option>
|
||||
</Select>
|
||||
<Sort selected={data.sort} />
|
||||
<div class="flex flex-col sm:flex-row gap-2 sm:ml-auto items-center">
|
||||
<TextInput
|
||||
bind:value={search}
|
||||
|
||||
@@ -1,30 +1,42 @@
|
||||
import { profile } from '$lib/auth.js'
|
||||
import { LINKED_INSTANCE_URL } from '$lib/instance.js'
|
||||
import { getClient } from '$lib/lemmy.js'
|
||||
import type { ListingType } from 'lemmy-js-client'
|
||||
import type { ListingType, SortType } from 'lemmy-js-client'
|
||||
import { get } from 'svelte/store'
|
||||
|
||||
export async function load({ url, fetch }) {
|
||||
const type = url.searchParams.get('type') as ListingType
|
||||
const type =
|
||||
(url.searchParams.get('type') as ListingType) ||
|
||||
(LINKED_INSTANCE_URL ? 'Local' : 'All')
|
||||
const sort = (url.searchParams.get('sort') as SortType) || 'TopAll'
|
||||
const page = Number(url.searchParams.get('page')) || 1
|
||||
const query = url.searchParams.get('q')
|
||||
|
||||
if (query) {
|
||||
return await getClient(undefined, fetch).search({
|
||||
limit: 40,
|
||||
page: page,
|
||||
sort: 'TopAll',
|
||||
type_: 'Communities',
|
||||
listing_type: type,
|
||||
q: query,
|
||||
auth: get(profile)?.jwt,
|
||||
})
|
||||
return {
|
||||
...(await getClient(undefined, fetch).search({
|
||||
limit: 40,
|
||||
page: page,
|
||||
sort: sort,
|
||||
type_: 'Communities',
|
||||
listing_type: type,
|
||||
q: query,
|
||||
auth: get(profile)?.jwt,
|
||||
})),
|
||||
type: type,
|
||||
sort: sort,
|
||||
}
|
||||
} else {
|
||||
return await getClient(undefined, fetch).listCommunities({
|
||||
limit: 40,
|
||||
page: page,
|
||||
sort: 'TopAll',
|
||||
type_: type,
|
||||
auth: get(profile)?.jwt,
|
||||
})
|
||||
return {
|
||||
...(await getClient(undefined, fetch).listCommunities({
|
||||
limit: 40,
|
||||
page: page,
|
||||
sort: sort,
|
||||
type_: type,
|
||||
auth: get(profile)?.jwt,
|
||||
})),
|
||||
type: type,
|
||||
sort: sort,
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user