fix: piefed pageination starting at 0
This commit is contained in:
6 files changed
+24
-17
No files matched your search
@@ -271,6 +271,7 @@ export abstract class BaseClient {
|
||||
abstract listMedia(form: types.ListMedia): Promise<types.ListMediaResponse>
|
||||
abstract voteOnPoll?(form: types.PollVote): Promise<types.PostView>
|
||||
abstract setNote?(form: types.SetNote): Promise<types.PersonView>
|
||||
abstract getPostReplies(form: types.GetPostReplies)
|
||||
}
|
||||
|
||||
export type NullableFnArg<T, Fallback = never> = T extends (
|
||||
|
||||
@@ -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(),
|
||||
}),
|
||||
},
|
||||
|
||||
|
||||
@@ -213,7 +213,7 @@ export function fromGetPosts(
|
||||
return {
|
||||
...getPosts,
|
||||
sort: toSortType(getPosts.sort),
|
||||
page: Number(getPosts.page_cursor),
|
||||
page: Number(getPosts.page_cursor || 1),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)) {
|
||||
|
||||
Reference in new issue
Block a user