diff --git a/frontend/src/pages/Rentabilidad.jsx b/frontend/src/pages/Rentabilidad.jsx index da70a05..d02c384 100644 --- a/frontend/src/pages/Rentabilidad.jsx +++ b/frontend/src/pages/Rentabilidad.jsx @@ -4,6 +4,7 @@ import { api } from "../lib/api"; import { Loader, ErrorBox, Filters, Select } from "../components/UI"; import Modal from "../components/Modal"; import { useColumnasAjustables } from "../lib/useColumnasAjustables"; +import { setVistaActual, onRefrescar } from "../lib/vistaActual"; const MESES = ["ENERO","FEBRERO","MARZO","ABRIL","MAYO","JUNIO","JULIO","AGOSTO","SEPTIEMBRE","OCTUBRE","NOVIEMBRE","DICIEMBRE"]; const ANOS = [2024, 2025, 2026]; @@ -44,11 +45,16 @@ export default function Rentabilidad() { useEffect(() => { let activo = true; - setLoading(true); setError(null); - api.rentabilidad(ano, mes, sede, programa) - .then((res) => { if (activo) { setFilas(res.filas || []); setLoading(false); } }) - .catch((e) => { if (activo) { setError(e.message); setLoading(false); } }); - return () => { activo = false; }; + setVistaActual(`rentabilidad:${ano}|${mes}|${sede}|${programa}`); + const cargarSeguro = () => { + setLoading(true); setError(null); + api.rentabilidad(ano, mes, sede, programa) + .then((res) => { if (activo) { setFilas(res.filas || []); setLoading(false); } }) + .catch((e) => { if (activo) { setError(e.message); setLoading(false); } }); + }; + cargarSeguro(); + const off = onRefrescar(cargarSeguro); + return () => { activo = false; off(); }; }, [ano, mes, sede, programa]); const datos = useMemo(() => filas.filter((f)=>String(f[0]).toUpperCase()!=="TOTAL GENERAL"), [filas]);