fix: add pageination to user profiles

This commit is contained in:
Xyphyn committed 2023-07-27 11:52:09 -07:00
1 parent ef0cb48710
commit 8e75e05585
3 files changed
+61 -46

No files matched your search

+29 -8
View File
@@ -1,14 +1,35 @@
import { isComment } from '$lib/components/lemmy/post/helpers.js'
import { authData, getClient } from '$lib/lemmy.js'
import type { CommentView, PostView } from 'lemmy-js-client'
import { get } from 'svelte/store'
export async function load({ params }) {
function getDateOfItem(item: CommentView | PostView): number {
if (isComment(item)) {
return Date.parse(item.comment.published)
} else {
return Date.parse(item.post.published)
}
}
export async function load({ params, url }) {
const page = Number(url.searchParams.get('page')) || 1
const type: 'comments' | 'posts' | 'all' =
(url.searchParams.get('type') as 'comments' | 'posts' | 'all') || 'all'
const user = await getClient().getPersonDetails({
limit: 20,
page: page,
username: params.name,
sort: 'New',
auth: get(authData)?.token,
})
return {
user: await getClient().getPersonDetails({
limit: 40,
page: 1,
username: params.name,
sort: 'New',
auth: get(authData)?.token,
}),
type: type,
page: page,
person_view: user.person_view,
items: [...user.posts, ...user.comments].sort(
(a, b) => getDateOfItem(b) - getDateOfItem(a)
),
}
}