mirror of
https://github.com/elisiariocouto/leggen.git
synced 2025-12-13 09:02:23 +00:00
Compare commits
3 Commits
44c1fa22e0
...
0531098f6d
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0531098f6d | ||
|
|
6053abbf35 | ||
|
|
2d0ca27a79 |
@@ -126,7 +126,10 @@ export default function TransactionsTable() {
|
||||
placeholderData: (previousData) => previousData,
|
||||
});
|
||||
|
||||
const transactions = transactionsResponse?.data || [];
|
||||
const transactions = useMemo(
|
||||
() => transactionsResponse?.data || [],
|
||||
[transactionsResponse],
|
||||
);
|
||||
const pagination = useMemo(
|
||||
() =>
|
||||
transactionsResponse
|
||||
@@ -142,6 +145,31 @@ export default function TransactionsTable() {
|
||||
[transactionsResponse],
|
||||
);
|
||||
|
||||
// Calculate stats from current page transactions, memoized for performance
|
||||
const stats = useMemo(() => {
|
||||
const totalIncome = transactions
|
||||
.filter((t: Transaction) => t.transaction_value > 0)
|
||||
.reduce((sum: number, t: Transaction) => sum + t.transaction_value, 0);
|
||||
|
||||
const totalExpenses = Math.abs(
|
||||
transactions
|
||||
.filter((t: Transaction) => t.transaction_value < 0)
|
||||
.reduce((sum: number, t: Transaction) => sum + t.transaction_value, 0)
|
||||
);
|
||||
|
||||
// Get currency from first transaction, fallback to EUR
|
||||
const displayCurrency = transactions.length > 0 ? transactions[0].transaction_currency : "EUR";
|
||||
|
||||
return {
|
||||
totalCount: pagination?.total || 0,
|
||||
pageCount: transactions.length,
|
||||
totalIncome,
|
||||
totalExpenses,
|
||||
netChange: totalIncome - totalExpenses,
|
||||
displayCurrency,
|
||||
};
|
||||
}, [transactions, pagination]);
|
||||
|
||||
// Check if search is currently debouncing
|
||||
const isSearchLoading = filterState.searchTerm !== debouncedSearchTerm;
|
||||
|
||||
@@ -356,28 +384,6 @@ export default function TransactionsTable() {
|
||||
);
|
||||
}
|
||||
|
||||
// Calculate stats from current page transactions
|
||||
const totalIncome = transactions
|
||||
.filter((t: Transaction) => t.transaction_value > 0)
|
||||
.reduce((sum: number, t: Transaction) => sum + t.transaction_value, 0);
|
||||
|
||||
const totalExpenses = Math.abs(
|
||||
transactions
|
||||
.filter((t: Transaction) => t.transaction_value < 0)
|
||||
.reduce((sum: number, t: Transaction) => sum + t.transaction_value, 0)
|
||||
);
|
||||
|
||||
// Get currency from first transaction, fallback to EUR
|
||||
const displayCurrency = transactions.length > 0 ? transactions[0].transaction_currency : "EUR";
|
||||
|
||||
const stats = {
|
||||
totalCount: pagination?.total || 0,
|
||||
pageCount: transactions.length,
|
||||
totalIncome,
|
||||
totalExpenses,
|
||||
netChange: totalIncome - totalExpenses,
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="space-y-6 max-w-full">
|
||||
{/* New FilterBar */}
|
||||
@@ -415,7 +421,7 @@ export default function TransactionsTable() {
|
||||
Income
|
||||
</p>
|
||||
<BlurredValue className="text-2xl font-bold text-green-600 mt-1 block">
|
||||
+{formatCurrency(stats.totalIncome, displayCurrency)}
|
||||
+{formatCurrency(stats.totalIncome, stats.displayCurrency)}
|
||||
</BlurredValue>
|
||||
</div>
|
||||
<TrendingUp className="h-8 w-8 text-green-600 opacity-50" />
|
||||
@@ -429,7 +435,7 @@ export default function TransactionsTable() {
|
||||
Expenses
|
||||
</p>
|
||||
<BlurredValue className="text-2xl font-bold text-red-600 mt-1 block">
|
||||
-{formatCurrency(stats.totalExpenses, displayCurrency)}
|
||||
-{formatCurrency(stats.totalExpenses, stats.displayCurrency)}
|
||||
</BlurredValue>
|
||||
</div>
|
||||
<TrendingDown className="h-8 w-8 text-red-600 opacity-50" />
|
||||
@@ -448,7 +454,7 @@ export default function TransactionsTable() {
|
||||
}`}
|
||||
>
|
||||
{stats.netChange >= 0 ? "+" : ""}
|
||||
{formatCurrency(stats.netChange, displayCurrency)}
|
||||
{formatCurrency(stats.netChange, stats.displayCurrency)}
|
||||
</BlurredValue>
|
||||
</div>
|
||||
{stats.netChange >= 0 ? (
|
||||
|
||||
@@ -44,7 +44,7 @@ export function FilterBar({
|
||||
currentInput.focus();
|
||||
currentInput.setSelectionRange(cursorPositionRef.current, cursorPositionRef.current);
|
||||
}
|
||||
});
|
||||
}, [isSearchLoading]);
|
||||
|
||||
const hasActiveFilters =
|
||||
filterState.searchTerm ||
|
||||
|
||||
Reference in New Issue
Block a user