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 { 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 { 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) {
|
function getSavedItemPublished(item: PostView | CommentView) {
|
||||||
if ('comment' in item) {
|
if ('comment' in item) {
|
||||||
@@ -14,29 +14,26 @@ function getSavedItemPublished(item: PostView | CommentView) {
|
|||||||
export async function load({ url, fetch }) {
|
export async function load({ url, fetch }) {
|
||||||
if (!profile.current.jwt) throw error(401)
|
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 page = Number(url.searchParams.get('page')) || 1
|
||||||
const type: 'comments' | 'posts' | 'all' =
|
const type: 'comments' | 'posts' | 'all' =
|
||||||
(url.searchParams.get('type') as 'comments' | 'posts' | 'all') || 'all'
|
(url.searchParams.get('type') as 'comments' | 'posts' | 'all') || 'all'
|
||||||
|
|
||||||
const client = getClient(undefined, fetch)
|
const { posts, comments } = await client({ func: fetch }).getPersonDetails({
|
||||||
|
|
||||||
const params = {
|
|
||||||
saved_only: true,
|
saved_only: true,
|
||||||
limit: 20,
|
limit: 20,
|
||||||
page: page,
|
page: 1,
|
||||||
// sort: 'New' as SortType & CommentSortType,
|
person_id: user?.local_user_view.person.id,
|
||||||
type_: 'All' as ListingType,
|
})
|
||||||
}
|
|
||||||
|
|
||||||
const [posts, comments] = await Promise.all([
|
const everything = [
|
||||||
type == 'posts' || type == 'all' ? client.getPosts(params) : { posts: [] },
|
...(type == 'posts' || type == 'all' ? posts : []),
|
||||||
|
...(type == 'comments' || type == 'all' ? comments : []),
|
||||||
type == 'comments' || type == 'all'
|
].sort(
|
||||||
? client.getComments(params)
|
|
||||||
: { comments: [] },
|
|
||||||
])
|
|
||||||
|
|
||||||
const everything = [...posts.posts, ...comments.comments].sort(
|
|
||||||
(a, b) =>
|
(a, b) =>
|
||||||
Date.parse(getSavedItemPublished(b)) -
|
Date.parse(getSavedItemPublished(b)) -
|
||||||
Date.parse(getSavedItemPublished(a)),
|
Date.parse(getSavedItemPublished(a)),
|
||||||
|
|||||||
Reference in new issue
Block a user