refactor(frontend): Address code review feedback on focus and currency handling.

Co-authored-by: elisiariocouto <818914+elisiariocouto@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2025-12-07 01:33:45 +00:00
committed by Elisiário Couto
parent 2c85722fd0
commit c8b161e7f2
2 changed files with 16 additions and 15 deletions

View File

@@ -366,6 +366,9 @@ export default function TransactionsTable() {
.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,
@@ -411,7 +414,7 @@ export default function TransactionsTable() {
Income
</p>
<p className="text-2xl font-bold text-green-600 mt-1">
+{formatCurrency(stats.totalIncome, transactions[0]?.transaction_currency || "EUR")}
+{formatCurrency(stats.totalIncome, displayCurrency)}
</p>
</div>
<TrendingUp className="h-8 w-8 text-green-600 opacity-50" />
@@ -425,7 +428,7 @@ export default function TransactionsTable() {
Expenses
</p>
<p className="text-2xl font-bold text-red-600 mt-1">
-{formatCurrency(stats.totalExpenses, transactions[0]?.transaction_currency || "EUR")}
-{formatCurrency(stats.totalExpenses, displayCurrency)}
</p>
</div>
<TrendingDown className="h-8 w-8 text-red-600 opacity-50" />
@@ -444,7 +447,7 @@ export default function TransactionsTable() {
}`}
>
{stats.netChange >= 0 ? "+" : ""}
{formatCurrency(stats.netChange, transactions[0]?.transaction_currency || "EUR")}
{formatCurrency(stats.netChange, displayCurrency)}
</p>
</div>
{stats.netChange >= 0 ? (

View File

@@ -32,24 +32,22 @@ export function FilterBar({
className,
}: FilterBarProps) {
const searchInputRef = useRef<HTMLInputElement>(null);
const wasFocused = useRef(false);
// Track if search input was focused before re-render
// Maintain focus on search input during re-renders
useEffect(() => {
const currentInput = searchInputRef.current;
if (!currentInput) return;
// Check if the input was focused before the effect runs
if (document.activeElement === currentInput) {
wasFocused.current = true;
// Only restore focus if the search input had focus before
const wasFocused = document.activeElement === currentInput;
// Use requestAnimationFrame to restore focus after React finishes rendering
if (wasFocused && document.activeElement !== currentInput) {
requestAnimationFrame(() => {
currentInput.focus();
});
}
// If it was focused, restore focus after render
if (wasFocused.current && document.activeElement !== currentInput) {
currentInput.focus();
wasFocused.current = false;
}
});
}, [isSearchLoading]);
const hasActiveFilters =
filterState.searchTerm ||