feat: add sort to community search page

This commit is contained in:
Xyphyn committed 2023-09-03 18:12:10 -07:00
1 parent d3ba6d969c
commit e9168d055e
7 files changed
+79 -55

No files matched your search

+1 -1
View File
@@ -8,7 +8,7 @@
export let selected: string
export let navigate: boolean = true
let sort: string
let sort: string = selected
const setSelected = () => (selected = sort)
</script>
+6 -14
View File
@@ -10,7 +10,7 @@
import { addAdmin } from '$lib/lemmy/user.js'
import { removeItem, trycatch } from '$lib/util.js'
import { Button } from 'mono-svelte'
import { Plus, QuestionMarkCircle, Trash } from 'svelte-hero-icons'
import { Icon, Plus, QuestionMarkCircle, Trash } from 'svelte-hero-icons'
export let data
@@ -61,11 +61,9 @@
{#each data.site?.admins ?? [] as admin}
<div class="py-3 flex items-center justify-between">
<UserLink avatar showInstance={false} user={admin.person} />
<Button
on:click={() => action(admin.person.id)}
icon={Trash}
size="square-md"
/>
<Button on:click={() => action(admin.person.id)} size="square-md">
<Icon src={Trash} mini size="16" />
</Button>
</div>
{/each}
{/if}
@@ -98,14 +96,8 @@
class="flex-1"
pattern={'@[^ |]{1,}'}
/>
<Button
loading={adding}
disabled={adding}
icon={Plus}
size="md"
class="h-full"
submit
>
<Button loading={adding} disabled={adding} size="md" class="h-full" submit>
<Icon src={Plus} mini size="16" slot="prefix" />
Add Admin
</Button>
</form>
@@ -119,11 +119,9 @@
</span>
</div>
</div>
<Button
size="square-md"
on:click={() => action(moderator.moderator)}
icon={Trash}
/>
<Button size="square-md" on:click={() => action(moderator.moderator)}>
<Icon src={Trash} mini size="16" />
</Button>
</div>
{/each}
</EditableList>
+18 -8
View File
@@ -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}
+30 -18
View File
@@ -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,
}
}
}
+17 -7
View File
@@ -22,8 +22,8 @@
PersonView,
PostView,
} from 'lemmy-js-client'
import { Button } from 'mono-svelte'
import { Icon, MagnifyingGlass } from 'svelte-hero-icons'
import { Button, Select } from 'mono-svelte'
import { Bars3BottomRight, Icon, MagnifyingGlass } from 'svelte-hero-icons'
import { expoInOut, expoOut } from 'svelte/easing'
import { fly, slide } from 'svelte/transition'
@@ -42,11 +42,21 @@
<h1 class="font-bold text-2xl">Search</h1>
<div class="flex flex-row flex-wrap sm:justify-between items-center gap-4 mt-4">
<MultiSelect
options={['All', 'Posts', 'Comments', 'Communities', 'Users']}
selected={$page.url.searchParams.get('type') ?? 'All'}
on:select={(e) => searchParam($page.url, 'type', e.detail, 'page')}
/>
<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={Bars3BottomRight} mini size="15" />
Type
</span>
<option value="All">All</option>
<option value="Local">Posts</option>
<option value="Comments">Comments</option>
<option value="Communities">Communities</option>
<option value="Users">Users</option>
</Select>
<div class="flex flex-row gap-2 items-center">
<TextInput
bind:value={query}
+4 -2
View File
@@ -16,8 +16,8 @@ export async function load({ url, fetch }) {
const query = url.searchParams.get('q')
const page = Number(url.searchParams.get('page')) || 1
const community = url.searchParams.get('community_name')
const sort = url.searchParams.get('sort')
const type = url.searchParams.get('type')
const sort = url.searchParams.get('sort') || 'New'
const type = url.searchParams.get('type') || 'All'
if (query) {
const results = await getClient(undefined, fetch).search({
@@ -44,6 +44,8 @@ export async function load({ url, fetch }) {
)
return {
type: type,
sort: sort,
page: page,
results: everything,
streamed: {