Skip to content

A local-first personal finance app

[Mobile] Use budget start month pref on mobile to match desktop behavior (#2613)

Joel Jeremy Marqueze9b5bfcc5308
diff --git a/packages/desktop-client/src/components/budget/index.tsx b/packages/desktop-client/src/components/budget/index.tsx
index a95139bf72..927e553dd3 100644
--- a/packages/desktop-client/src/components/budget/index.tsx
+++ b/packages/desktop-client/src/components/budget/index.tsx
@@ -75,22 +75,20 @@ function BudgetInner(props: BudgetInnerProps) {
const spreadsheet = useSpreadsheet();
const dispatch = useDispatch();
const navigate = useNavigate();
- const [_startMonth, setBudgetStartMonthPref] =
- useLocalPref('budget.startMonth');
- const startMonth = _startMonth || currentMonth;
const [summaryCollapsed, setSummaryCollapsedPref] = useLocalPref(
'budget.summaryCollapsed',
);
- const [_budgetType] = useLocalPref('budgetType');
- const budgetType = _budgetType || 'rollover';
- const [_maxMonths] = useGlobalPref('maxMonths');
- const maxMonths = _maxMonths || 1;
-
- const [initialized, setInitialized] = useState(false);
+ const [startMonthPref, setStartMonthPref] = useLocalPref('budget.startMonth');
+ const startMonth = startMonthPref || currentMonth;
const [bounds, setBounds] = useState({
- start: currentMonth,
- end: currentMonth,
+ start: startMonth,
+ end: startMonth,
});
+ const [budgetTypePref] = useLocalPref('budgetType');
+ const budgetType = budgetTypePref || 'rollover';
+ const [maxMonthsPref] = useGlobalPref('maxMonths');
+ const maxMonths = maxMonthsPref || 1;
+ const [initialized, setInitialized] = useState(false);
const { grouped: categoryGroups } = useCategories();
function loadCategories() {
@@ -153,7 +151,7 @@ function BudgetInner(props: BudgetInnerProps) {
}, [props.accountId]);
const onMonthSelect = async (month, numDisplayed) => {
- setBudgetStartMonthPref(month);
+ setStartMonthPref(month);
const warmingMonth = month;
@@ -180,7 +178,7 @@ function BudgetInner(props: BudgetInnerProps) {
}
if (warmingMonth === month) {
- setBudgetStartMonthPref(month);
+ setStartMonthPref(month);
}
};
diff --git a/packages/desktop-client/src/components/mobile/budget/index.tsx b/packages/desktop-client/src/components/mobile/budget/index.tsx
index 0e244fb1f7..48d4705fb9 100644
--- a/packages/desktop-client/src/components/mobile/budget/index.tsx
+++ b/packages/desktop-client/src/components/mobile/budget/index.tsx
@@ -49,9 +49,12 @@ function BudgetInner(props: BudgetInnerProps) {
const { categoryGroups, categories, budgetType, spreadsheet } = props;
const currMonth = monthUtils.currentMonth();
-
- const [bounds, setBounds] = useState({ start: currMonth, end: currMonth });
- const [currentMonth, setCurrentMonth] = useState(currMonth);
+ const [startMonth = currMonth, setStartMonthPref] =
+ useLocalPref('budget.startMonth');
+ const [bounds, setBounds] = useState({
+ start: startMonth,
+ end: startMonth,
+ });
const [initialized, setInitialized] = useState(false);
// const [editMode, setEditMode] = useState(false);
@@ -65,7 +68,7 @@ function BudgetInner(props: BudgetInnerProps) {
const { start, end } = await send('get-budget-bounds');
setBounds({ start, end });
- await prewarmMonth(budgetType, spreadsheet, currentMonth);
+ await prewarmMonth(budgetType, spreadsheet, startMonth);
setInitialized(true);
}
@@ -85,7 +88,7 @@ function BudgetInner(props: BudgetInnerProps) {
});
return () => unlisten();
- }, [budgetType, currentMonth, dispatch, spreadsheet]);
+ }, [budgetType, startMonth, dispatch, spreadsheet]);
const onBudgetAction = async (month, type, args) => {
dispatch(applyBudgetAction(month, type, args));
@@ -95,13 +98,13 @@ function BudgetInner(props: BudgetInnerProps) {
if (budgetType === 'report') {
dispatch(
pushModal('report-budget-summary', {
- month: currentMonth,
+ month: startMonth,
}),
);
} else {
dispatch(
pushModal('rollover-budget-summary', {
- month: currentMonth,
+ month: startMonth,
onBudgetAction,
}),
);
@@ -233,16 +236,16 @@ function BudgetInner(props: BudgetInnerProps) {
};
const onPrevMonth = async () => {
- const month = monthUtils.subMonths(currentMonth, 1);
+ const month = monthUtils.subMonths(startMonth, 1);
await prewarmMonth(budgetType, spreadsheet, month);
- setCurrentMonth(month);
+ setStartMonthPref(month);
setInitialized(true);
};
const onNextMonth = async () => {
- const month = monthUtils.addMonths(currentMonth, 1);
+ const month = monthUtils.addMonths(startMonth, 1);
await prewarmMonth(budgetType, spreadsheet, month);
- setCurrentMonth(month);
+ setStartMonthPref(month);
setInitialized(true);
};
@@ -293,7 +296,7 @@ function BudgetInner(props: BudgetInnerProps) {
newBudgetType,
spreadsheet,
bounds,
- currentMonth,
+ startMonth,
async () => {
dispatch(loadPrefs());
},
@@ -401,7 +404,7 @@ function BudgetInner(props: BudgetInnerProps) {
}
return (
- <NamespaceContext.Provider value={monthUtils.sheetForMonth(currentMonth)}>
+ <NamespaceContext.Provider value={monthUtils.sheetForMonth(startMonth)}>
<SyncRefresh
onSync={async () => {
dispatch(sync());
@@ -414,7 +417,7 @@ function BudgetInner(props: BudgetInnerProps) {
key={`${numberFormat}${hideFraction}`}
categoryGroups={categoryGroups}
type={budgetType}
- month={currentMonth}
+ month={startMonth}
monthBounds={bounds}
// editMode={editMode}
onShowBudgetSummary={onShowBudgetSummary}
diff --git a/upcoming-release-notes/2613.md b/upcoming-release-notes/2613.md
new file mode 100644
index 0000000000..d3d0e90d6e
--- /dev/null
+++ b/upcoming-release-notes/2613.md
@@ -0,0 +1,6 @@
+---
+category: Enhancements
+authors: [joel-jeremy]
+---
+
+Honor the budget.startMonth pref to open the last month the user was working on before closing the app.