feat: add cursor pagination to community pages
This commit is contained in:
1 parent
0239d6cef9
commit
ddd560c463
3 files changed
+8
-4
No files matched your search
@@ -5,7 +5,8 @@ import type { ListingType, SortType } from 'lemmy-js-client'
|
||||
import { get } from 'svelte/store'
|
||||
|
||||
export async function load(req: any) {
|
||||
const page = Number(req.url.searchParams.get('page') || 1) || 1
|
||||
const cursor: string | undefined = req.url.searchParams.get('cursor')
|
||||
const page = Number(req.url.searchParams.get('page')) || undefined
|
||||
|
||||
const sort: SortType =
|
||||
(req.url.searchParams.get('sort') as SortType) ||
|
||||
@@ -13,12 +14,13 @@ export async function load(req: any) {
|
||||
|
||||
return {
|
||||
sort: sort,
|
||||
page: page,
|
||||
page: page || 1,
|
||||
posts: getClient(undefined, req.fetch).getPosts({
|
||||
limit: 40,
|
||||
community_name: req.params.name,
|
||||
page: page,
|
||||
sort: sort,
|
||||
page_cursor: cursor
|
||||
}),
|
||||
community: getClient(undefined, req.fetch).getCommunity({
|
||||
name: req.params.name,
|
||||
|
||||
@@ -89,6 +89,8 @@
|
||||
|
||||
<Pageination
|
||||
page={data.page}
|
||||
next_cursor={data.posts.next_page}
|
||||
on:cursor={(c) => searchParam($page.url, 'cursor', c.detail)}
|
||||
on:change={(p) => searchParam($page.url, 'page', p.detail.toString())}
|
||||
>
|
||||
{#if data.posts.posts.length > 0}
|
||||
|
||||
Reference in new issue
Block a user