feat: add sorting to search page

This commit is contained in:
Xylight committed 2024-03-09 11:23:25 -08:00
1 parent cb21ab02c5
commit 609c8c1b73
3 files changed
+25 -24

No files matched your search

+6 -5
View File
@@ -53,7 +53,7 @@
</Material>
</Popover>
</h1>
<div class="flex flex-row flex-wrap gap-4 mt-4">
<div class="flex flex-row flex-wrap gap-4 mt-4 items-center">
<Select
bind:value={data.type}
on:change={() => searchParam($page.url, 'type', data.type ?? 'All', 'page')}
@@ -75,14 +75,15 @@
bind:value={search}
placeholder="Search for a community..."
label="Query"
size="sm"
size="md"
/>
<Button
submit
color="ghost"
size="square-md"
color="secondary"
size="custom"
class="self-end"
aria-label="Search"
style="width: 38px; height: 38px;"
title="Search"
>
<Icon src={MagnifyingGlass} size="16" mini />
</Button>
+17 -14
View File
@@ -2,6 +2,7 @@
import { page } from '$app/stores'
import { profile } from '$lib/auth.js'
import ObjectAutocomplete from '$lib/components/lemmy/ObjectAutocomplete.svelte'
import Sort from '$lib/components/lemmy/Sort.svelte'
import CommentItem from '$lib/components/lemmy/comment/CommentItem.svelte'
import CommunityItem from '$lib/components/lemmy/community/CommunityItem.svelte'
import Post from '$lib/components/lemmy/post/Post.svelte'
@@ -56,7 +57,7 @@
>
<span slot="label" class="flex items-center gap-1">
<Icon src={AdjustmentsHorizontal} mini size="15" />
Type
Filter
</span>
<option value="All">All</option>
<option value="Posts">Posts</option>
@@ -64,25 +65,27 @@
<option value="Communities">Communities</option>
<option value="Users">Users</option>
</Select>
<Sort navigate bind:selected={data.sort} />
<form
class="flex flex-row gap-2 items-center ml-auto"
on:submit|preventDefault={() => searchParam($page.url, 'q', query, 'page')}
class="flex flex-col sm:flex-row gap-2 sm:ml-auto items-center"
>
<TextInput
label="Query"
bind:value={query}
placeholder="!community@instance.com"
inlineAffixes
placeholder="Search for a keyword..."
label="Query"
size="md"
/>
<Button
submit
color="secondary"
size="custom"
class="self-end"
style="width: 38px; height: 38px;"
title="Search"
>
<button
type="submit"
aria-label="Search"
slot="suffix"
class="flex items-center"
>
<Icon src={MagnifyingGlass} size="20" mini />
</button>
</TextInput>
<Icon src={MagnifyingGlass} size="16" mini />
</Button>
</form>
<Button
slot="summary"
+2 -5
View File
@@ -25,7 +25,7 @@ export async function load({ url, fetch }) {
community_id: community ?? undefined,
limit: 20,
page: page,
sort: (sort as SortType) || 'New',
sort: (sort as SortType) || 'TopAll',
listing_type: 'All',
type_: (type as SearchType) ?? 'All',
})
@@ -37,10 +37,7 @@ export async function load({ url, fetch }) {
results.communities,
]
const everything = [...posts, ...comments, ...users, ...communities].sort(
(a, b) =>
Date.parse(getItemPublished(b)) - Date.parse(getItemPublished(a))
)
const everything = [...posts, ...comments, ...users, ...communities]
return {
type: type,