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
@@ -8,7 +8,7 @@
|
|||||||
export let selected: string
|
export let selected: string
|
||||||
export let navigate: boolean = true
|
export let navigate: boolean = true
|
||||||
|
|
||||||
let sort: string
|
let sort: string = selected
|
||||||
const setSelected = () => (selected = sort)
|
const setSelected = () => (selected = sort)
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
import { addAdmin } from '$lib/lemmy/user.js'
|
import { addAdmin } from '$lib/lemmy/user.js'
|
||||||
import { removeItem, trycatch } from '$lib/util.js'
|
import { removeItem, trycatch } from '$lib/util.js'
|
||||||
import { Button } from 'mono-svelte'
|
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
|
export let data
|
||||||
|
|
||||||
@@ -61,11 +61,9 @@
|
|||||||
{#each data.site?.admins ?? [] as admin}
|
{#each data.site?.admins ?? [] as admin}
|
||||||
<div class="py-3 flex items-center justify-between">
|
<div class="py-3 flex items-center justify-between">
|
||||||
<UserLink avatar showInstance={false} user={admin.person} />
|
<UserLink avatar showInstance={false} user={admin.person} />
|
||||||
<Button
|
<Button on:click={() => action(admin.person.id)} size="square-md">
|
||||||
on:click={() => action(admin.person.id)}
|
<Icon src={Trash} mini size="16" />
|
||||||
icon={Trash}
|
</Button>
|
||||||
size="square-md"
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
{/each}
|
{/each}
|
||||||
{/if}
|
{/if}
|
||||||
@@ -98,14 +96,8 @@
|
|||||||
class="flex-1"
|
class="flex-1"
|
||||||
pattern={'@[^ |]{1,}'}
|
pattern={'@[^ |]{1,}'}
|
||||||
/>
|
/>
|
||||||
<Button
|
<Button loading={adding} disabled={adding} size="md" class="h-full" submit>
|
||||||
loading={adding}
|
<Icon src={Plus} mini size="16" slot="prefix" />
|
||||||
disabled={adding}
|
|
||||||
icon={Plus}
|
|
||||||
size="md"
|
|
||||||
class="h-full"
|
|
||||||
submit
|
|
||||||
>
|
|
||||||
Add Admin
|
Add Admin
|
||||||
</Button>
|
</Button>
|
||||||
</form>
|
</form>
|
||||||
|
|||||||
@@ -119,11 +119,9 @@
|
|||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<Button
|
<Button size="square-md" on:click={() => action(moderator.moderator)}>
|
||||||
size="square-md"
|
<Icon src={Trash} mini size="16" />
|
||||||
on:click={() => action(moderator.moderator)}
|
</Button>
|
||||||
icon={Trash}
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
{/each}
|
{/each}
|
||||||
</EditableList>
|
</EditableList>
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
import { page } from '$app/stores'
|
import { page } from '$app/stores'
|
||||||
import {
|
import {
|
||||||
ChatBubbleOvalLeftEllipsis,
|
ChatBubbleOvalLeftEllipsis,
|
||||||
|
GlobeAmericas,
|
||||||
Icon,
|
Icon,
|
||||||
PencilSquare,
|
PencilSquare,
|
||||||
QuestionMarkCircle,
|
QuestionMarkCircle,
|
||||||
@@ -17,7 +18,8 @@
|
|||||||
import { addSubscription } from '$lib/lemmy/user.js'
|
import { addSubscription } from '$lib/lemmy/user.js'
|
||||||
import { LINKED_INSTANCE_URL } from '$lib/instance.js'
|
import { LINKED_INSTANCE_URL } from '$lib/instance.js'
|
||||||
import { profile } from '$lib/auth.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
|
export let data
|
||||||
|
|
||||||
@@ -39,13 +41,21 @@
|
|||||||
page, and search with this syntax:
|
page, and search with this syntax:
|
||||||
<code>!community@instance.com</code>
|
<code>!community@instance.com</code>
|
||||||
</p>
|
</p>
|
||||||
<div class="flex flex-col sm:flex-row gap-4 mt-4">
|
<div class="flex flex-row flex-wrap gap-4 mt-4">
|
||||||
<MultiSelect
|
<Select
|
||||||
options={['Subscribed', 'Local', 'All']}
|
class="w-48"
|
||||||
selected={$page.url.searchParams.get('type') ??
|
bind:value={data.type}
|
||||||
(LINKED_INSTANCE_URL ? 'Local' : 'All')}
|
on:change={() => searchParam($page.url, 'type', data.type ?? 'All', 'page')}
|
||||||
on:select={(e) => searchParam($page.url, 'type', e.detail, '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">
|
<div class="flex flex-col sm:flex-row gap-2 sm:ml-auto items-center">
|
||||||
<TextInput
|
<TextInput
|
||||||
bind:value={search}
|
bind:value={search}
|
||||||
|
|||||||
@@ -1,30 +1,42 @@
|
|||||||
import { profile } from '$lib/auth.js'
|
import { profile } from '$lib/auth.js'
|
||||||
|
import { LINKED_INSTANCE_URL } from '$lib/instance.js'
|
||||||
import { getClient } from '$lib/lemmy.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'
|
import { get } from 'svelte/store'
|
||||||
|
|
||||||
export async function load({ url, fetch }) {
|
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 page = Number(url.searchParams.get('page')) || 1
|
||||||
const query = url.searchParams.get('q')
|
const query = url.searchParams.get('q')
|
||||||
|
|
||||||
if (query) {
|
if (query) {
|
||||||
return await getClient(undefined, fetch).search({
|
return {
|
||||||
limit: 40,
|
...(await getClient(undefined, fetch).search({
|
||||||
page: page,
|
limit: 40,
|
||||||
sort: 'TopAll',
|
page: page,
|
||||||
type_: 'Communities',
|
sort: sort,
|
||||||
listing_type: type,
|
type_: 'Communities',
|
||||||
q: query,
|
listing_type: type,
|
||||||
auth: get(profile)?.jwt,
|
q: query,
|
||||||
})
|
auth: get(profile)?.jwt,
|
||||||
|
})),
|
||||||
|
type: type,
|
||||||
|
sort: sort,
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return await getClient(undefined, fetch).listCommunities({
|
return {
|
||||||
limit: 40,
|
...(await getClient(undefined, fetch).listCommunities({
|
||||||
page: page,
|
limit: 40,
|
||||||
sort: 'TopAll',
|
page: page,
|
||||||
type_: type,
|
sort: sort,
|
||||||
auth: get(profile)?.jwt,
|
type_: type,
|
||||||
})
|
auth: get(profile)?.jwt,
|
||||||
|
})),
|
||||||
|
type: type,
|
||||||
|
sort: sort,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -22,8 +22,8 @@
|
|||||||
PersonView,
|
PersonView,
|
||||||
PostView,
|
PostView,
|
||||||
} from 'lemmy-js-client'
|
} from 'lemmy-js-client'
|
||||||
import { Button } from 'mono-svelte'
|
import { Button, Select } from 'mono-svelte'
|
||||||
import { Icon, MagnifyingGlass } from 'svelte-hero-icons'
|
import { Bars3BottomRight, Icon, MagnifyingGlass } from 'svelte-hero-icons'
|
||||||
import { expoInOut, expoOut } from 'svelte/easing'
|
import { expoInOut, expoOut } from 'svelte/easing'
|
||||||
import { fly, slide } from 'svelte/transition'
|
import { fly, slide } from 'svelte/transition'
|
||||||
|
|
||||||
@@ -42,11 +42,21 @@
|
|||||||
|
|
||||||
<h1 class="font-bold text-2xl">Search</h1>
|
<h1 class="font-bold text-2xl">Search</h1>
|
||||||
<div class="flex flex-row flex-wrap sm:justify-between items-center gap-4 mt-4">
|
<div class="flex flex-row flex-wrap sm:justify-between items-center gap-4 mt-4">
|
||||||
<MultiSelect
|
<Select
|
||||||
options={['All', 'Posts', 'Comments', 'Communities', 'Users']}
|
class="w-48"
|
||||||
selected={$page.url.searchParams.get('type') ?? 'All'}
|
bind:value={data.type}
|
||||||
on:select={(e) => searchParam($page.url, 'type', e.detail, 'page')}
|
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">
|
<div class="flex flex-row gap-2 items-center">
|
||||||
<TextInput
|
<TextInput
|
||||||
bind:value={query}
|
bind:value={query}
|
||||||
|
|||||||
@@ -16,8 +16,8 @@ export async function load({ url, fetch }) {
|
|||||||
const query = url.searchParams.get('q')
|
const query = url.searchParams.get('q')
|
||||||
const page = Number(url.searchParams.get('page')) || 1
|
const page = Number(url.searchParams.get('page')) || 1
|
||||||
const community = url.searchParams.get('community_name')
|
const community = url.searchParams.get('community_name')
|
||||||
const sort = url.searchParams.get('sort')
|
const sort = url.searchParams.get('sort') || 'New'
|
||||||
const type = url.searchParams.get('type')
|
const type = url.searchParams.get('type') || 'All'
|
||||||
|
|
||||||
if (query) {
|
if (query) {
|
||||||
const results = await getClient(undefined, fetch).search({
|
const results = await getClient(undefined, fetch).search({
|
||||||
@@ -44,6 +44,8 @@ export async function load({ url, fetch }) {
|
|||||||
)
|
)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
type: type,
|
||||||
|
sort: sort,
|
||||||
page: page,
|
page: page,
|
||||||
results: everything,
|
results: everything,
|
||||||
streamed: {
|
streamed: {
|
||||||
|
|||||||
Reference in new issue
Block a user