feat: Implement infinite scrolling for posts and replies on the main feed and user profile pages using cursor-based pagination.

This commit is contained in:
Christomatt
2026-01-26 14:34:45 +01:00
parent a2ec470354
commit 74ec163625
4 changed files with 249 additions and 50 deletions
+21 -2
View File
@@ -146,6 +146,7 @@ export async function GET(request: Request, context: RouteContext) {
const cleanHandle = handle.toLowerCase().replace(/^@/, '');
const { searchParams } = new URL(request.url);
const limit = Math.min(parseInt(searchParams.get('limit') || '25'), 50);
const cursor = searchParams.get('cursor');
const remote = parseRemoteHandle(handle);
@@ -374,9 +375,27 @@ export async function GET(request: Request, context: RouteContext) {
return NextResponse.json({ error: 'User not found' }, { status: 404 });
}
// Get user's posts
// Get user's posts with cursor-based pagination
const { lt } = await import('drizzle-orm');
let whereConditions = and(eq(posts.userId, user.id), eq(posts.isRemoved, false));
// If cursor provided, get posts older than the cursor
if (cursor) {
const cursorPost = await db.query.posts.findFirst({
where: eq(posts.id, cursor),
});
if (cursorPost) {
whereConditions = and(
eq(posts.userId, user.id),
eq(posts.isRemoved, false),
lt(posts.createdAt, cursorPost.createdAt)
);
}
}
let userPosts: any[] = await db.query.posts.findMany({
where: and(eq(posts.userId, user.id), eq(posts.isRemoved, false)),
where: whereConditions,
with: {
author: true,
media: true,