feat: add sorts to user pages

This commit is contained in:
Xyphyn committed 2023-07-27 12:25:26 -07:00
1 parent d427d4b2fc
commit c0aaf08a9f
12 files changed
+129 -69

No files matched your search

+2 -22
View File
@@ -1,4 +1,5 @@
import { authData, getClient } from '$lib/lemmy.js'
import { getItemPublished } from '$lib/lemmy/item.js'
import type {
CommentView,
CommunityView,
@@ -10,26 +11,6 @@ import type {
} from 'lemmy-js-client'
import { get } from 'svelte/store'
function getSearchItemPublished(
item: PostView | CommentView | PersonView | CommunityView
) {
if ('comment' in item) {
return item.comment.published
} else if ('post' in item) {
return item.post.published
}
if ('person' in item) {
return item.person.published
}
if ('community' in item) {
return item.community.published
}
return ''
}
export async function load({ url }) {
const query = url.searchParams.get('q')
const page = Number(url.searchParams.get('page')) || 1
@@ -58,8 +39,7 @@ export async function load({ url }) {
const everything = [...posts, ...comments, ...users, ...communities].sort(
(a, b) =>
Date.parse(getSearchItemPublished(b)) -
Date.parse(getSearchItemPublished(a))
Date.parse(getItemPublished(b)) - Date.parse(getItemPublished(a))
)
return {