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

View File

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