MainPage.js
2.59 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import React, { Component, Fragment } from 'react';
import { post } from 'axios';
import { withStyles, Typography, Paper, Button, TextField } from '@material-ui/core';
const styles = theme => ({
root: {
'& .MuiTextField-root': {
margin: theme.spacing(1),
width: '100%',
minWidth: 1080
},
},
title: {
marginTop: theme.spacing.unit * 5,
textAlign: 'center',
display: 'none',
fontSize: '2.0rem',
[theme.breakpoints.up('sm')]: {
display: 'block',
}
},
paper: {
marginTop: theme.spacing.unit * 5,
marginLeft: theme.spacing.unit * 20,
marginRight: theme.spacing.unit * 20
},
button: {
marginTop: theme.spacing.unit * 1,
marginLeft: theme.spacing.unit * 20,
fontSize: '1rem',
},
});
class MainPage extends Component {
constructor(props) {
super(props);
this.state = {
script: ''
}
}
stateRefresh = () => {
this.setState({
script: '',
});
this.callApi()
.then(res => this.setState({script: res}))
.catch(err => console.log(err));
}
callApi = async () => {
const response = await fetch('/api/script');
const body = await response.json();
return body;
}
// Get Script
getScript = (e) => {
this.script = e.target.value;
}
// Execute addScript() && Move Next URL
handleScriptSubmit = (e) => {
e.preventDefault()
this.addScript()
.then((response) => {
console.log(response.data);
this.stateRefresh();
})
this.setState({
script: ''
})
this.props.history.push('/prompter');
}
// Send script to Server
addScript = () => {
const url = `/api/this.props.script`;
let scriptJSON = { script : this.script };
const config = {
headers: {
'content-type': 'application/json'
}
}
return post(url, JSON.stringify(scriptJSON), config);
}
render() {
const { classes } = this.props;
return (
<Fragment>
<Typography className={classes.title} variant="h6" color="inherit" noWrap>μμ±μ λ§μΆ° λλ³Έμ νλ©΄μ μ€μκ°μΌλ‘ μΆλ ₯νλ ν둬νν° μλΉμ€</Typography>
<Paper className={classes.paper} elevation={3}>
<TextField id="outlined-textarea" label="Scriptλ₯Ό μ
λ ₯ν΄μ£ΌμΈμ." fullWidth="true" rows={20} placeholder="Script" multiline variant="outlined" onChange={this.getScript} />
</Paper>
<Button className={classes.button} variant="contained" color="primary" size="medium" onClick={this.handleScriptSubmit}>μμν©λλ€.</Button>
</Fragment>
);
}
}
export default withStyles(styles)(MainPage);