From 21461645ccc33bff318d2d0b4bb707b0f90e9daf Mon Sep 17 00:00:00 2001 From: Michael Shanks Date: Thu, 20 Feb 2020 17:08:17 +0000 Subject: [PATCH] store method for save page or screen (context dependant) --- packages/builder/src/builderStore/store.js | 29 +++++++++------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/packages/builder/src/builderStore/store.js b/packages/builder/src/builderStore/store.js index 3cb400c4de..766dac3f06 100644 --- a/packages/builder/src/builderStore/store.js +++ b/packages/builder/src/builderStore/store.js @@ -749,7 +749,7 @@ const addTemplatedComponent = store => props => { props ) - _savePage(state) + _saveCurrentPreviewItem(state) return state }) @@ -792,9 +792,7 @@ const setComponentStyle = store => (type, name, value) => { ]) // save without messing with the store - s.currentFrontEndType === "page" - ? _savePage(s) - : _saveScreenApi(s.currentPreviewItem, s) + _saveCurrentPreviewItem(s) return s }) } @@ -843,9 +841,7 @@ const deleteComponent = store => component => { parent._children = parent._children.filter(c => c !== component) } - s.currentFrontEndType === "page" - ? _savePage(s) - : _saveScreenApi(s.currentPreviewItem, s) + _saveCurrentPreviewItem(s) return s }) @@ -864,9 +860,7 @@ const moveUpComponent = store => component => { parent._children = newChildren } s.currentComponentInfo = component - s.currentFrontEndType === "page" - ? _savePage(s) - : _saveScreenApi(s.currentPreviewItem, s) + _saveCurrentPreviewItem(s) return s }) @@ -885,9 +879,7 @@ const moveDownComponent = store => component => { parent._children = newChildren } s.currentComponentInfo = component - s.currentFrontEndType === "page" - ? _savePage(s) - : _saveScreenApi(s.currentPreviewItem, s) + _saveCurrentPreviewItem(s) return s }) @@ -902,9 +894,7 @@ const copyComponent = store => component => { }) parent._children = [...parent._children, copiedComponent] s.curren - s.currentFrontEndType === "page" - ? _savePage(s) - : _saveScreenApi(s.currentPreviewItem, s) + _saveCurrentPreviewItem(s) s.currentComponentInfo = copiedComponent return s }) @@ -913,7 +903,7 @@ const copyComponent = store => component => { const getParent = (rootProps, child) => { let parent walkProps(rootProps, (p, breakWalk) => { - if (p._children.includes(child)) { + if (p._children && p._children.includes(child)) { parent = p breakWalk() } @@ -934,3 +924,8 @@ const walkProps = (props, action, cancelToken = null) => { } } } + +const _saveCurrentPreviewItem = s => + s.currentFrontEndType === "page" + ? _savePage(s) + : _saveScreenApi(s.currentPreviewItem, s)