PrompterPage.js
1.7 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
import React, { Fragment, useEffect } from 'react';
import axios from 'axios'
import { withStyles, Button} from '@material-ui/core';
import {
GlobalStyles,
StyledApp,
StyledTeleprompter as Teleprompter,
} from "../styles";
const styles = theme => ({
button: {
fontSize: '1.2rem',
},
});
function PrompterPage({match}) {
const classes = styles();
const [listening, setListening] = React.useState(false);
const [words, setWords] = React.useState("".split(" "));
const [progress, setProgress] = React.useState(0);
// Serverλ‘λΆν° Script λ°μμ΄
useEffect(() => {
axios.get('api/script')
.then(res => { // .then : μλ΅(μνμ½λ200~300λ―Έλ§)μ±κ³΅μ
console.log(res.data);
setWords(res.data.split(" ")); // λ°μμ¨ Script λ¬Έμμ΄ μ²λ¦¬
})
.catch(error => {
console.log(error);
});
}, [match.params]);
const handleListening = () => {
if (listening) {
setListening(false);
} else {
setProgress(0);
setListening(true);
}
};
const handleReset = () => setProgress(0);
const handleChange = (progress) => setProgress(progress);
return (
<>
<Button className={classes.button} variant="contained" color="primary" size="medium" onClick={handleListening}>{listening ? "Stop" : "Start"}</Button>
<Button className={classes.button} variant="contained" color="secondary" size="medium" disabled={listening} onClick={handleReset}>Reset</Button>
<GlobalStyles />
<StyledApp>
<Teleprompter words={words} listening={listening} progress={progress} onChange={handleChange} />
</StyledApp>
</>
);
}
export default withStyles(styles)(PrompterPage);