From 4c1fb9362533e4b1269ca71a93c8f6918e77fe45 Mon Sep 17 00:00:00 2001 From: Crazypkr Date: Wed, 6 Sep 2023 17:10:56 -0400 Subject: [PATCH] Responsive support for < 365px mobile screens --- .../components/budget/MobileBudgetTable.js | 68 +++++++++++++++++-- 1 file changed, 63 insertions(+), 5 deletions(-) diff --git a/packages/desktop-client/src/components/budget/MobileBudgetTable.js b/packages/desktop-client/src/components/budget/MobileBudgetTable.js index bb95540b996..f3d7da30cb1 100644 --- a/packages/desktop-client/src/components/budget/MobileBudgetTable.js +++ b/packages/desktop-client/src/components/budget/MobileBudgetTable.js @@ -1,4 +1,10 @@ -import React, { Component, memo, PureComponent, useState } from 'react'; +import React, { + Component, + memo, + PureComponent, + useState, + useEffect, +} from 'react'; // import { // RectButton, // PanGestureHandler, @@ -37,8 +43,6 @@ import { AmountInput } from '../util/AmountInput'; // import { DragDrop, Draggable, Droppable, DragDropHighlight } from './dragdrop'; import { ListItem, ROW_HEIGHT } from './MobileTable'; -const smallVPWidth = document.documentElement.clientWidth < 365; - function ToBudget({ toBudget, onClick }) { let amount = useSheetValue(toBudget); let format = useFormat(); @@ -247,6 +251,10 @@ class BudgetCategory extends PureComponent { let { editMode, blank } = props; // this.opacity = new Animated.Value(editMode || blank ? 0 : 1); this.opacity = editMode || blank ? 0 : 1; + + this.state = { + smallVPWidth: window.innerWidth < 365, + }; } // componentDidUpdate(prevProps) { @@ -264,6 +272,20 @@ class BudgetCategory extends PureComponent { // }).start(); // } // } + componentDidMount() { + // Add event listener for window resize + window.addEventListener('resize', this.handleResize); + } + + componentWillUnmount() { + // Remove the event listener when the component unmounts + window.removeEventListener('resize', this.handleResize); + } + handleResize = () => { + this.setState({ + smallVPWidth: window.innerWidth < 365, + }); + }; render() { let { @@ -282,6 +304,8 @@ class BudgetCategory extends PureComponent { let balance = rolloverBudget.catBalance(category.id); let spent = rolloverBudget.catSumAmount(category.id); + const { smallVPWidth } = this.state; + let content = !category.hidden && ( (this.container = el)} @@ -391,6 +415,10 @@ class TotalsRow extends PureComponent { let { editMode, blank } = props; // this.animation = new Animated.Value(editMode || blank ? 0 : 1); this.opacity = editMode || blank ? 0 : 1; + + this.state = { + smallVPWidth: window.innerWidth < 365, + }; } // componentDidUpdate(prevProps) { @@ -403,9 +431,24 @@ class TotalsRow extends PureComponent { // } // } + componentDidMount() { + // Add event listener for window resize + window.addEventListener('resize', this.handleResize); + } + + componentWillUnmount() { + // Remove the event listener when the component unmounts + window.removeEventListener('resize', this.handleResize); + } + handleResize = () => { + this.setState({ + smallVPWidth: window.innerWidth < 365, + }); + }; + render() { let { group, editMode, onAddCategory } = this.props; - + const { smallVPWidth } = this.state; let content = ( { + const handleResize = () => { + if (window.innerWidth < 365) { + setSmallVPWidth(true); + } else { + setSmallVPWidth(false); + } + }; + + window.addEventListener('resize', handleResize); + + return () => { + window.removeEventListener('resize', handleResize); + }; + }, []); const { type,