Proyecciones: clicking a month row opens that month in Budget

The clicked year/month now travel in the navigation state; Budget
seeds useBudget with them instead of always defaulting to today.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Carlos Escalante
2026-07-03 20:40:09 -06:00
parent f832138b41
commit 72a5840752
3 changed files with 17 additions and 8 deletions

View File

@@ -22,6 +22,17 @@ const MAX_YEAR = 2030;
export default function Budget() {
const currentYear = Math.max(MIN_YEAR, new Date().getFullYear());
const location = useLocation();
const navigate = useNavigate();
// Proyecciones row clicks land here with the clicked period in the state.
const navState = location.state as
| { from?: string; year?: number; month?: number }
| null;
const cameFromProyecciones = navState?.from === 'proyecciones';
const initialYear =
navState?.year && navState.year >= MIN_YEAR && navState.year <= MAX_YEAR
? navState.year
: currentYear;
const {
year,
setYear,
@@ -35,12 +46,8 @@ export default function Budget() {
updateItem,
deleteItem,
refresh,
} = useBudget(currentYear);
} = useBudget(initialYear, navState?.month);
const queryClient = useQueryClient();
const location = useLocation();
const navigate = useNavigate();
const cameFromProyecciones =
(location.state as { from?: string } | null)?.from === 'proyecciones';
const [subTab, setSubTab] = useState<'detail' | 'transactions'>('detail');
const [txSearch, setTxSearch] = useState('');