feat: display user's posts on profile page

This commit is contained in:
Stevan Freeborn
2023-09-11 00:40:14 -05:00
parent 8b350c9809
commit 4b74f47e75
18 changed files with 397 additions and 67 deletions
+38
View File
@@ -0,0 +1,38 @@
'use client';
import { usePaginatedQuery } from 'convex/react';
import { api } from '../../convex/_generated/api';
import { Doc } from '../../convex/_generated/dataModel';
import Post from './Post';
export default function UserPosts({ user }: { user: Doc<'users'> }) {
const PAGE_SIZE = 10;
const pager = usePaginatedQuery(
api.posts.getUsersPostById,
{
userId: user._id,
},
{ initialNumItems: 10 }
);
return (
<div className='flex flex-col w-full h-full'>
{pager.results.map(post => (
<Post
key={post._id}
post={post}
/>
))}
{pager.isLoading ? (
<div>Loading...</div>
) : (
<button
onClick={() => pager.loadMore(10)}
disabled={pager.status !== 'CanLoadMore'}
>
Load More
</button>
)}
</div>
);
}