You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
1.0 KiB
54 lines
1.0 KiB
import React, { Component } from 'react'; |
|
import { withRouter } from 'react-router-dom'; |
|
|
|
class Submit extends Component { |
|
constructor(props) { |
|
super(props); |
|
|
|
this.state = { |
|
progress: null, |
|
}; |
|
|
|
this.inputRef = React.createRef(); |
|
} |
|
|
|
submitArticle = (event) => { |
|
event.preventDefault(); |
|
const url = event.target[0].value; |
|
this.inputRef.current.blur(); |
|
|
|
this.setState({ progress: 'Submitting...' }); |
|
|
|
let data = new FormData(); |
|
data.append('url', url); |
|
|
|
fetch('/api/submit', { method: 'POST', body: data }) |
|
.then(res => res.json()) |
|
.then( |
|
(result) => { |
|
this.props.history.replace('/' + result.nid); |
|
}, |
|
(error) => { |
|
this.setState({ progress: 'Error' }); |
|
} |
|
); |
|
} |
|
|
|
render() { |
|
const progress = this.state.progress; |
|
|
|
return ( |
|
<span className='search'> |
|
<form onSubmit={this.submitArticle}> |
|
<input |
|
placeholder='Submit URL' |
|
ref={this.inputRef} |
|
/> |
|
</form> |
|
{progress ? progress : ''} |
|
</span> |
|
); |
|
} |
|
} |
|
|
|
export default withRouter(Submit);
|
|
|