Skip to content

Commit

Permalink
Use document count only instead of whole document list
Browse files Browse the repository at this point in the history
  • Loading branch information
scastiel committed Dec 7, 2024
1 parent adf35b2 commit b3991fc
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 12 deletions.
13 changes: 3 additions & 10 deletions src/app/groups/[groupId]/expenses/documents-count.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
import { ExpenseFormValues } from '@/lib/schemas'
import { Paperclip } from 'lucide-react'
import { useTranslations } from 'next-intl'

type DocumentCount = {
documents: ExpenseFormValues['documents']
}
export function DocumentsCount({ documents }: DocumentCount) {
const t = useTranslations('ExpenseCard')
const documentsCount = documents.length
if (documentsCount === 0) return <></>
export function DocumentsCount({ count }: { count: number }) {
if (count === 0) return <></>
return (
<div className="flex items-center">
<Paperclip className="w-3.5 h-3.5 mr-1 mt-0.5 text-muted-foreground" />
<span>{documentsCount}</span>
<span>{count}</span>
</div>
)
}
2 changes: 1 addition & 1 deletion src/app/groups/[groupId]/expenses/expense-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export function ExpenseCard({ expense, currency, groupId }: Props) {
{formatCurrency(currency, expense.amount, locale)}
</div>
<div className="text-xs text-muted-foreground">
<DocumentsCount documents={expense.documents} />
<DocumentsCount count={expense._count.documents} />
</div>
<div className="text-xs text-muted-foreground">
{formatDate(expense.expenseDate, locale, { dateStyle: 'medium' })}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ export async function getGroupExpenses(
},
splitMode: true,
title: true,
documents: true,
_count: { select: { documents: true } },
},
where: {
groupId,
Expand Down

0 comments on commit b3991fc

Please sign in to comment.