mirror of
https://github.com/ilyakooo0/urbit.git
synced 2024-12-01 11:33:41 +03:00
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:
parent
45b61f90e1
commit
b86d6006a0
@ -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() {
|
||||
|
Loading…
Reference in New Issue
Block a user