From cf360d032103b2a8f692813a1891b3c67bb0bdae Mon Sep 17 00:00:00 2001 From: Xylight Date: Fri, 3 Apr 2026 14:34:34 -0700 Subject: [PATCH] fix: piefed pageination starting at 0 --- src/lib/api/base.ts | 1 + src/lib/api/piefed/adapter.ts | 2 +- src/lib/api/piefed/rewrite.ts | 2 +- src/lib/feature/comment/CommentTree.svelte | 22 +++++++++---------- src/lib/feature/comment/comments.svelte.ts | 9 +++++--- .../post/[instance]/[id=integer]/+page.ts | 5 ++++- 6 files changed, 24 insertions(+), 17 deletions(-) diff --git a/src/lib/api/base.ts b/src/lib/api/base.ts index 38b64efd..81035683 100644 --- a/src/lib/api/base.ts +++ b/src/lib/api/base.ts @@ -271,6 +271,7 @@ export abstract class BaseClient { abstract listMedia(form: types.ListMedia): Promise abstract voteOnPoll?(form: types.PollVote): Promise abstract setNote?(form: types.SetNote): Promise + abstract getPostReplies(form: types.GetPostReplies) } export type NullableFnArg = T extends ( diff --git a/src/lib/api/piefed/adapter.ts b/src/lib/api/piefed/adapter.ts index f47c3f99..56900496 100644 --- a/src/lib/api/piefed/adapter.ts +++ b/src/lib/api/piefed/adapter.ts @@ -202,7 +202,7 @@ const methods: MethodDefinitions = { transform: (r: piefed['ListPostsResponse'], p) => ({ ...r, posts: r.posts.map(toPostView), - next_page: String(Number(p.page_cursor ?? 1) + 1), + next_page: (Number(p.page_cursor || 1) + 1).toString(), }), }, diff --git a/src/lib/api/piefed/rewrite.ts b/src/lib/api/piefed/rewrite.ts index d1eda11e..2001218f 100644 --- a/src/lib/api/piefed/rewrite.ts +++ b/src/lib/api/piefed/rewrite.ts @@ -213,7 +213,7 @@ export function fromGetPosts( return { ...getPosts, sort: toSortType(getPosts.sort), - page: Number(getPosts.page_cursor), + page: Number(getPosts.page_cursor || 1), } } diff --git a/src/lib/feature/comment/CommentTree.svelte b/src/lib/feature/comment/CommentTree.svelte index 20be3a65..1420d73c 100644 --- a/src/lib/feature/comment/CommentTree.svelte +++ b/src/lib/feature/comment/CommentTree.svelte @@ -19,22 +19,16 @@ let { nodes = $bindable(), post }: Props = $props() async function fetchChildren(parent: CommentNodeI) { - if ( - !( - parent.comment_view.counts.child_count > 0 && - parent.children.length == 0 - ) - ) { - return - } - try { parent.loading = true + parent.page ??= 1 const newComments = await client().getComments({ - max_depth: 5, + max_depth: 3, parent_id: parent.comment_view.comment.id, type_: 'All', + limit: 1000000, + page: parent.page++, }) if (newComments.comments.length == 0) { @@ -45,6 +39,12 @@ return } + if ( + newComments.comments.length >= parent.comment_view.counts.child_count + ) { + parent.hasMore = false + } + parent.children = buildCommentsTree( newComments.comments, parent.depth, @@ -97,7 +97,7 @@ shadow="none" loaderWidth={16} onclick={() => { - if (nodes[index].depth > 4) { + if (nodes[index].depth > 6) { goto(`/comment/${nodes[index].comment_view.comment.id}#comments`) } else { nodes[index].loading = true diff --git a/src/lib/feature/comment/comments.svelte.ts b/src/lib/feature/comment/comments.svelte.ts index e321fe67..9a1b2a03 100644 --- a/src/lib/feature/comment/comments.svelte.ts +++ b/src/lib/feature/comment/comments.svelte.ts @@ -1,6 +1,6 @@ -import type { Comment, CommentView } from "$lib/api/types" -import { t } from "$lib/app/i18n" -import { SvelteMap } from "svelte/reactivity" +import type { Comment, CommentView } from '$lib/api/types' +import { t } from '$lib/app/i18n' +import { SvelteMap } from 'svelte/reactivity' export interface CommentNodeI { comment_view: CommentView @@ -8,6 +8,8 @@ export interface CommentNodeI { depth: number loading?: boolean expanded?: boolean + hasMore?: boolean + page?: number } function getCommentParentId(comment?: Comment): number | undefined { @@ -44,6 +46,7 @@ export function buildCommentsTree( children: [], depth: depth, expanded: true, + hasMore: false, } min_depth = Math.min(min_depth, depth) if (filter(comment_view)) { diff --git a/src/routes/post/[instance]/[id=integer]/+page.ts b/src/routes/post/[instance]/[id=integer]/+page.ts index 719b7f79..e688a541 100644 --- a/src/routes/post/[instance]/[id=integer]/+page.ts +++ b/src/routes/post/[instance]/[id=integer]/+page.ts @@ -1,6 +1,7 @@ import { goto } from '$app/navigation' import { resolve } from '$app/paths' import { client } from '$lib/api/client.svelte' +import { PiefedClient } from '$lib/api/piefed/adapter.js' import { profile } from '$lib/app/auth' import { settings } from '$lib/app/settings.svelte' import { ReactiveState } from '$lib/app/util.svelte' @@ -97,10 +98,12 @@ export async function load({ params, url, route }) { comments: { post_id: Number(params.id), type_: 'All', - max_depth: max_depth, + max_depth: + profile.client instanceof PiefedClient ? max_depth - 1 : max_depth, saved_only: false, sort: sort, parent_id: parentId, + limit: 10000000000, }, posts: { id: Number(params.id) }, preload: cachedPost,