feat: add cursor pagination
This commit is contained in:
1 parent
24c0c248f3
commit
0239d6cef9
5 files changed
+26
-10
No files matched your search
+12
-6
@@ -4,8 +4,10 @@ import type { ListingType, SortType } from 'lemmy-js-client'
|
||||
import { get } from 'svelte/store'
|
||||
import { error } from '@sveltejs/kit'
|
||||
import { profile } from '$lib/auth.js'
|
||||
import { feature } from '$lib/version.js'
|
||||
|
||||
export async function load({ url, fetch }) {
|
||||
const cursor = url.searchParams.get('cursor') as string | undefined
|
||||
const page = Number(url.searchParams.get('page') || 1) || 1
|
||||
|
||||
const sort: SortType =
|
||||
@@ -15,17 +17,21 @@ export async function load({ url, fetch }) {
|
||||
(url.searchParams.get('type') as ListingType) ||
|
||||
get(userSettings).defaultSort.feed
|
||||
|
||||
const posts = await getClient(undefined, fetch).getPosts({
|
||||
limit: 20,
|
||||
page: page,
|
||||
sort: sort,
|
||||
type_: listingType,
|
||||
page_cursor: cursor
|
||||
})
|
||||
|
||||
try {
|
||||
return {
|
||||
sort: sort,
|
||||
listingType: listingType,
|
||||
page: page,
|
||||
posts: await getClient(undefined, fetch).getPosts({
|
||||
limit: 20,
|
||||
page: page,
|
||||
sort: sort,
|
||||
type_: listingType,
|
||||
}),
|
||||
posts: posts,
|
||||
next_page: posts.next_page
|
||||
}
|
||||
} catch (err) {
|
||||
throw error(500, {
|
||||
|
||||
Reference in new issue
Block a user