diff --git a/packages/desktop-client/e2e/mobile.test.js-snapshots/Mobile-loads-the-budget-page-with-budgeted-amounts-1-chromium-linux.png b/packages/desktop-client/e2e/mobile.test.js-snapshots/Mobile-loads-the-budget-page-with-budgeted-amounts-1-chromium-linux.png index 4e52ef1c12c..32c77b8ac70 100644 Binary files a/packages/desktop-client/e2e/mobile.test.js-snapshots/Mobile-loads-the-budget-page-with-budgeted-amounts-1-chromium-linux.png and b/packages/desktop-client/e2e/mobile.test.js-snapshots/Mobile-loads-the-budget-page-with-budgeted-amounts-1-chromium-linux.png differ diff --git a/packages/desktop-client/src/components/budget/MobileBudgetTable.js b/packages/desktop-client/src/components/budget/MobileBudgetTable.js index 0b27c37b4f1..6f8dbf39bce 100644 --- a/packages/desktop-client/src/components/budget/MobileBudgetTable.js +++ b/packages/desktop-client/src/components/budget/MobileBudgetTable.js @@ -1,4 +1,5 @@ import React, { Component, memo, PureComponent, useState } from 'react'; +import { useDispatch, useSelector } from 'react-redux'; // import { // RectButton, // PanGestureHandler, @@ -9,6 +10,7 @@ import React, { Component, memo, PureComponent, useState } from 'react'; import memoizeOne from 'memoize-one'; +import { savePrefs } from 'loot-core/src/client/actions'; import { rolloverBudget, reportBudget } from 'loot-core/src/client/queries'; import * as monthUtils from 'loot-core/src/shared/months'; import { amountToInteger, integerToAmount } from 'loot-core/src/shared/util'; @@ -16,6 +18,7 @@ import { amountToInteger, integerToAmount } from 'loot-core/src/shared/util'; import Add from '../../icons/v1/Add'; import ArrowThinLeft from '../../icons/v1/ArrowThinLeft'; import ArrowThinRight from '../../icons/v1/ArrowThinRight'; +import { useResponsive } from '../../ResponsiveProvider'; import { colors, styles } from '../../style'; import Button from '../common/Button'; import Card from '../common/Card'; @@ -71,7 +74,13 @@ function Saved({ projected }) { let isNegative = saved < 0; return ( - + {projected ? ( - {/* */} - + {show3Cols || showBudgetedCol ? ( + + ) : null} + {show3Cols || !showBudgetedCol ? ( + + ) : null} - {/* */} ); @@ -383,8 +379,8 @@ class TotalsRow extends PureComponent { // } render() { - let { group, editMode, onAddCategory } = this.props; - + let { group, editMode, onAddCategory, show3Cols, showBudgetedCol } = + this.props; let content = ( - + {show3Cols || showBudgetedCol ? ( + + ) : null} + {show3Cols || !showBudgetedCol ? ( + + ) : null} } } - class IncomeCategory extends PureComponent { render() { const { @@ -597,6 +606,8 @@ class BudgetGroup extends PureComponent { // onReorderGroup, onAddCategory, onBudgetAction, + showBudgetedCol, + show3Cols, } = this.props; function editable(content) { @@ -637,8 +648,10 @@ class BudgetGroup extends PureComponent { > ); })} @@ -788,11 +807,11 @@ class BudgetGroups extends Component { export function BudgetTable(props) { const [editingCategory, setEditingCategory] = useState(null); - function onEditCategory(id) { setEditingCategory(id); } - + const { width } = useResponsive(); + const show3Cols = width >= 360; const { type, categoryGroups, @@ -815,11 +834,40 @@ export function BudgetTable(props) { let currentMonth = monthUtils.currentMonth(); let format = useFormat(); + const mobileShowBudgetedColPref = useSelector(state => { + return ( + (state.prefs.local && state.prefs.local.toggleMobileDisplayPref) || true + ); + }); + + let [showBudgetedCol, setShowBudgetedCol] = useState( + !mobileShowBudgetedColPref && + !document.cookie.match(/mobileShowBudgetedColPref=true/), + ); + + let dispatch = useDispatch(); + + function toggleDisplay() { + setShowBudgetedCol(!showBudgetedCol); + if (!showBudgetedCol) { + // remember the pref indefinitely + dispatch(savePrefs({ mobileShowBudgetedColPref: true })); + } + } + let buttonStyle = { + padding: 0, + backgroundColor: 'transparent', + borderRadius: 'unset', + }; + return ( onEditMode(false)} @@ -847,23 +895,62 @@ export function BudgetTable(props) { /> )} - - - +