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.
This commit is contained in:
Matilde Park 2020-03-18 18:42:42 -04:00
parent 45b61f90e1
commit b86d6006a0

View File

@ -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() {