diff --git a/packages/desktop-client/src/components/mobile/budget/BudgetTable.jsx b/packages/desktop-client/src/components/mobile/budget/BudgetTable.jsx
index e8465eb7439..3a81c34fa7c 100644
--- a/packages/desktop-client/src/components/mobile/budget/BudgetTable.jsx
+++ b/packages/desktop-client/src/components/mobile/budget/BudgetTable.jsx
@@ -1,44 +1,31 @@
-import React, { memo, useCallback, useRef } from 'react';
+import React from 'react';
import { useTranslation } from 'react-i18next';
import { Button } from '@actual-app/components/button';
-import { Card } from '@actual-app/components/card';
import { Label } from '@actual-app/components/label';
import { styles } from '@actual-app/components/styles';
import { Text } from '@actual-app/components/text';
import { View } from '@actual-app/components/view';
-import { css } from '@emotion/css';
import { AutoTextSize } from 'auto-text-size';
import memoizeOne from 'memoize-one';
-import { collapseModals, pushModal } from 'loot-core/client/actions';
import {
envelopeBudget,
trackingBudget,
uncategorizedCount,
} from 'loot-core/client/queries';
import * as monthUtils from 'loot-core/shared/months';
-import { groupById, integerToCurrency } from 'loot-core/shared/util';
-import { useCategories } from '../../../hooks/useCategories';
-import { useFeatureFlag } from '../../../hooks/useFeatureFlag';
import { useLocalPref } from '../../../hooks/useLocalPref';
-import { useNavigate } from '../../../hooks/useNavigate';
import { useSyncedPref } from '../../../hooks/useSyncedPref';
-import { useUndo } from '../../../hooks/useUndo';
import { SvgLogo } from '../../../icons/logo';
-import { SvgExpandArrow } from '../../../icons/v0';
import {
SvgArrowThinLeft,
SvgArrowThinRight,
- SvgArrowThickRight,
SvgCheveronRight,
} from '../../../icons/v1';
import { SvgCalendar, SvgViewShow } from '../../../icons/v2';
-import { useDispatch } from '../../../redux';
import { theme } from '../../../style';
-import { BalanceWithCarryover } from '../../budget/BalanceWithCarryover';
-import { makeAmountGrey, makeBalanceAmountStyle } from '../../budget/util';
import { Link } from '../../common/Link';
import { MobilePageHeader, Page } from '../../Page';
import { PrivacyFilter } from '../../PrivacyFilter';
@@ -49,9 +36,8 @@ import { useSheetValue } from '../../spreadsheet/useSheetValue';
import { MOBILE_NAV_HEIGHT } from '../MobileNavTabs';
import { PullToRefresh } from '../PullToRefresh';
-import { BudgetCell } from './BudgetCell';
+import { ExpenseGroup } from './ExpenseGroup';
import { IncomeGroup } from './IncomeGroup';
-import { ListItem } from './ListItem';
export const PILL_STYLE = {
borderRadius: 16,
@@ -60,23 +46,23 @@ export const PILL_STYLE = {
};
export function getColumnWidth({
- show3Cols,
+ show3Columns = false,
isSidebar = false,
offset = 0,
} = {}) {
- // If show3Cols = 35vw | 20vw | 20vw | 20vw,
+ // If show3Columns = 35vw | 20vw | 20vw | 20vw,
// Else = 45vw | 25vw | 25vw,
if (!isSidebar) {
- return show3Cols ? `${20 + offset}vw` : `${25 + offset}vw`;
+ return show3Columns ? `${20 + offset}vw` : `${25 + offset}vw`;
}
- return show3Cols ? `${35 + offset}vw` : `${45 + offset}vw`;
+ return show3Columns ? `${35 + offset}vw` : `${45 + offset}vw`;
}
-function ToBudget({ toBudget, onPress, show3Cols }) {
+function ToBudget({ toBudget, onPress, show3Columns }) {
const { t } = useTranslation();
const amount = useSheetValue(toBudget);
const format = useFormat();
- const sidebarColumnWidth = getColumnWidth({ show3Cols, isSidebar: true });
+ const sidebarColumnWidth = getColumnWidth({ show3Columns, isSidebar: true });
return (
-
-
- {group.categories.map((cat, index) => (
-
- ))}
-
- );
-}
-
-// eslint-disable-next-line @typescript-eslint/no-unused-vars
-function ExpenseCategoryPreview({ name, pending, style }) {
- return (
-
- {name}
-
- );
-}
-
-const ExpenseCategory = memo(function ExpenseCategory({
- type,
- category,
- isHidden,
- goal,
- longGoal,
- budgeted,
- spent,
- balance,
- carryover,
- index,
- // gestures,
- blank,
- style,
- month,
- onEdit,
- onBudgetAction,
- show3Cols,
- showBudgetedCol,
-}) {
- const opacity = blank ? 0 : 1;
-
- const { t } = useTranslation();
- const isGoalTemplatesEnabled = useFeatureFlag('goalTemplatesEnabled');
- const goalTemp = useSheetValue(goal);
- const goalValue = isGoalTemplatesEnabled ? goalTemp : null;
-
- const [budgetType = 'rollover'] = useSyncedPref('budgetType');
- const modalBudgetType = budgetType === 'rollover' ? 'envelope' : 'tracking';
- const dispatch = useDispatch();
- const { showUndoNotification } = useUndo();
- const { list: categories } = useCategories();
- const categoriesById = groupById(categories);
-
- const onCarryover = useCallback(
- carryover => {
- onBudgetAction(month, 'carryover', {
- category: category.id,
- flag: carryover,
- });
- dispatch(collapseModals(`${modalBudgetType}-balance-menu`));
- },
- [modalBudgetType, category.id, dispatch, month, onBudgetAction],
- );
-
- const catBalance = useSheetValue(
- type === 'rollover'
- ? envelopeBudget.catBalance(category.id)
- : trackingBudget.catBalance(category.id),
- );
- const budgetedtmp = useSheetValue(budgeted);
- const balancetmp = useSheetValue(balance);
- const isLongGoal = useSheetValue(longGoal) === 1;
- const budgetedValue = isGoalTemplatesEnabled
- ? isLongGoal
- ? balancetmp
- : budgetedtmp
- : null;
-
- const onTransfer = useCallback(() => {
- dispatch(
- pushModal('transfer', {
- title: category.name,
- categoryId: category.id,
- month,
- amount: catBalance,
- onSubmit: (amount, toCategoryId) => {
- onBudgetAction(month, 'transfer-category', {
- amount,
- from: category.id,
- to: toCategoryId,
- });
- dispatch(collapseModals(`${modalBudgetType}-balance-menu`));
- showUndoNotification({
- message: `Transferred ${integerToCurrency(amount)} from ${category.name} to ${categoriesById[toCategoryId].name}.`,
- });
- },
- showToBeBudgeted: true,
- }),
- );
- }, [
- modalBudgetType,
- catBalance,
- categoriesById,
- category.id,
- category.name,
- dispatch,
- month,
- onBudgetAction,
- showUndoNotification,
- ]);
-
- const onCover = useCallback(() => {
- dispatch(
- pushModal('cover', {
- title: category.name,
- month,
- categoryId: category.id,
- onSubmit: fromCategoryId => {
- onBudgetAction(month, 'cover-overspending', {
- to: category.id,
- from: fromCategoryId,
- });
- dispatch(collapseModals(`${modalBudgetType}-balance-menu`));
- showUndoNotification({
- message: t(
- `Covered {{toCategoryName}} overspending from {{fromCategoryName}}.`,
- {
- toCategoryName: category.name,
- fromCategoryName: categoriesById[fromCategoryId].name,
- },
- ),
- });
- },
- }),
- );
- }, [
- modalBudgetType,
- categoriesById,
- category.id,
- category.name,
- dispatch,
- month,
- onBudgetAction,
- showUndoNotification,
- t,
- ]);
-
- const onOpenBalanceMenu = useCallback(() => {
- dispatch(
- pushModal(`${modalBudgetType}-balance-menu`, {
- categoryId: category.id,
- month,
- onCarryover,
- ...(budgetType === 'rollover' && { onTransfer, onCover }),
- }),
- );
- }, [
- modalBudgetType,
- budgetType,
- category.id,
- dispatch,
- month,
- onCarryover,
- onCover,
- onTransfer,
- ]);
-
- const listItemRef = useRef();
- const format = useFormat();
- const navigate = useNavigate();
- const onShowActivity = useCallback(() => {
- navigate(`/categories/${category.id}?month=${month}`);
- }, [category.id, month, navigate]);
-
- const sidebarColumnWidth = getColumnWidth({ show3Cols, isSidebar: true });
- const columnWidth = getColumnWidth({ show3Cols });
-
- const content = (
- 0 ? 1 : 0,
- opacity: isHidden ? 0.5 : undefined,
- ...style,
- }}
- data-testid="category-row"
- innerRef={listItemRef}
- >
-
-
-
-
-
-
-
-
-
- {({ type, value }) => (
-
- )}
-
-
-
- (
-
-
-
- )}
- >
- {({ type, value }) => (
-
- )}
-
-
-
-
- );
-
- return {content};
-
- // (
- //
- // )}
- // gestures={gestures}
- // >
- // {
- // let pos = (y - layout.y) / layout.height;
- // return pos < 0.5 ? 'top' : 'bottom';
- // }}
- // onDrop={(id, type, droppable, status) =>
- // props.onReorder(id.replace('category:', ''), {
- // aroundCategory: {
- // id: category.id,
- // position: status
- // }
- // })
- // }
- // >
- // {() => content}
- //
- //
-});
-
-const ExpenseGroupHeader = memo(function ExpenseGroupHeader({
- group,
- budgeted,
- spent,
- balance,
- editMode,
- onEdit,
- blank,
- show3Cols,
- showBudgetedCol,
- collapsed,
- onToggleCollapse,
- style,
-}) {
- const opacity = blank ? 0 : 1;
- const listItemRef = useRef();
- const format = useFormat();
- const sidebarColumnWidth = getColumnWidth({
- show3Cols,
- isSidebar: true,
- offset: -3.5,
- });
- const columnWidth = getColumnWidth({ show3Cols });
-
- const amountStyle = {
- width: columnWidth,
- fontSize: 12,
- fontWeight: '500',
- paddingLeft: 5,
- textAlign: 'right',
- };
-
- const content = (
-
-
-
-
-
-
-
-
- {({ type, value }) => (
-
-
-
- {format(value, type)}
-
-
-
- )}
-
-
-
-
- {({ type, value }) => (
-
-
-
- {format(value, type)}
-
-
-
- )}
-
-
-
- {({ type, value }) => (
-
-
-
- {format(value, type)}
-
-
-
- )}
-
-
-
- {/* {editMode && (
-
-
-
- )} */}
-
- );
-
- if (!editMode) {
- return content;
- }
-
- return content;
- // {
- // return 'bottom';
- // }}
- // onDrop={(id, type, droppable, status) =>
- // props.onReorderCategory(id, { inGroup: group.id })
- // }
- // >
- // {() => content}
- //
-});
-
-const ExpenseGroup = memo(function ExpenseGroup({
- type,
- group,
- editMode,
- onEditGroup,
- onEditCategory,
- // gestures,
- month,
- // onReorderCategory,
- // onReorderGroup,
- onAddCategory,
- onBudgetAction,
- showBudgetedCol,
- show3Cols,
- showHiddenCategories,
- collapsed,
- onToggleCollapse,
-}) {
- function editable(content) {
- if (!editMode) {
- return content;
- }
-
- return content;
- // (
- //
- // )}
- // gestures={gestures}
- // >
- // {
- // let pos = (y - layout.y) / layout.height;
- // return pos < 0.5 ? 'top' : 'bottom';
- // }}
- // onDrop={(id, type, droppable, status) => {
- // onReorderGroup(id, group.id, status);
- // }}
- // >
- // {() => content}
- //
- //
- }
-
- return editable(
-
-
-
- {group.categories
- .filter(
- category => !collapsed && (!category.hidden || showHiddenCategories),
- )
- .map((category, index) => {
- return (
-
- );
- })}
- ,
- );
-});
-
function UncategorizedButton() {
const count = useSheetValue(uncategorizedCount());
if (count === null || count <= 0) {
@@ -1050,21 +243,13 @@ function UncategorizedButton() {
}
function BudgetGroups({
- type,
categoryGroups,
onEditGroup,
onEditCategory,
- editMode,
- gestures,
month,
- onSaveCategory,
- onDeleteCategory,
- onAddCategory,
- onReorderCategory,
- onReorderGroup,
onBudgetAction,
- showBudgetedCol,
- show3Cols,
+ showBudgetedColumn,
+ show3Columns,
showHiddenCategories,
}) {
const separateGroups = memoizeOne(groups => {
@@ -1097,23 +282,15 @@ function BudgetGroups({
return (
);
@@ -1136,21 +313,12 @@ function BudgetGroups({
}
export function BudgetTable({
- type,
categoryGroups,
month,
monthBounds,
- // editMode,
onPrevMonth,
onNextMonth,
onCurrentMonth,
- onSaveGroup,
- onDeleteGroup,
- onAddCategory,
- onSaveCategory,
- onDeleteCategory,
- onReorderCategory,
- onReorderGroup,
onShowBudgetSummary,
onBudgetAction,
onRefresh,
@@ -1161,7 +329,7 @@ export function BudgetTable({
}) {
const { t } = useTranslation();
const { width } = useResponsive();
- const show3Cols = width >= 360;
+ const show3Columns = width >= 360;
// let editMode = false; // neuter editMode -- sorry, not rewriting drag-n-drop right now
@@ -1177,6 +345,8 @@ export function BudgetTable({
'budget.showHiddenCategories',
);
+ const [budgetType = 'rollover'] = useSyncedPref('budgetType');
+
return (
@@ -1269,8 +429,7 @@ export function BudgetTable({
}
function BudgetTableHeader({
- show3Cols,
- type,
+ show3Columns,
month,
onShowBudgetSummary,
showSpentColumn,
@@ -1278,13 +437,14 @@ function BudgetTableHeader({
}) {
const { t } = useTranslation();
const format = useFormat();
+ const [budgetType = 'rollover'] = useSyncedPref('budgetType');
const buttonStyle = {
padding: 0,
backgroundColor: 'transparent',
borderRadius: 'unset',
};
- const sidebarColumnWidth = getColumnWidth({ show3Cols, isSidebar: true });
- const columnWidth = getColumnWidth({ show3Cols });
+ const sidebarColumnWidth = getColumnWidth({ show3Columns, isSidebar: true });
+ const columnWidth = getColumnWidth({ show3Columns });
const amountStyle = {
color: theme.formInputText,
@@ -1318,17 +478,17 @@ function BudgetTableHeader({
alignItems: 'center',
}}
>
- {type === 'report' ? (
+ {budgetType === 'report' ? (
= monthUtils.currentMonth()}
onPress={onShowBudgetSummary}
- show3Cols={show3Cols}
+ show3Columns={show3Columns}
/>
) : (
)}
@@ -1339,10 +499,10 @@ function BudgetTableHeader({
alignItems: 'center',
}}
>
- {(show3Cols || !showSpentColumn) && (
+ {(show3Columns || !showSpentColumn) && (
(
)}
- {(show3Cols || showSpentColumn) && (
+ {(show3Columns || showSpentColumn) && (
(