From 9a1c615d7fa99c24d7ff43dbc6305cef734267fa Mon Sep 17 00:00:00 2001 From: Ricard Mallafre Date: Sun, 31 Mar 2024 14:46:53 +0200 Subject: [PATCH] fix(groups): limit amount of group activity elements --- src/app/groups/[groupId]/group-activity.tsx | 4 +++- src/app/groups/[groupId]/page.tsx | 6 +++--- src/server/api/routers/groups/expenses.ts | 6 +++--- src/server/api/routers/groups/settlements.ts | 6 +++--- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/app/groups/[groupId]/group-activity.tsx b/src/app/groups/[groupId]/group-activity.tsx index b01db64..3f77f58 100644 --- a/src/app/groups/[groupId]/group-activity.tsx +++ b/src/app/groups/[groupId]/group-activity.tsx @@ -13,11 +13,13 @@ export default function RecentGroupActivity({ settlements, user, group, + amountToShow, }: { user: RouterOutputs['users']['get']; expenses: RouterOutputs['groups']['expenses']['recent']; settlements: RouterOutputs['groups']['settlements']['recent']; group: Exclude; + amountToShow: number; }) { const settlementListItems = settlements.map((s) => ({ date: s.date, @@ -34,7 +36,7 @@ export default function RecentGroupActivity({ return ( Recent activity - {allItems.slice(0, 5).map((item) => item.component)} + {allItems.slice(0, amountToShow).map((item) => item.component)} ); } diff --git a/src/app/groups/[groupId]/page.tsx b/src/app/groups/[groupId]/page.tsx index fe56e37..dac12c5 100644 --- a/src/app/groups/[groupId]/page.tsx +++ b/src/app/groups/[groupId]/page.tsx @@ -16,8 +16,8 @@ export default async function GroupPage({ params: { groupId } }: { params: { gro if (!user) return notFound(); const balance = await api.groups.balance.query({ groupId }); - const expenses = await api.groups.expenses.recent.query({ groupId }); - const settlements = await api.groups.settlements.recent.query({ groupId }); + const expenses = await api.groups.expenses.recent.query({ groupId, take: Math.max(5, balance.length) }); + const settlements = await api.groups.settlements.recent.query({ groupId, take: Math.max(5, balance.length) }); return ( <> @@ -44,7 +44,7 @@ export default async function GroupPage({ params: { groupId } }: { params: { gro
- +
diff --git a/src/server/api/routers/groups/expenses.ts b/src/server/api/routers/groups/expenses.ts index fb1665b..e8acd94 100644 --- a/src/server/api/routers/groups/expenses.ts +++ b/src/server/api/routers/groups/expenses.ts @@ -148,8 +148,8 @@ export const groupExpensesRouter = createTRPCRouter({ }), recent: privateProcedure - .input(z.object({ groupId: z.string().cuid() })) - .query(async ({ ctx: { db, user }, input: { groupId } }) => { + .input(z.object({ groupId: z.string().cuid(), take: z.number().default(5) })) + .query(async ({ ctx: { db, user }, input: { groupId, take } }) => { await assertUserInGroup({ groupId, userId: user.id }); return db.sharedTransaction.findMany({ @@ -177,7 +177,7 @@ export const groupExpensesRouter = createTRPCRouter({ date: 'desc', }, }, - take: 5, + take, }); }), }); diff --git a/src/server/api/routers/groups/settlements.ts b/src/server/api/routers/groups/settlements.ts index b6d42b2..e553703 100644 --- a/src/server/api/routers/groups/settlements.ts +++ b/src/server/api/routers/groups/settlements.ts @@ -97,8 +97,8 @@ export const groupSettlementsRouter = createTRPCRouter({ }), recent: privateProcedure - .input(z.object({ groupId: z.string().cuid() })) - .query(async ({ ctx: { db, user }, input: { groupId } }) => { + .input(z.object({ groupId: z.string().cuid(), take: z.number().default(5) })) + .query(async ({ ctx: { db, user }, input: { groupId, take } }) => { await assertUserInGroup({ groupId, userId: user.id }); return db.settlement.findMany({ @@ -128,7 +128,7 @@ export const groupSettlementsRouter = createTRPCRouter({ orderBy: { date: 'desc', }, - take: 5, + take, }); }), });