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 listMedia(form: types.ListMedia): Promise<types.ListMediaResponse>
|
||||||
abstract voteOnPoll?(form: types.PollVote): Promise<types.PostView>
|
abstract voteOnPoll?(form: types.PollVote): Promise<types.PostView>
|
||||||
abstract setNote?(form: types.SetNote): Promise<types.PersonView>
|
abstract setNote?(form: types.SetNote): Promise<types.PersonView>
|
||||||
|
abstract getPostReplies(form: types.GetPostReplies)
|
||||||
}
|
}
|
||||||
|
|
||||||
export type NullableFnArg<T, Fallback = never> = T extends (
|
export type NullableFnArg<T, Fallback = never> = T extends (
|
||||||
|
|||||||
@@ -202,7 +202,7 @@ const methods: MethodDefinitions = {
|
|||||||
transform: (r: piefed['ListPostsResponse'], p) => ({
|
transform: (r: piefed['ListPostsResponse'], p) => ({
|
||||||
...r,
|
...r,
|
||||||
posts: r.posts.map(toPostView),
|
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 {
|
return {
|
||||||
...getPosts,
|
...getPosts,
|
||||||
sort: toSortType(getPosts.sort),
|
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()
|
let { nodes = $bindable(), post }: Props = $props()
|
||||||
|
|
||||||
async function fetchChildren(parent: CommentNodeI) {
|
async function fetchChildren(parent: CommentNodeI) {
|
||||||
if (
|
|
||||||
!(
|
|
||||||
parent.comment_view.counts.child_count > 0 &&
|
|
||||||
parent.children.length == 0
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
parent.loading = true
|
parent.loading = true
|
||||||
|
parent.page ??= 1
|
||||||
|
|
||||||
const newComments = await client().getComments({
|
const newComments = await client().getComments({
|
||||||
max_depth: 5,
|
max_depth: 3,
|
||||||
parent_id: parent.comment_view.comment.id,
|
parent_id: parent.comment_view.comment.id,
|
||||||
type_: 'All',
|
type_: 'All',
|
||||||
|
limit: 1000000,
|
||||||
|
page: parent.page++,
|
||||||
})
|
})
|
||||||
|
|
||||||
if (newComments.comments.length == 0) {
|
if (newComments.comments.length == 0) {
|
||||||
@@ -45,6 +39,12 @@
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
newComments.comments.length >= parent.comment_view.counts.child_count
|
||||||
|
) {
|
||||||
|
parent.hasMore = false
|
||||||
|
}
|
||||||
|
|
||||||
parent.children = buildCommentsTree(
|
parent.children = buildCommentsTree(
|
||||||
newComments.comments,
|
newComments.comments,
|
||||||
parent.depth,
|
parent.depth,
|
||||||
@@ -97,7 +97,7 @@
|
|||||||
shadow="none"
|
shadow="none"
|
||||||
loaderWidth={16}
|
loaderWidth={16}
|
||||||
onclick={() => {
|
onclick={() => {
|
||||||
if (nodes[index].depth > 4) {
|
if (nodes[index].depth > 6) {
|
||||||
goto(`/comment/${nodes[index].comment_view.comment.id}#comments`)
|
goto(`/comment/${nodes[index].comment_view.comment.id}#comments`)
|
||||||
} else {
|
} else {
|
||||||
nodes[index].loading = true
|
nodes[index].loading = true
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import type { Comment, CommentView } from "$lib/api/types"
|
import type { Comment, CommentView } from '$lib/api/types'
|
||||||
import { t } from "$lib/app/i18n"
|
import { t } from '$lib/app/i18n'
|
||||||
import { SvelteMap } from "svelte/reactivity"
|
import { SvelteMap } from 'svelte/reactivity'
|
||||||
|
|
||||||
export interface CommentNodeI {
|
export interface CommentNodeI {
|
||||||
comment_view: CommentView
|
comment_view: CommentView
|
||||||
@@ -8,6 +8,8 @@ export interface CommentNodeI {
|
|||||||
depth: number
|
depth: number
|
||||||
loading?: boolean
|
loading?: boolean
|
||||||
expanded?: boolean
|
expanded?: boolean
|
||||||
|
hasMore?: boolean
|
||||||
|
page?: number
|
||||||
}
|
}
|
||||||
|
|
||||||
function getCommentParentId(comment?: Comment): number | undefined {
|
function getCommentParentId(comment?: Comment): number | undefined {
|
||||||
@@ -44,6 +46,7 @@ export function buildCommentsTree(
|
|||||||
children: [],
|
children: [],
|
||||||
depth: depth,
|
depth: depth,
|
||||||
expanded: true,
|
expanded: true,
|
||||||
|
hasMore: false,
|
||||||
}
|
}
|
||||||
min_depth = Math.min(min_depth, depth)
|
min_depth = Math.min(min_depth, depth)
|
||||||
if (filter(comment_view)) {
|
if (filter(comment_view)) {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { goto } from '$app/navigation'
|
import { goto } from '$app/navigation'
|
||||||
import { resolve } from '$app/paths'
|
import { resolve } from '$app/paths'
|
||||||
import { client } from '$lib/api/client.svelte'
|
import { client } from '$lib/api/client.svelte'
|
||||||
|
import { PiefedClient } from '$lib/api/piefed/adapter.js'
|
||||||
import { profile } from '$lib/app/auth'
|
import { profile } from '$lib/app/auth'
|
||||||
import { settings } from '$lib/app/settings.svelte'
|
import { settings } from '$lib/app/settings.svelte'
|
||||||
import { ReactiveState } from '$lib/app/util.svelte'
|
import { ReactiveState } from '$lib/app/util.svelte'
|
||||||
@@ -97,10 +98,12 @@ export async function load({ params, url, route }) {
|
|||||||
comments: {
|
comments: {
|
||||||
post_id: Number(params.id),
|
post_id: Number(params.id),
|
||||||
type_: 'All',
|
type_: 'All',
|
||||||
max_depth: max_depth,
|
max_depth:
|
||||||
|
profile.client instanceof PiefedClient ? max_depth - 1 : max_depth,
|
||||||
saved_only: false,
|
saved_only: false,
|
||||||
sort: sort,
|
sort: sort,
|
||||||
parent_id: parentId,
|
parent_id: parentId,
|
||||||
|
limit: 10000000000,
|
||||||
},
|
},
|
||||||
posts: { id: Number(params.id) },
|
posts: { id: Number(params.id) },
|
||||||
preload: cachedPost,
|
preload: cachedPost,
|
||||||
|
|||||||
Reference in new issue
Block a user