Skip to content

A local-first personal finance app

Editable mobile budget (#1662)

Joel Jeremy Marquezf1973d55c03b
diff --git a/packages/desktop-client/src/components/budget/MobileBudgetTable.js b/packages/desktop-client/src/components/budget/MobileBudgetTable.js
index 0533135d5f..9fd0ae8f18 100644
--- a/packages/desktop-client/src/components/budget/MobileBudgetTable.js
+++ b/packages/desktop-client/src/components/budget/MobileBudgetTable.js
@@ -1,4 +1,4 @@
-import React, { Component, memo, PureComponent, useState } from 'react';
+import React, { memo, useState } from 'react';
import { useDispatch, useSelector } from 'react-redux';
// import {
// RectButton,
@@ -13,7 +13,6 @@ 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';
import Add from '../../icons/v1/Add';
import ArrowThinLeft from '../../icons/v1/ArrowThinLeft';
@@ -42,7 +41,6 @@ import { ListItem, ROW_HEIGHT } from './MobileTable';
function ToBudget({ toBudget, onClick }) {
let amount = useSheetValue(toBudget);
- let format = useFormat();
return (
<Button
type="bare"
@@ -53,24 +51,25 @@ function ToBudget({ toBudget, onClick }) {
title={amount < 0 ? 'OVERBUDGETED' : 'TO BUDGET'}
style={{ color: theme.formInputText, flexShrink: 0 }}
/>
- <Text
+ <CellValue
+ binding={toBudget}
+ type="financial"
style={{
...styles.smallText,
fontWeight: '500',
color: amount < 0 ? theme.errorText : theme.formInputText,
}}
- >
- {format(amount, 'financial')}
- </Text>
+ />
</Button>
);
}
function Saved({ projected }) {
- let budgetedSaved = useSheetValue(reportBudget.totalBudgetedSaved) || 0;
- let totalSaved = useSheetValue(reportBudget.totalSaved) || 0;
- let format = useFormat();
- let saved = projected ? budgetedSaved : totalSaved;
+ let binding = projected
+ ? reportBudget.totalBudgetedSaved
+ : reportBudget.totalSaved;
+
+ let saved = useSheetValue(binding) || 0;
let isNegative = saved < 0;
return (
@@ -93,7 +92,9 @@ function Saved({ projected }) {
/>
)}
- <Text
+ <CellValue
+ binding={binding}
+ type="financial"
style={{
...styles.smallText,
fontWeight: '500',
@@ -103,66 +104,71 @@ function Saved({ projected }) {
? theme.alt2ErrorText
: theme.formInputText,
}}
- >
- {format(saved, 'financial')}
- </Text>
+ />
</View>
);
}
-const BudgetCell = memo(function BudgetCell(props) {
- const {
- name,
- binding,
- editing,
- style,
- textStyle,
- categoryId,
- month,
- onBudgetAction,
- } = props;
-
+function BudgetCell({
+ name,
+ binding,
+ editing,
+ style,
+ textStyle,
+ categoryId,
+ month,
+ onBudgetAction,
+ onEdit,
+}) {
let sheetValue = useSheetValue(binding);
- let format = useFormat();
- return (
- <View style={style}>
- <AmountInput
- value={integerToAmount(sheetValue || 0)}
- style={{
- height: ROW_HEIGHT - 4,
- transform: 'translateX(6px)',
- ...(!editing && {
- opacity: 0,
- position: 'absolute',
- top: 0,
- }),
- }}
- focused={editing}
- textStyle={{ ...styles.smallText, ...textStyle }}
- onChange={() => {}} // temporarily disabled for read-only view
- onBlur={value => {
- onBudgetAction(month, 'budget-amount', {
- category: categoryId,
- amount: amountToInteger(value),
- });
- }}
- />
+ function updateBudgetAmount(amount) {
+ onBudgetAction?.(month, 'budget-amount', {
+ category: categoryId,
+ amount: amount,
+ });
+ }
- <View
- style={{
- justifyContent: 'center',
- height: ROW_HEIGHT - 4,
- ...(editing && { display: 'none' }),
- }}
- >
- <Text style={{ ...styles.smallText, ...textStyle }} data-testid={name}>
- {format(sheetValue || 0, 'financial')}
- </Text>
- </View>
+ function onAmountClick(e) {
+ onEdit?.(categoryId);
+ }
+
+ return (
+ <View
+ style={style}
+ onPointerUp={onAmountClick}
+ onPointerDown={e => e.preventDefault()}
+ >
+ {editing ? (
+ <AmountInput
+ initialValue={sheetValue}
+ style={{
+ height: ROW_HEIGHT - 4,
+ transform: 'translateX(6px)',
+ }}
+ focused={editing}
+ textStyle={{ ...styles.smallText, ...textStyle }}
+ onChange={updateBudgetAmount}
+ onEdit={onEdit}
+ />
+ ) : (
+ <View
+ style={{
+ justifyContent: 'center',
+ height: ROW_HEIGHT - 4,
+ }}
+ >
+ <CellValue
+ binding={binding}
+ type="financial"
+ style={{ ...styles.smallText, ...textStyle }}
+ data-testid={name}
+ />
+ </View>
+ )}
</View>
);
-});
+}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
function BudgetGroupPreview({ group, pending, style }) {
@@ -248,203 +254,190 @@ function BudgetCategoryPreview({ name, pending, style }) {
);
}
-class BudgetCategory extends PureComponent {
- constructor(props) {
- super(props);
+const BudgetCategory = memo(function BudgetCategory({
+ category,
+ editing,
+ index,
+ // gestures,
+ editMode,
+ blank,
+ style,
+ month,
+ onEdit,
+ onBudgetAction,
+ show3Cols,
+ showBudgetedCol,
+}) {
+ // let opacity = new Animated.Value(editMode || blank ? 0 : 1);
+ let opacity = editMode || blank ? 0 : 1;
- let { editMode, blank } = props;
- this.opacity = editMode || blank ? 0 : 1;
- }
+ // useEffect(() => {
+ // if (editing && ACTScrollViewManager) {
+ // ACTScrollViewManager.setFocused(findNodeHandle(container.current));
+ // }
+ // }, [editing]);
- render() {
- let {
- category,
- editing,
- index,
- style,
- month,
- onBudgetAction,
- show3Cols,
- showBudgetedCol,
- } = this.props;
- let budgeted = rolloverBudget.catBudgeted(category.id);
- let balance = rolloverBudget.catBalance(category.id);
- let spent = rolloverBudget.catSumAmount(category.id);
-
- let content = !category.hidden && (
- <ListItem
+ // useEffect(() => {
+ // Animated.timing(this.opacity, {
+ // toValue: this.props.editMode ? 0 : 1,
+ // duration: 200,
+ // easing: Easing.inOut(Easing.ease),
+ // }).start();
+ // }, [editMode]);
+
+ let budgeted = rolloverBudget.catBudgeted(category.id);
+ let balance = rolloverBudget.catBalance(category.id);
+ let spent = rolloverBudget.catSumAmount(category.id);
+
+ let content = !category.hidden && (
+ <ListItem
+ style={{
+ backgroundColor: editing ? theme.altTableTextEditing : 'transparent',
+ borderBottomWidth: 0,
+ borderTopWidth: index > 0 ? 1 : 0,
+ ...style,
+ }}
+ data-testid="row"
+ >
+ <View style={{ flex: 1 }}>
+ <Text style={styles.smallText} data-testid="category-name">
+ {category.name}
+ </Text>
+ </View>
+ <View
style={{
- backgroundColor: editing ? theme.altTableTextEditing : 'transparent',
- borderBottomWidth: 0,
- borderTopWidth: index > 0 ? 1 : 0,
- ...style,
+ alignItems: 'center',
+ flexDirection: 'row',
+ opacity: opacity,
}}
- data-testid="row"
>
- <View style={{ flex: 1 }}>
- <Text style={styles.smallText} data-testid="category-name">
- {category.name}
- </Text>
- </View>
- <View
- style={{
- alignItems: 'center',
- flexDirection: 'row',
- opacity: this.opacity,
- }}
- >
- {show3Cols || showBudgetedCol ? (
- <BudgetCell
- name="budgeted"
- binding={budgeted}
- editing={editing}
- style={{ width: 90 }}
- textStyle={{ ...styles.smallText, textAlign: 'right' }}
- categoryId={category.id}
- month={month}
- onBudgetAction={onBudgetAction}
- />
- ) : null}
- {show3Cols || !showBudgetedCol ? (
- <CellValue
- name="spent"
- binding={spent}
- style={{
- ...styles.smallText,
- width: 90,
- textAlign: 'right',
- }}
- type="financial"
- />
- ) : null}
+ {show3Cols || showBudgetedCol ? (
+ <BudgetCell
+ name="budgeted"
+ binding={budgeted}
+ editing={editing}
+ style={{ width: 90 }}
+ textStyle={{ ...styles.smallText, textAlign: 'right' }}
+ categoryId={category.id}
+ month={month}
+ onBudgetAction={onBudgetAction}
+ onEdit={onEdit}
+ />
+ ) : null}
+ {show3Cols || !showBudgetedCol ? (
<CellValue
- name="balance"
- binding={balance}
+ name="spent"
+ binding={spent}
style={{
...styles.smallText,
width: 90,
textAlign: 'right',
}}
- getStyle={value => value < 0 && { color: theme.errorText }}
type="financial"
/>
- </View>
- </ListItem>
- );
+ ) : null}
+ <CellValue
+ name="balance"
+ binding={balance}
+ style={{
+ ...styles.smallText,
+ width: 90,
+ textAlign: 'right',
+ }}
+ getStyle={value => value < 0 && { color: theme.errorText }}
+ type="financial"
+ />
+ </View>
+ </ListItem>
+ );
- return <div>{content}</div>;
- // <Draggable
- // id={category.id}
- // type="category"
- // preview={({ pending, style }) => (
- // <BudgetCategoryPreview
- // name={category.name}
- // pending={pending}
- // style={style}
- // />
- // )}
- // gestures={gestures}
- // >
- // <Droppable
- // type="category"
- // getActiveStatus={(x, y, { layout }, { id }) => {
- // let pos = (y - layout.y) / layout.height;
- // return pos < 0.5 ? 'top' : 'bottom';
- // }}
- // onDrop={(id, type, droppable, status) =>
- // this.props.onReorder(id.replace('category:', ''), {
- // aroundCategory: {
- // id: category.id,
- // position: status
- // }
- // })
- // }
- // >
- // {() => content}
- // </Droppable>
- // </Draggable>
- }
-}
+ return <View>{content}</View>;
-class TotalsRow extends PureComponent {
- constructor(props) {
- super(props);
+ // <Draggable
+ // id={category.id}
+ // type="category"
+ // preview={({ pending, style }) => (
+ // <BudgetCategoryPreview
+ // name={category.name}
+ // pending={pending}
+ // style={style}
+ // />
+ // )}
+ // gestures={gestures}
+ // >
+ // <Droppable
+ // type="category"
+ // getActiveStatus={(x, y, { layout }, { id }) => {
+ // 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}
+ // </Droppable>
+ // </Draggable>
+});
- let { editMode, blank } = props;
- // this.animation = new Animated.Value(editMode || blank ? 0 : 1);
- this.opacity = editMode || blank ? 0 : 1;
- }
+const TotalsRow = memo(function TotalsRow({
+ group,
+ editMode,
+ blank,
+ onAddCategory,
+ show3Cols,
+ showBudgetedCol,
+}) {
+ // useEffect(() => {
+ // Animated.timing(this.animation, {
+ // toValue: this.props.editMode ? 0 : 1,
+ // duration: 200,
+ // easing: Easing.inOut(Easing.ease),
+ // }).start();
+ // }, [editMode]);
- // componentDidUpdate(prevProps) {
- // if (prevProps.editMode !== this.props.editMode) {
- // Animated.timing(this.animation, {
- // toValue: this.props.editMode ? 0 : 1,
- // duration: 200,
- // easing: Easing.inOut(Easing.ease)
- // }).start();
- // }
- // }
+ // let animation = new Animated.Value(editMode || blank ? 0 : 1);
+ let opacity = editMode || blank ? 0 : 1;
- render() {
- let { group, editMode, onAddCategory, show3Cols, showBudgetedCol } =
- this.props;
- let content = (
- <ListItem
+ let content = (
+ <ListItem
+ style={{
+ flexDirection: 'row',
+ alignItems: 'center',
+ backgroundColor: theme.tableHeaderBackground,
+ }}
+ data-testid="totals"
+ >
+ <View style={{ flex: 1 }}>
+ <Text
+ style={{ ...styles.smallText, fontWeight: '500' }}
+ data-testid="name"
+ >
+ {group.name}
+ </Text>
+ </View>
+ {/* <Animated.View
style={{
flexDirection: 'row',
alignItems: 'center',
- backgroundColor: theme.tableHeaderBackground,
+ opacity: animation
+ }}
+ > */}
+ <View
+ style={{
+ flexDirection: 'row',
+ alignItems: 'center',
+ opacity: opacity,
}}
- data-testid="totals"
>
- <View style={{ flex: 1 }}>
- <Text
- style={{ ...styles.smallText, fontWeight: '500' }}
- data-testid="name"
- >
- {group.name}
- </Text>
- </View>
- {/* <Animated.View
- style={{
- flexDirection: 'row',
- alignItems: 'center',
- opacity: this.animation
- }}
- > */}
- <View
- style={{
- flexDirection: 'row',
- alignItems: 'center',
- opacity: this.opacity,
- }}
- >
- {show3Cols || showBudgetedCol ? (
- <CellValue
- binding={rolloverBudget.groupBudgeted(group.id)}
- style={{
- ...styles.smallText,
- width: 90,
- fontWeight: '500',
- textAlign: 'right',
- }}
- type="financial"
- />
- ) : null}
- {show3Cols || !showBudgetedCol ? (
- <CellValue
- binding={rolloverBudget.groupSumAmount(group.id)}
- style={{
- ...styles.smallText,
- width: 90,
- fontWeight: '500',
- textAlign: 'right',
- }}
- type="financial"
- />
- ) : null}
+ {show3Cols || showBudgetedCol ? (
<CellValue
- binding={rolloverBudget.groupBalance(group.id)}
+ binding={rolloverBudget.groupBudgeted(group.id)}
style={{
...styles.smallText,
width: 90,
@@ -453,113 +446,133 @@ class TotalsRow extends PureComponent {
}}
type="financial"
/>
- </View>
- {/* </Animated.View> */}
-
- {editMode && (
- // <Animated.View
- // style={{
- // flexDirection: 'row',
- // alignItems: 'center',
- // opacity: this.opacity,
- // position: 'absolute',
- // top: 0,
- // bottom: 0,
- // right: this.animation.interpolate({
- // inputRange: [0, 1],
- // outputRange: [5, -30]
- // })
- // }}
- // >
- <View>
- <Button
- onClick={() => onAddCategory(group.id)}
- style={{ padding: 10 }}
- >
- <Add width={15} height={15} />
- </Button>
- </View>
- // </Animated.View>
- )}
- </ListItem>
- );
-
- if (!editMode) {
- return content;
- }
-
- return content;
- // <Droppable
- // type="category"
- // getActiveStatus={(x, y, { layout }, { id }) => {
- // return 'bottom';
- // }}
- // onDrop={(id, type, droppable, status) =>
- // this.props.onReorderCategory(id, { inGroup: group.id })
- // }
- // >
- // {() => content}
- // </Droppable>
- }
-}
-class IncomeCategory extends PureComponent {
- render() {
- const {
- name,
- budget,
- hidden,
- balance,
- style,
- nameTextStyle,
- amountTextStyle,
- } = this.props;
- if (hidden) {
- return null;
- }
- return (
- <ListItem
- style={{
- flexDirection: 'row',
- alignItems: 'center',
- padding: 10,
- backgroundColor: 'transparent',
- ...style,
- }}
- >
- <View style={{ flex: 1 }}>
- <Text
- style={{ ...styles.smallText, ...nameTextStyle }}
- data-testid="name"
- >
- {name}
- </Text>
- </View>
- {budget && (
+ ) : null}
+ {show3Cols || !showBudgetedCol ? (
<CellValue
- binding={budget}
+ binding={rolloverBudget.groupSumAmount(group.id)}
style={{
...styles.smallText,
width: 90,
+ fontWeight: '500',
textAlign: 'right',
- ...amountTextStyle,
}}
type="financial"
/>
- )}
+ ) : null}
<CellValue
- binding={balance}
+ binding={rolloverBudget.groupBalance(group.id)}
style={{
...styles.smallText,
width: 90,
+ fontWeight: '500',
textAlign: 'right',
- ...amountTextStyle,
}}
type="financial"
/>
- </ListItem>
- );
+ </View>
+ {/* </Animated.View> */}
+
+ {editMode && (
+ // <Animated.View
+ // style={{
+ // flexDirection: 'row',
+ // alignItems: 'center',
+ // opacity: opacity,
+ // position: 'absolute',
+ // top: 0,
+ // bottom: 0,
+ // right: animation.interpolate({
+ // inputRange: [0, 1],
+ // outputRange: [5, -30]
+ // })
+ // }}
+ // >
+ <View>
+ <Button
+ onClick={() => onAddCategory(group.id)}
+ style={{ padding: 10 }}
+ >
+ <Add width={15} height={15} />
+ </Button>
+ </View>
+ // </Animated.View>
+ )}
+ </ListItem>
+ );
+
+ if (!editMode) {
+ return content;
}
-}
+
+ return content;
+ // <Droppable
+ // type="category"
+ // getActiveStatus={(x, y, { layout }, { id }) => {
+ // return 'bottom';
+ // }}
+ // onDrop={(id, type, droppable, status) =>
+ // props.onReorderCategory(id, { inGroup: group.id })
+ // }
+ // >
+ // {() => content}
+ // </Droppable>
+});
+
+const IncomeCategory = memo(function IncomeCategory({
+ name,
+ budget,
+ hidden,
+ balance,
+ style,
+ nameTextStyle,
+ amountTextStyle,
+}) {
+ if (hidden) {
+ return null;
+ }
+ return (
+ <ListItem
+ style={{
+ flexDirection: 'row',
+ alignItems: 'center',
+ padding: 10,
+ backgroundColor: 'transparent',
+ ...style,
+ }}
+ >
+ <View style={{ flex: 1 }}>
+ <Text
+ style={{ ...styles.smallText, ...nameTextStyle }}
+ data-testid="name"
+ >
+ {name}
+ </Text>
+ </View>
+ {budget && (
+ <CellValue
+ binding={budget}
+ style={{
+ ...styles.smallText,
+ width: 90,
+ textAlign: 'right',
+ ...amountTextStyle,
+ }}
+ type="financial"
+ />
+ )}
+ <CellValue
+ binding={balance}
+ style={{
+ ...styles.smallText,
+ width: 90,
+ textAlign: 'right',
+ ...amountTextStyle,
+ }}
+ type="financial"
+ />
+ </ListItem>
+ );
+});
// export function BudgetAccessoryView() {
// let emitter = useContext(AmountAccessoryContext);
@@ -600,218 +613,205 @@ class IncomeCategory extends PureComponent {
// );
// }
-class BudgetGroup extends PureComponent {
- render() {
- const {
- group,
- // editingId,
- editMode,
- // gestures,
- month,
- onEditCategory,
- onReorderCategory,
- // onReorderGroup,
- onAddCategory,
- onBudgetAction,
- showBudgetedCol,
- show3Cols,
- } = this.props;
-
- function editable(content) {
- if (!editMode) {
- return content;
- }
-
+const BudgetGroup = memo(function BudgetGroup({
+ group,
+ editingId,
+ editMode,
+ // gestures,
+ month,
+ onEditCategory,
+ // onReorderCategory,
+ // onReorderGroup,
+ onAddCategory,
+ onBudgetAction,
+ showBudgetedCol,
+ show3Cols,
+}) {
+ function editable(content) {
+ if (!editMode) {
return content;
- // <Draggable
- // id={group.id}
- // type="group"
- // preview={({ pending, style }) => (
- // <BudgetGroupPreview group={group} pending={pending} style={style} />
- // )}
- // gestures={gestures}
- // >
- // <Droppable
- // type="group"
- // getActiveStatus={(x, y, { layout }, { id }) => {
- // let pos = (y - layout.y) / layout.height;
- // return pos < 0.5 ? 'top' : 'bottom';
- // }}
- // onDrop={(id, type, droppable, status) => {
- // onReorderGroup(id, group.id, status);
- // }}
- // >
- // {() => content}
- // </Droppable>
- // </Draggable>
}
- if (!group.hidden) {
- return editable(
- <Card
- style={{
- marginTop: 7,
- marginBottom: 7,
- }}
- >
- <TotalsRow
- group={group}
- showBudgetedCol={showBudgetedCol}
- budgeted={rolloverBudget.groupBudgeted(group.id)}
- balance={rolloverBudget.groupBalance(group.id)}
+
+ return content;
+ // <Draggable
+ // id={group.id}
+ // type="group"
+ // preview={({ pending, style }) => (
+ // <BudgetGroupPreview group={group} pending={pending} style={style} />
+ // )}
+ // gestures={gestures}
+ // >
+ // <Droppable
+ // type="group"
+ // getActiveStatus={(x, y, { layout }, { id }) => {
+ // let pos = (y - layout.y) / layout.height;
+ // return pos < 0.5 ? 'top' : 'bottom';
+ // }}
+ // onDrop={(id, type, droppable, status) => {
+ // onReorderGroup(id, group.id, status);
+ // }}
+ // >
+ // {() => content}
+ // </Droppable>
+ // </Draggable>
+ }
+
+ if (group.hidden) {
+ return null;
+ }
+
+ return editable(
+ <Card
+ style={{
+ marginTop: 7,
+ marginBottom: 7,
+ }}
+ >
+ <TotalsRow
+ group={group}
+ showBudgetedCol={showBudgetedCol}
+ budgeted={rolloverBudget.groupBudgeted(group.id)}
+ balance={rolloverBudget.groupBalance(group.id)}
+ show3Cols={show3Cols}
+ editMode={editMode}
+ onAddCategory={onAddCategory}
+ // onReorderCategory={onReorderCategory}
+ />
+
+ {group.categories.map((category, index) => {
+ const editing = editingId === category.id;
+ return (
+ <BudgetCategory
show3Cols={show3Cols}
+ key={category.id}
+ index={index}
+ category={category}
+ showBudgetedCol={showBudgetedCol}
+ editing={editing}
editMode={editMode}
- onAddCategory={onAddCategory}
- onReorderCategory={onReorderCategory}
+ // gestures={gestures}
+ month={month}
+ onEdit={onEditCategory}
+ // onReorder={onReorderCategory}
+ onBudgetAction={onBudgetAction}
/>
+ );
+ })}
+ </Card>,
+ );
+});
- {group.categories.map((category, index) => {
- // const editing = editingId === category.id;
- return (
- <BudgetCategory
- show3Cols={show3Cols}
- key={category.id}
- index={index}
- category={category}
- showBudgetedCol={showBudgetedCol}
- editing={undefined} //editing}
- editMode={editMode}
- //gestures={gestures}
- month={month}
- onEdit={onEditCategory}
- onReorder={onReorderCategory}
- onBudgetAction={onBudgetAction}
- />
- );
- })}
- </Card>,
- );
- } else {
- return null;
- }
- }
-}
+function IncomeBudgetGroup({ type, group }) {
+ return (
+ <View>
+ <View
+ style={{
+ flexDirection: 'row',
+ alignItems: 'center',
+ justifyContent: 'flex-end',
+ marginTop: 50,
+ marginBottom: 5,
+ marginRight: 14,
+ }}
+ >
+ {type === 'report' && <Label title="BUDGETED" style={{ width: 90 }} />}
+ <Label title="RECEIVED" style={{ width: 90 }} />
+ </View>
-class IncomeBudgetGroup extends Component {
- render() {
- const { type, group } = this.props;
- return (
- <View>
- <View
+ <Card style={{ marginTop: 0 }}>
+ <IncomeCategory
+ name={group.name}
+ budget={
+ type === 'report' ? reportBudget.groupBudgeted(group.id) : null
+ }
+ balance={
+ type === 'report'
+ ? reportBudget.groupSumAmount(group.id)
+ : rolloverBudget.groupSumAmount(group.id)
+ }
+ nameTextStyle={{ fontWeight: '500' }}
+ amountTextStyle={{ fontWeight: '500' }}
style={{
- flexDirection: 'row',
- alignItems: 'center',
- justifyContent: 'flex-end',
- marginTop: 50,
- marginBottom: 5,
- marginRight: 14,
+ backgroundColor: theme.altTableBackground,
}}
- >
- {type === 'report' && (
- <Label title="BUDGETED" style={{ width: 90 }} />
- )}
- <Label title="RECEIVED" style={{ width: 90 }} />
- </View>
-
- <Card style={{ marginTop: 0 }}>
- <IncomeCategory
- name={group.name}
- budget={
- type === 'report' ? reportBudget.groupBudgeted(group.id) : null
- }
- balance={
- type === 'report'
- ? reportBudget.groupSumAmount(group.id)
- : rolloverBudget.groupSumAmount(group.id)
- }
- nameTextStyle={{ fontWeight: '500' }}
- amountTextStyle={{ fontWeight: '500' }}
- style={{
- backgroundColor: theme.altTableBackground,
- }}
- />
+ />
- {group.categories.map((category, index) => {
- return (
- <IncomeCategory
- key={category.id}
- type={type}
- name={category.name}
- hidden={category.hidden}
- budget={
- type === 'report'
- ? reportBudget.catBudgeted(category.id)
- : null
- }
- balance={
- type === 'report'
- ? reportBudget.catSumAmount(category.id)
- : rolloverBudget.catSumAmount(category.id)
- }
- index={index}
- />
- );
- })}
- </Card>
- </View>
- );
- }
+ {group.categories.map((category, index) => {
+ return (
+ <IncomeCategory
+ key={category.id}
+ type={type}
+ name={category.name}
+ hidden={category.hidden}
+ budget={
+ type === 'report' ? reportBudget.catBudgeted(category.id) : null
+ }
+ balance={
+ type === 'report'
+ ? reportBudget.catSumAmount(category.id)
+ : rolloverBudget.catSumAmount(category.id)
+ }
+ index={index}
+ />
+ );
+ })}
+ </Card>
+ </View>
+ );
}
-class BudgetGroups extends Component {
- getGroups = memoizeOne(groups => {
+function BudgetGroups({
+ type,
+ categoryGroups,
+ editingId,
+ editMode,
+ gestures,
+ month,
+ onEditCategory,
+ onAddCategory,
+ onReorderCategory,
+ onReorderGroup,
+ onBudgetAction,
+ showBudgetedCol,
+ show3Cols,
+}) {
+ const getGroups = memoizeOne(groups => {
return {
incomeGroup: groups.find(group => group.is_income),
expenseGroups: groups.filter(group => !group.is_income),
};
});
- render() {
- const {
- type,
- categoryGroups,
- editingId,
- // editMode,
- gestures,
- month,
- onEditCategory,
- onAddCategory,
- onReorderCategory,
- onReorderGroup,
- onBudgetAction,
- showBudgetedCol,
- show3Cols,
- } = this.props;
- const { incomeGroup, expenseGroups } = this.getGroups(categoryGroups);
+ const { incomeGroup, expenseGroups } = getGroups(categoryGroups);
- return (
- <View
- data-testid="budget-groups"
- style={{ flex: '1 0 auto', overflowY: 'auto', paddingBottom: 15 }}
- >
- {expenseGroups.map(group => {
- return (
- <BudgetGroup
- key={group.id}
- group={group}
- editingId={editingId}
- showBudgetedCol={showBudgetedCol}
- editMode={undefined} //editMode}
- gestures={gestures}
- month={month}
- onEditCategory={onEditCategory}
- onAddCategory={onAddCategory}
- onReorderCategory={onReorderCategory}
- onReorderGroup={onReorderGroup}
- onBudgetAction={onBudgetAction}
- show3Cols={show3Cols}
- />
- );
- })}
+ return (
+ <View
+ data-testid="budget-groups"
+ style={{ flex: '1 0 auto', overflowY: 'auto', paddingBottom: 15 }}
+ >
+ {expenseGroups.map(group => {
+ return (
+ <BudgetGroup
+ key={group.id}
+ group={group}
+ editingId={editingId}
+ showBudgetedCol={showBudgetedCol}
+ editMode={editMode}
+ gestures={gestures}
+ month={month}
+ onEditCategory={onEditCategory}
+ onAddCategory={onAddCategory}
+ onReorderCategory={onReorderCategory}
+ onReorderGroup={onReorderGroup}
+ onBudgetAction={onBudgetAction}
+ show3Cols={show3Cols}
+ />
+ );
+ })}
- {incomeGroup && <IncomeBudgetGroup type={type} group={incomeGroup} />}
- </View>
- );
- }
+ {incomeGroup && <IncomeBudgetGroup type={type} group={incomeGroup} />}
+ </View>
+ );
}
export function BudgetTable(props) {
@@ -1018,25 +1018,24 @@ export function BudgetTable(props) {
// scrollRef,
// onScroll
// }) => (
- <>
- <View>
- <BudgetGroups
- categoryGroups={categoryGroups}
- showBudgetedCol={showBudgetedCol}
- show3Cols={show3Cols}
- editingId={editingCategory}
- editMode={editMode}
- // gestures={gestures}
- onEditCategory={() => {}} //onEditCategory}
- onAddCategory={onAddCategory}
- onReorderCategory={onReorderCategory}
- onReorderGroup={onReorderGroup}
- />
- </View>
+ <View>
+ <BudgetGroups
+ type={type}
+ categoryGroups={categoryGroups}
+ showBudgetedCol={showBudgetedCol}
+ show3Cols={show3Cols}
+ editingId={editingCategory}
+ editMode={editMode}
+ // gestures={gestures}
+ onEditCategory={onEditCategory}
+ onAddCategory={onAddCategory}
+ onReorderCategory={onReorderCategory}
+ onReorderGroup={onReorderGroup}
+ onBudgetAction={onBudgetAction}
+ />
+ </View>
- {/* <DragDropHighlight /> */}
- </>
- // )}
+ // <DragDropHighlight />
// </DragDrop>
)}
</View>
@@ -1045,6 +1044,8 @@ export function BudgetTable(props) {
);
}
+const BUDGET_HEADER_HEIGHT = 50;
+
function BudgetHeader({
currentMonth,
monthBounds,
@@ -1086,7 +1087,7 @@ function BudgetHeader({
alignItems: 'center',
flexDirection: 'row',
flexShrink: 0,
- height: 50,
+ height: BUDGET_HEADER_HEIGHT,
justifyContent: 'center',
backgroundColor: theme.buttonPrimaryBackground,
}}
diff --git a/packages/desktop-client/src/components/common/InputWithContent.tsx b/packages/desktop-client/src/components/common/InputWithContent.tsx
index 01c21a35a9..058c311613 100644
--- a/packages/desktop-client/src/components/common/InputWithContent.tsx
+++ b/packages/desktop-client/src/components/common/InputWithContent.tsx
@@ -22,7 +22,7 @@ export default function InputWithContent({
getStyle,
...props
}: InputWithContentProps) {
- let [focused, setFocused] = useState(false);
+ let [focused, setFocused] = useState(props.focused);
return (
<View
@@ -42,6 +42,7 @@ export default function InputWithContent({
{leftContent}
<Input
{...props}
+ focused={focused}
style={{
...inputStyle,
flex: 1,
diff --git a/packages/desktop-client/src/components/schedules/EditSchedule.js b/packages/desktop-client/src/components/schedules/EditSchedule.js
index 132362b606..68216988fc 100644
--- a/packages/desktop-client/src/components/schedules/EditSchedule.js
+++ b/packages/desktop-client/src/components/schedules/EditSchedule.js
@@ -510,7 +510,7 @@ export default function ScheduleDetails({ modalProps, actions, id }) {
) : (
<AmountInput
id="amount-field"
- defaultValue={state.fields.amount}
+ initialValue={state.fields.amount}
onChange={value =>
dispatch({
type: 'set-field',
diff --git a/packages/desktop-client/src/components/spreadsheet/CellValue.tsx b/packages/desktop-client/src/components/spreadsheet/CellValue.tsx
index 969003ba5a..2b7bc06bc3 100644
--- a/packages/desktop-client/src/components/spreadsheet/CellValue.tsx
+++ b/packages/desktop-client/src/components/spreadsheet/CellValue.tsx
@@ -1,4 +1,4 @@
-import React, { useMemo, type ReactNode } from 'react';
+import React, { type ReactNode } from 'react';
import { type CSSProperties, styles } from '../../style';
import Text from '../common/Text';
@@ -36,40 +36,28 @@ function CellValue({
let sheetValue = useSheetValue(binding);
let format = useFormat();
- return useMemo(
- () => (
- <ConditionalPrivacyFilter
- privacyFilter={
- privacyFilter != null
- ? privacyFilter
- : type === 'financial'
- ? true
- : undefined
- }
+ return (
+ <ConditionalPrivacyFilter
+ privacyFilter={
+ privacyFilter != null
+ ? privacyFilter
+ : type === 'financial'
+ ? true
+ : undefined
+ }
+ >
+ <Text
+ style={{
+ ...(type === 'financial' && styles.tnum),
+ ...style,
+ ...(getStyle && getStyle(sheetValue)),
+ }}
+ data-testid={testId || fullSheetName}
+ data-cellname={fullSheetName}
>
- <Text
- style={{
- ...(type === 'financial' && styles.tnum),
- ...style,
- ...(getStyle && getStyle(sheetValue)),
- }}
- data-testid={testId || fullSheetName}
- data-cellname={fullSheetName}
- >
- {formatter ? formatter(sheetValue) : format(sheetValue, type)}
- </Text>
- </ConditionalPrivacyFilter>
- ),
- [
- privacyFilter,
- type,
- style,
- getStyle,
- fullSheetName,
- formatter,
- format,
- sheetValue,
- ],
+ {formatter ? formatter(sheetValue) : format(sheetValue, type)}
+ </Text>
+ </ConditionalPrivacyFilter>
);
}
diff --git a/packages/desktop-client/src/components/util/AmountInput.js b/packages/desktop-client/src/components/util/AmountInput.js
index 4cfe9e222b..4dbb8941e0 100644
--- a/packages/desktop-client/src/components/util/AmountInput.js
+++ b/packages/desktop-client/src/components/util/AmountInput.js
@@ -1,8 +1,8 @@
-import React, { useState } from 'react';
+import React, { useRef, useState } from 'react';
import {
- integerToCurrency,
currencyToInteger,
+ integerToCurrency,
} from 'loot-core/src/shared/util';
import Add from '../../icons/v1/Add';
@@ -12,27 +12,60 @@ import Button from '../common/Button';
import InputWithContent from '../common/InputWithContent';
import View from '../common/View';
-export function AmountInput({ id, defaultValue = 0, onChange, style }) {
- let [negative, setNegative] = useState(defaultValue <= 0);
- let [value, setValue] = useState(integerToCurrency(Math.abs(defaultValue)));
+export function AmountInput({
+ id,
+ inputRef,
+ initialValue = 0,
+ onChange,
+ onEdit,
+ style,
+ textStyle,
+ focused,
+}) {
+ let [negative, setNegative] = useState(initialValue <= 0);
+ let initialValueAbsolute = integerToCurrency(Math.abs(initialValue || 0));
+ let [value, setValue] = useState(initialValueAbsolute);
+ let buttonRef = useRef();
function onSwitch() {
setNegative(!negative);
- fireChange(!negative);
+ fireChange(value, !negative);
+ }
+
+ function fireChange(val, neg) {
+ let valueOrInitial = Math.abs(
+ currencyToInteger(val ? val : initialValueAbsolute),
+ );
+ let amount = neg ? valueOrInitial * -1 : valueOrInitial;
+
+ onChange?.(amount);
}
- function fireChange(neg = negative) {
- let v = currencyToInteger(value);
- let amount = neg ? (v < 0 ? v : -v) : v > 0 ? v : -v;
+ function onInputAmountChange(value) {
+ setValue(value ? value : '');
+ }
- onChange(amount);
+ function onInputAmountBlur(e) {
+ fireChange(value, negative);
+ if (!buttonRef.current?.contains(e.relatedTarget)) {
+ onEdit?.(null);
+ }
}
return (
<InputWithContent
id={id}
+ inputRef={inputRef}
+ inputMode="decimal"
leftContent={
- <Button type="bare" style={{ padding: '0 7px' }} onClick={onSwitch}>
+ <Button
+ type="bare"
+ style={{ padding: '0 7px' }}
+ disabled={!focused}
+ onPointerUp={onSwitch}
+ onPointerDown={e => e.preventDefault()}
+ ref={buttonRef}
+ >
{negative ? (
<Subtract style={{ width: 8, height: 8, color: 'inherit' }} />
) : (
@@ -41,10 +74,16 @@ export function AmountInput({ id, defaultValue = 0, onChange, style }) {
</Button>
}
value={value}
+ focused={focused}
style={{ flex: 1, alignItems: 'stretch', ...style }}
- inputStyle={{ paddingLeft: 0 }}
- onChange={e => setValue(e.target.value)}
- onBlur={e => fireChange()}
+ inputStyle={{ paddingLeft: 0, ...textStyle }}
+ onKeyUp={e => {
+ if (e.key === 'Enter') {
+ fireChange(value, negative);
+ }
+ }}
+ onUpdate={onInputAmountChange}
+ onBlur={onInputAmountBlur}
/>
);
}
@@ -56,7 +95,7 @@ export function BetweenAmountInput({ defaultValue, onChange }) {
return (
<View style={{ flexDirection: 'row', alignItems: 'center' }}>
<AmountInput
- defaultValue={num1}
+ initialValue={num1}
onChange={value => {
setNum1(value);
onChange({ num1: value, num2 });
@@ -65,7 +104,7 @@ export function BetweenAmountInput({ defaultValue, onChange }) {
/>
<View style={{ margin: '0 5px' }}>and</View>
<AmountInput
- defaultValue={num2}
+ initialValue={num2}
onChange={value => {
setNum2(value);
onChange({ num1, num2: value });
diff --git a/upcoming-release-notes/1662.md b/upcoming-release-notes/1662.md
new file mode 100644
index 0000000000..4800358b66
--- /dev/null
+++ b/upcoming-release-notes/1662.md
@@ -0,0 +1,5 @@
+---
+category: Enhancements
+authors: [joel-jeremy, dmlazaro]
+---
+Editable mobile budget cells