From 0d760f23fb26356bdea822ada95ce6bb18623b1f Mon Sep 17 00:00:00 2001 From: Matthew Lean Date: Mon, 25 May 2020 14:58:28 -0700 Subject: [PATCH 01/29] Separate calcState and statsState --- src/components/Panel.jsx | 7 +++---- src/scripts/calc.js | 1 - src/scripts/draw.js | 4 ++-- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/components/Panel.jsx b/src/components/Panel.jsx index 5229c53..e351702 100644 --- a/src/components/Panel.jsx +++ b/src/components/Panel.jsx @@ -50,7 +50,6 @@ const Panel = ({ selectionAmount, validSelection }) => { cols, colWidth, floorVals, - gridHeight, gutterWidth, topMargin, rightMargin, @@ -144,7 +143,7 @@ const Panel = ({ selectionAmount, validSelection }) => { // Calculate grid height const calcGridHeightResult = calcGridHeight(calcState) - setGridHeight(calcState.gridHeight) + setGridHeight(calcGridHeightResult.gridHeight) setTopBottomMarginsSum(calcGridHeightResult.topBottomMarginsSum) setIsCalcReady(true) } @@ -198,7 +197,7 @@ const Panel = ({ selectionAmount, validSelection }) => { // Calculate grid height const calcGridHeightResult = calcGridHeight(calcState) - setGridHeight(calcState.gridHeight) + setGridHeight(calcGridHeightResult.gridHeight) setTopBottomMarginsSum(calcGridHeightResult.topBottomMarginsSum) setIsCalcReady(true) } @@ -540,7 +539,7 @@ const Panel = ({ selectionAmount, validSelection }) => { id="create" onClick={() => { if (isCalcReady) { - draw(calcState, { drawFields, drawGridlines }) + draw(calcState, { gridHeight }, { drawFields, drawGridlines }) } }} disabled={!isCalcReady || (!drawFields && !drawGridlines)} diff --git a/src/scripts/calc.js b/src/scripts/calc.js index 656f532..1f313b9 100644 --- a/src/scripts/calc.js +++ b/src/scripts/calc.js @@ -261,7 +261,6 @@ const calcGridHeight = (calcState, currResult = { errs: [] }) => { currResult.topBottomMarginsSum = calcState.topMargin + calcState.bottomMargin currResult.gridHeight = canvasHeight - currResult.topBottomMarginsSum - calcState.gridHeight = currResult.gridHeight return currResult } diff --git a/src/scripts/draw.js b/src/scripts/draw.js index edd96b5..87c85d5 100644 --- a/src/scripts/draw.js +++ b/src/scripts/draw.js @@ -7,7 +7,7 @@ const { group } = require('commands') * @param {Object} calcState State for calculations. Should be validated beforehand. * @param {Object} drawOptions Options to control what should be drawn */ -const draw = (calcState, drawOptions) => { +const draw = (calcState, statsState, drawOptions) => { editDocument((selection) => { const currSelection = selection.items[0] const { @@ -15,11 +15,11 @@ const draw = (calcState, drawOptions) => { canvasHeight, cols, colWidth, - gridHeight, gutterWidth, topMargin, leftMargin, } = calcState + const { gridHeight } = statsState const { drawFields, drawGridlines } = drawOptions const newItems = [] const colFills = [] From 80899530a898ba6574011ce7ecc7bf1b7e091d50 Mon Sep 17 00:00:00 2001 From: Matthew Lean Date: Mon, 25 May 2020 15:09:36 -0700 Subject: [PATCH 02/29] Add create columns flag --- src/components/Panel.jsx | 21 +++++++++++++++++---- src/style.css | 4 ++++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/components/Panel.jsx b/src/components/Panel.jsx index e351702..16b3805 100644 --- a/src/components/Panel.jsx +++ b/src/components/Panel.jsx @@ -24,6 +24,8 @@ const Panel = ({ selectionAmount, validSelection }) => { const [boundType, setBoundType] = useState('path') const [canvasWidth, setCanvasWidth] = useState('') const [canvasHeight, setCanvasHeight] = useState('') + + const [createCols, setCreateCols] = useState(true) const [cols, setCols] = useState('') const [gutterWidth, setGutterWidth] = useState(0) const [colWidth, setColWidth] = useState('') @@ -338,7 +340,6 @@ const Panel = ({ selectionAmount, validSelection }) => { -
+
+ -