From 952136039bd495dfc4d3797d3b3c07413c52c21a Mon Sep 17 00:00:00 2001 From: Joel Jeremy Marquez Date: Thu, 7 Sep 2023 22:06:50 -0700 Subject: [PATCH] Functional mobile components --- .../components/budget/MobileBudgetTable.js | 918 +++++++++--------- 1 file changed, 442 insertions(+), 476 deletions(-) diff --git a/packages/desktop-client/src/components/budget/MobileBudgetTable.js b/packages/desktop-client/src/components/budget/MobileBudgetTable.js index 758fb9355b8..4016d961976 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, PureComponent, useState } from 'react'; +import React, { memo, useState } from 'react'; // import { // RectButton, // PanGestureHandler, @@ -93,19 +93,17 @@ function Saved({ projected }) { ); } -function BudgetCell(props) { - const { - name, - binding, - editing, - style, - textStyle, - categoryId, - month, - onBudgetAction, - onEdit, - } = props; - +function BudgetCell({ + name, + binding, + editing, + style, + textStyle, + categoryId, + month, + onBudgetAction, + onEdit, +}) { let sheetValue = useSheetValue(binding); function updateBudgetAmount(amount) { @@ -235,308 +233,279 @@ 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, +}) { + // let opacity = new Animated.Value(editMode || blank ? 0 : 1); + let opacity = editMode || blank ? 0 : 1; - let { editMode, blank } = props; - // this.opacity = new Animated.Value(editMode || blank ? 0 : 1); - this.opacity = editMode || blank ? 0 : 1; - } + // useEffect(() => { + // if (editing && ACTScrollViewManager) { + // ACTScrollViewManager.setFocused(findNodeHandle(container.current)); + // } + // }, [editing]); - // componentDidUpdate(prevProps) { - // if (prevProps.editing !== this.props.editing) { - // if (this.props.editing && ACTScrollViewManager) { - // ACTScrollViewManager.setFocused(findNodeHandle(this.container)); - // } - // } + // useEffect(() => { + // Animated.timing(this.opacity, { + // toValue: this.props.editMode ? 0 : 1, + // duration: 200, + // easing: Easing.inOut(Easing.ease), + // }).start(); + // }, [editMode]); - // if (prevProps.editMode !== this.props.editMode) { - // Animated.timing(this.opacity, { - // toValue: this.props.editMode ? 0 : 1, - // duration: 200, - // easing: Easing.inOut(Easing.ease) - // }).start(); - // } - // } + let budgeted = rolloverBudget.catBudgeted(category.id); + let balance = rolloverBudget.catBalance(category.id); - render() { - let { - category, - editing, - index, - // gestures, - // editMode, - style, - month, - onEdit, - onBudgetAction, - } = this.props; - - let budgeted = rolloverBudget.catBudgeted(category.id); - let balance = rolloverBudget.catBalance(category.id); - - let content = !category.hidden && ( - (this.container = el)} + let content = !category.hidden && ( + (container.current = el)} + style={{ + backgroundColor: editing ? colors.p11 : 'transparent', + borderBottomWidth: 0, + borderTopWidth: index > 0 ? 1 : 0, + ...style, + }} + data-testid="row" + > + + + {category.name} + + + {/* 0 ? 1 : 0, - ...style, + flexDirection: 'row', + alignItems: 'center', + opacity: opacity + }} + > */} + - - - {category.name} - - - {/* */} - + - - value < 0 && { color: colors.r4 }} - type="financial" - /> - - {/* */} - - ); - - return {content}; - - // ( - // - // )} - // gestures={gestures} - // > - // { - // 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} - // - // - } -} - -class TotalsRow extends PureComponent { - constructor(props) { - super(props); - - let { editMode, blank } = props; - // this.animation = new Animated.Value(editMode || blank ? 0 : 1); - this.opacity = editMode || blank ? 0 : 1; - } + getStyle={value => value < 0 && { color: colors.r4 }} + type="financial" + /> + + {/* */} + + ); - // 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(); + 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 + // } + // }) // } - // } - - render() { - let { group, editMode, onAddCategory } = this.props; - - let content = ( - + // {() => content} + // + // +}); + +const TotalsRow = memo(function TotalsRow({ + group, + editMode, + blank, + onAddCategory, +}) { + // useEffect(() => { + // Animated.timing(this.animation, { + // toValue: this.props.editMode ? 0 : 1, + // duration: 200, + // easing: Easing.inOut(Easing.ease), + // }).start(); + // }, [editMode]); + + // let animation = new Animated.Value(editMode || blank ? 0 : 1); + let opacity = editMode || blank ? 0 : 1; + + let content = ( + + + + {group.name} + + + {/* */} + - - - {group.name} - - - {/* */} - + - - + type="financial" + /> + + {/* */} + + {editMode && ( + // + + - {/* */} - - {editMode && ( - // - - - - // - )} - - ); - - if (!editMode) { - return content; - } + // + )} + + ); + if (!editMode) { return content; - // { - // return 'bottom'; - // }} - // onDrop={(id, type, droppable, status) => - // this.props.onReorderCategory(id, { inGroup: group.id }) - // } - // > - // {() => content} - // } -} -class IncomeCategory extends PureComponent { - render() { - const { - name, - budget, - hidden, - balance, - style, - nameTextStyle, - amountTextStyle, - } = this.props; - if (hidden) { - return null; - } - return ( - - - - {name} - - - {budget && ( - - )} + return content; + // { + // return 'bottom'; + // }} + // onDrop={(id, type, droppable, status) => + // props.onReorderCategory(id, { inGroup: group.id }) + // } + // > + // {() => content} + // +}); + +const IncomeCategory = memo(function IncomeCategory({ + name, + budget, + hidden, + balance, + style, + nameTextStyle, + amountTextStyle, +}) { + if (hidden) { + return null; + } + return ( + + + + {name} + + + {budget && ( - - ); - } -} + )} + + + ); +}); // export function BudgetAccessoryView() { // let emitter = useContext(AmountAccessoryContext); @@ -589,206 +568,193 @@ class IncomeCategory extends PureComponent { // ); // } -class BudgetGroup extends PureComponent { - render() { - const { - group, - editingId, - editMode, - // gestures, - month, - onEditCategory, - // onReorderCategory, - // onReorderGroup, - onAddCategory, - onBudgetAction, - } = this.props; - - function editable(content) { - if (!editMode) { - return content; - } - +const BudgetGroup = memo(function BudgetGroup({ + group, + editingId, + editMode, + // gestures, + month, + onEditCategory, + // onReorderCategory, + // onReorderGroup, + onAddCategory, + onBudgetAction, +}) { + function editable(content) { + if (!editMode) { 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} - // - // } - if (!group.hidden) { - return editable( - - - {group.categories.map((category, index) => { - const editing = editingId === category.id; - return ( - - ); - })} - , - ); - } else { - return null; - } + 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} + // + // } -} -class IncomeBudgetGroup extends Component { - render() { - const { type, group } = this.props; - return ( - - - {type === 'report' && ( - + if (group.hidden) { + return null; + } + + return editable( + + - - { + const editing = editingId === category.id; + return ( + + ); + })} + , + ); +}); - {group.categories.map((category, index) => { - return ( - +function IncomeBudgetGroup({ type, group }) { + return ( + + + {type === 'report' && - ); - } + + + + + {group.categories.map((category, index) => { + return ( + + + ); } -class BudgetGroups extends Component { - getGroups = memoizeOne(groups => { +function BudgetGroups({ + type, + categoryGroups, + editingId, + editMode, + gestures, + month, + onEditCategory, + onAddCategory, + onReorderCategory, + onReorderGroup, + onBudgetAction, +}) { + 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, - } = this.props; - const { incomeGroup, expenseGroups } = this.getGroups(categoryGroups); - - return ( - - {expenseGroups.map(group => { - return ( - - ); - })} + const { incomeGroup, expenseGroups } = getGroups(categoryGroups); - {incomeGroup && } - - ); - } + return ( + + {expenseGroups.map(group => { + return ( + + ); + })} + + {incomeGroup && } + + ); } export function BudgetTable(props) {