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
@@ -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