From 1d772fb605333b2e168233897bfe7b88dc48336f Mon Sep 17 00:00:00 2001 From: Gurkirpal Singh <12171804+gpalsingh@users.noreply.github.com> Date: Fri, 1 Sep 2023 02:30:02 +0530 Subject: [PATCH 1/2] fix: Component not updating while typing --- src/components/AddComponent.js | 10 ++++++++++ src/redux/reducers/appDataReducers.js | 8 ++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/components/AddComponent.js b/src/components/AddComponent.js index e0ef1da8..40a3e9c0 100644 --- a/src/components/AddComponent.js +++ b/src/components/AddComponent.js @@ -167,8 +167,18 @@ class AddComponent extends React.Component { } } + debouncedSave = _.debounce((id, e, emitOnly = false) => { + this.props.updateComponent({id, newState: {content: e.target.innerHTML}, emitOnly}); + }, 300); + handleInput = (e) => { + e.persist(); this.setState({ showActionBtn: e.target.innerHTML === '' && !e.target.value }) + + // Same as onBlur + if(this.props.data.componentType !== 'Embed') { + this.debouncedSave(this.props.id, e, true) + } } // handles the focus and set the cursor to right position. diff --git a/src/redux/reducers/appDataReducers.js b/src/redux/reducers/appDataReducers.js index b5e5856e..470af2ab 100644 --- a/src/redux/reducers/appDataReducers.js +++ b/src/redux/reducers/appDataReducers.js @@ -236,9 +236,9 @@ function updateComponentTypeState(state, data) { } function updateComponentState(state, data) { - let { componentData } = state; - let { newState, id } = data; - componentData = componentData.map((component) => { + const { componentData } = state; + let { newState, id, emitOnly } = data; + const newComponentData = componentData.map((component) => { if (component.id === id) { return { ...component, @@ -250,7 +250,7 @@ function updateComponentState(state, data) { } }); emitUpdate({ id, ...newState }, "update"); - return { componentData }; + return emitOnly ? state : { componentData: newComponentData}; } function removeComponentFromState(state, data) { From 58cbfe8c580e45b33cf16bde1a7fb18f51832eaf Mon Sep 17 00:00:00 2001 From: Gurkirpal Singh <12171804+gpalsingh@users.noreply.github.com> Date: Fri, 1 Sep 2023 02:31:29 +0530 Subject: [PATCH 2/2] chore: Version bump --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 5fdb7d27..670b7831 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@commutatus/cm-page-builder", - "version": "2.1.0", + "version": "2.1.1", "description": "Page builder package like notion", "main": "lib/page/index.js", "files": [