From b86d6006a053cdb55852e29e9e251231218fc57e Mon Sep 17 00:00:00 2001 From: Matilde Park Date: Wed, 18 Mar 2020 18:42:42 -0400 Subject: [PATCH] publish: prevent submission of empty notes The onclick would fire regardless of disabled attr. This commit adds a conditional check to the onclick's function. --- .../publish/src/js/components/lib/new-post.js | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/pkg/interface/publish/src/js/components/lib/new-post.js b/pkg/interface/publish/src/js/components/lib/new-post.js index d71a21753..d9aed3506 100644 --- a/pkg/interface/publish/src/js/components/lib/new-post.js +++ b/pkg/interface/publish/src/js/components/lib/new-post.js @@ -23,28 +23,31 @@ export class NewPost extends Component { } postSubmit() { - let newNote = { - "new-note": { - who: this.props.ship.slice(1), - book: this.props.book, - note: stringToSymbol(this.state.title), - title: this.state.title, - body: this.state.body, + const { state, props } = this; + if (state.submit && !state.disabled) { + let newNote = { + "new-note": { + who: this.props.ship.slice(1), + book: this.props.book, + note: stringToSymbol(this.state.title), + title: this.state.title, + body: this.state.body, + } } - } window.api.setSpinner(true); this.setState({ disabled: true }); - window.api.action("publish", "publish-action", newNote).then(() =>{ + window.api.action("publish", "publish-action", newNote).then(() => { this.setState({ awaiting: newNote["new-note"].note, disabled: false }); }).catch((err) => { if (err.includes("note already exists")) { let timestamp = Math.floor(Date.now() / 1000); newNote["new-note"].note += "-" + timestamp; - this.setState({awaiting: newNote["new-note"].note, disabled: false}); + this.setState({ awaiting: newNote["new-note"].note, disabled: false }); window.api.action("publish", "publish-action", newNote); } }); + } } componentWillMount() {