Skip to content

Commit

Permalink
fix(groups): limit amount of group activity elements
Browse files Browse the repository at this point in the history
  • Loading branch information
nikensss committed Mar 31, 2024
1 parent 17fe71e commit 9a1c615
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 10 deletions.
4 changes: 3 additions & 1 deletion src/app/groups/[groupId]/group-activity.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<RouterOutputs['groups']['get'], null>;
amountToShow: number;
}) {
const settlementListItems = settlements.map((s) => ({
date: s.date,
Expand All @@ -34,7 +36,7 @@ export default function RecentGroupActivity({
return (
<GroupList>
<GroupListTitle>Recent activity</GroupListTitle>
<GroupListBody>{allItems.slice(0, 5).map((item) => item.component)}</GroupListBody>
<GroupListBody>{allItems.slice(0, amountToShow).map((item) => item.component)}</GroupListBody>
</GroupList>
);
}
Expand Down
6 changes: 3 additions & 3 deletions src/app/groups/[groupId]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<>
Expand All @@ -44,7 +44,7 @@ export default async function GroupPage({ params: { groupId } }: { params: { gro
</Button>
</div>
<div className="flex grow flex-col gap-2 lg:grid lg:grid-cols-2 lg:grid-rows-1">
<RecentGroupActivity {...{ expenses, settlements, user, group }} />
<RecentGroupActivity {...{ expenses, settlements, user, group, amountToShow: Math.max(5, balance.length) }} />
<GroupBalance {...{ group, balance, user }} />
</div>
</>
Expand Down
6 changes: 3 additions & 3 deletions src/server/api/routers/groups/expenses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -177,7 +177,7 @@ export const groupExpensesRouter = createTRPCRouter({
date: 'desc',
},
},
take: 5,
take,
});
}),
});
6 changes: 3 additions & 3 deletions src/server/api/routers/groups/settlements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -128,7 +128,7 @@ export const groupSettlementsRouter = createTRPCRouter({
orderBy: {
date: 'desc',
},
take: 5,
take,
});
}),
});

0 comments on commit 9a1c615

Please sign in to comment.