fix: use /user endpoint for getting saved posts
This commit is contained in:
1 file changed
+15
-18
+15
-18
@@ -1,7 +1,7 @@
|
||||
import { profile } from '$lib/auth.svelte'
|
||||
import { getClient } from '$lib/lemmy.svelte.js'
|
||||
import { client } from '$lib/lemmy.svelte.js'
|
||||
import { error } from '@sveltejs/kit'
|
||||
import type { CommentView, ListingType, PostView } from 'lemmy-js-client'
|
||||
import type { CommentView, PostView } from 'lemmy-js-client'
|
||||
|
||||
function getSavedItemPublished(item: PostView | CommentView) {
|
||||
if ('comment' in item) {
|
||||
@@ -14,29 +14,26 @@ function getSavedItemPublished(item: PostView | CommentView) {
|
||||
export async function load({ url, fetch }) {
|
||||
if (!profile.current.jwt) throw error(401)
|
||||
|
||||
const user =
|
||||
profile.current.user ?? (await client({ func: fetch }).getSite()).my_user
|
||||
|
||||
if (!user) throw error(401)
|
||||
|
||||
const page = Number(url.searchParams.get('page')) || 1
|
||||
const type: 'comments' | 'posts' | 'all' =
|
||||
(url.searchParams.get('type') as 'comments' | 'posts' | 'all') || 'all'
|
||||
|
||||
const client = getClient(undefined, fetch)
|
||||
|
||||
const params = {
|
||||
const { posts, comments } = await client({ func: fetch }).getPersonDetails({
|
||||
saved_only: true,
|
||||
limit: 20,
|
||||
page: page,
|
||||
// sort: 'New' as SortType & CommentSortType,
|
||||
type_: 'All' as ListingType,
|
||||
}
|
||||
page: 1,
|
||||
person_id: user?.local_user_view.person.id,
|
||||
})
|
||||
|
||||
const [posts, comments] = await Promise.all([
|
||||
type == 'posts' || type == 'all' ? client.getPosts(params) : { posts: [] },
|
||||
|
||||
type == 'comments' || type == 'all'
|
||||
? client.getComments(params)
|
||||
: { comments: [] },
|
||||
])
|
||||
|
||||
const everything = [...posts.posts, ...comments.comments].sort(
|
||||
const everything = [
|
||||
...(type == 'posts' || type == 'all' ? posts : []),
|
||||
...(type == 'comments' || type == 'all' ? comments : []),
|
||||
].sort(
|
||||
(a, b) =>
|
||||
Date.parse(getSavedItemPublished(b)) -
|
||||
Date.parse(getSavedItemPublished(a)),
|
||||
|
||||
Reference in new issue
Block a user