Pagination + Optimistic updates
Basically I am building a chat in my applicatin so team members can talk to each other.
1) In the code below you can see my convex function to return members form a project which should go to the chat members list. But I have to populate the user data field so thats why I have the promise all, when I try to implement it with pagination using the documentation in the convex web I get an error as I can't iterate a PaginatedREsult (I belive its call like that), and if I access the data then the paginated query throws an error:
export const getMembers = query({
args: {
projectId: v.id('projects'),
},
handler: async (ctx, args) => {
const access = await accessToProject(
ctx,
args.projectId,
'juanillaberia2002@gmail.com'
);
if (!access) return [];
const projectMembers = await ctx.db
.query('project_members')
.withIndex('by_projectId', q => q.eq('projectId', args.projectId))
.collect();
// const projectMembers = await ctx.db
// .query('project_members')
// .withIndex('by_projectId', q => q.eq('projectId', args.projectId))
// .paginate(args.paginationOpts);
return await Promise.all(
projectMembers.map(async member => {
const userData = await ctx.db.get(member.userId);
return {
...userData,
role: member.role,
};
})
);
},
});
2) And second, is it possible to implement optimistic updates and also paginate messages? I successfully implemented the optimistic updates, but I am not quite sure how to add the pagination (because of the question 1 and also if they go well together or their are meant to be separated features) as messages contain the userId who sent it and I need to query for the image and the name.
Thank you so much for your time!
