Skip to content

Commit

Permalink
Merge pull request #12 from commutatus/fix-save
Browse files Browse the repository at this point in the history
fix: Component not updating while typing
  • Loading branch information
gpalsingh authored Sep 1, 2023
2 parents 9cddc13 + 58cbfe8 commit 7eb3912
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": [
Expand Down
10 changes: 10 additions & 0 deletions src/components/AddComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions src/redux/reducers/appDataReducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -250,7 +250,7 @@ function updateComponentState(state, data) {
}
});
emitUpdate({ id, ...newState }, "update");
return { componentData };
return emitOnly ? state : { componentData: newComponentData};
}

function removeComponentFromState(state, data) {
Expand Down

0 comments on commit 7eb3912

Please sign in to comment.