mirror of
https://github.com/escalante29/WealthySmart.git
synced 2026-07-17 09:08:46 +02:00
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:
@@ -16,11 +16,11 @@ import {
|
||||
|
||||
/** All budget data hangs off the ['budget', ...] key family; every mutation
|
||||
* invalidates the family so projection, month detail and items stay in sync. */
|
||||
export function useBudget(initialYear: number) {
|
||||
export function useBudget(initialYear: number, initialMonth?: number) {
|
||||
const queryClient = useQueryClient();
|
||||
const [year, setYear] = useState(initialYear);
|
||||
const [selectedMonth, setSelectedMonth] = useState<number>(
|
||||
new Date().getMonth() + 1,
|
||||
initialMonth ?? new Date().getMonth() + 1,
|
||||
);
|
||||
|
||||
const projectionQ = useQuery({
|
||||
|
||||
@@ -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('');
|
||||
|
||||
@@ -99,7 +99,9 @@ export default function Proyecciones() {
|
||||
year={year}
|
||||
onSelectMonth={(m) => {
|
||||
setSelectedMonth(m);
|
||||
navigate('/budget', { state: { from: 'proyecciones' } });
|
||||
navigate('/budget', {
|
||||
state: { from: 'proyecciones', year, month: m },
|
||||
});
|
||||
}}
|
||||
onSaveOverride={async (month, value) => {
|
||||
await saveBalanceOverride(year, month, value);
|
||||
|
||||
Reference in New Issue
Block a user