diff --git a/src/routes/saved/+page.ts b/src/routes/saved/+page.ts index 6e4660b4..f885d314 100644 --- a/src/routes/saved/+page.ts +++ b/src/routes/saved/+page.ts @@ -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)),