mirror of
https://github.com/lukevella/rallly.git
synced 2025-06-03 19:21:51 +02:00
⚡️ Use infinite query on polls page (#1200)
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
This commit is contained in:
parent
e985a5db9f
commit
43c450aa91
4 changed files with 182 additions and 66 deletions
|
@ -93,6 +93,58 @@ export const polls = router({
|
|||
},
|
||||
});
|
||||
}),
|
||||
infiniteList: possiblyPublicProcedure
|
||||
.input(
|
||||
z.object({
|
||||
status: z.enum(["all", "live", "paused", "finalized"]),
|
||||
cursor: z.string().optional(),
|
||||
limit: z.number(),
|
||||
}),
|
||||
)
|
||||
.query(async ({ ctx, input }) => {
|
||||
const { cursor, limit, status } = input;
|
||||
const polls = await prisma.poll.findMany({
|
||||
where: {
|
||||
userId: ctx.user.id,
|
||||
status: status === "all" ? undefined : status,
|
||||
},
|
||||
orderBy: [
|
||||
{
|
||||
createdAt: "desc",
|
||||
},
|
||||
{
|
||||
title: "asc",
|
||||
},
|
||||
],
|
||||
cursor: cursor ? { id: cursor } : undefined,
|
||||
take: limit + 1,
|
||||
select: {
|
||||
id: true,
|
||||
title: true,
|
||||
location: true,
|
||||
timeZone: true,
|
||||
createdAt: true,
|
||||
status: true,
|
||||
userId: true,
|
||||
participants: {
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
let nextCursor: typeof cursor | undefined = undefined;
|
||||
if (polls.length > input.limit) {
|
||||
const nextItem = polls.pop();
|
||||
nextCursor = nextItem!.id;
|
||||
}
|
||||
return {
|
||||
polls,
|
||||
nextCursor,
|
||||
};
|
||||
}),
|
||||
|
||||
// START LEGACY ROUTES
|
||||
create: possiblyPublicProcedure
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue