-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathSubmitButton.js
68 lines (56 loc) · 1.99 KB
/
SubmitButton.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import React,{Component} from 'react'
import { Button, Modal, ModalHeader, ModalBody, ModalFooter } from 'reactstrap'
class SubmitCodeButton extends Component {
constructor(props){
super(props);
this.state = {
showConfirmation: false,
}
this.submitCode = this.submitCode.bind(this);
this.toggleConfirmation = this.toggleConfirmation.bind(this);
}
toggleConfirmation(){
this.setState(prevState => ({
showConfirmation: !prevState.showConfirmation
}))
}
submitCode(event) {
event.preventDefault()
this.toggleConfirmation()
const codeText = this.props.editor.getValue()
const codeLanguage = this.props.language.toLowerCase()
var data = {
content: codeText,
language: codeLanguage,
customInput: false,
stdin: '',
submit: true
}
if(this.props.customFunction === undefined){
console.error('No Submit Function is defined for the TextIDE Component')
}
else {
this.props.customFunction(data)
}
}
render(){
return (
<div>
<Button className="btn btn-success" onClick= {this.toggleConfirmation} >
Submit
</Button>
<Modal isOpen={this.state.showConfirmation} toggle={this.toggleConfirmation}>
<ModalHeader toggle={this.toggleConfirmation}>Confirm to Submit</ModalHeader>
<ModalBody>
Are you sure you want to submit?
</ModalBody>
<ModalFooter>
<Button color="primary" onClick={this.submitCode}>Submit</Button>
<Button color="secondary" onClick={this.toggleConfirmation}>Cancel</Button>
</ModalFooter>
</Modal>
</div>
)
}
}
export default SubmitCodeButton;