diff --git a/src/App.jsx b/src/App.jsx
index b50d788..c6dde97 100644
--- a/src/App.jsx
+++ b/src/App.jsx
@@ -13,6 +13,18 @@ function addMonths(ym, delta) {
return fmt(d);
}
+// Detecta móvil para ajustar alturas de charts
+function useIsMobile() {
+ const [isMobile, setIsMobile] = useState(false);
+ useEffect(() => {
+ const onResize = () => setIsMobile(window.innerWidth < 640);
+ onResize();
+ window.addEventListener('resize', onResize);
+ return () => window.removeEventListener('resize', onResize);
+ }, []);
+ return isMobile;
+}
+
const FinanceTracker = () => {
// ====== Filtros (mes / histórico) ======
const [rangeMode, setRangeMode] = useState('month'); // 'month' | 'all'
@@ -35,11 +47,11 @@ const FinanceTracker = () => {
return () => { mounted = false; };
}, []);
- // ====== Datos (hook SIEMPRE se llama para mantener orden de hooks) ======
- const userId = user?.userId ?? null; // el backend ya toma userId del token
+ // ====== Datos (el hook SIEMPRE se llama para mantener orden) ======
+ const userId = user?.userId ?? null;
const { items, loading, error, create, remove } = useTransactions(userId, queryMonth);
- // ====== Estado local (resto de hooks antes de cualquier return) ======
+ // ====== Estado local UI ======
const [creditCards, setCreditCards] = useState([
{ id: 1, name: 'Visa Oro', limit: 30000, balance: 15000, cutoffDay: 15, paymentDay: 25 },
{ id: 2, name: 'Mastercard', limit: 20000, balance: 5000, cutoffDay: 10, paymentDay: 20 }
@@ -80,7 +92,6 @@ const FinanceTracker = () => {
if (!category || Number.isNaN(n)) return;
const signed = type === 'egreso' ? -Math.abs(n) : Math.abs(n);
const res = await create({ date, amount: signed, category, note: description, account: 'Other' });
- // reset
setNewTransaction({
date: new Date().toISOString().split('T')[0],
type: 'egreso', category: '', amount: '', description: ''
@@ -162,6 +173,9 @@ const FinanceTracker = () => {
return { totalIngresos, totalEgresos, balance, pieData, lineData, totalCreditLimit, totalCreditUsed, creditAvailable };
}, [transactions, creditCards]);
+ const isMobile = useIsMobile();
+ const chartHeight = isMobile ? 220 : 300;
+
// ====== Early returns (después de TODOS los hooks) ======
if (loadingUser) return
Cargando sesión…
;
if (!user) { window.location.href = '/login'; return null; }
@@ -171,35 +185,35 @@ const FinanceTracker = () => {
// ====== UI ======
return (
-
+
-
-
-
- Control de Finanzas Personales
+
+
+
+ Control de Finanzas Personales
-
-
{user.userDetails}
-
{/* Tabs */}
-
+
{['dashboard', 'transacciones', 'tarjetas'].map(tab => (
setActiveTab(tab)}
- className={`px-6 py-3 font-semibold transition-all ${
+ className={`px-4 sm:px-6 py-3 font-semibold whitespace-nowrap transition-all ${
activeTab === tab ? 'text-blue-600 border-b-2 border-blue-600' : 'text-slate-600 hover:text-slate-800'
}`}
>
@@ -209,26 +223,26 @@ const FinanceTracker = () => {
{/* Selector de rango (Mes / Histórico) */}
-
-