PrompterPage.js 2.45 KB
import React, { Fragment } from 'react';
import axios from 'axios'
import {
  GlobalStyles,
  StyledApp,
  StyledTeleprompter as Teleprompter,
  Controls,
  Buttons,
  Button,
} from "../styles";
// 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',
//     },
//   });

// const INITIAL_TEXT = ``;

function PrompterPage() {
  const [listening, setListening] = React.useState(false);
  const [words, setWords] = React.useState("".split(" "));
  // const [words, setWords] = React.useState("");
  const [progress, setProgress] = React.useState(0);

  // Serverλ‘œλΆ€ν„° Script λ°›μ•„μ˜΄
  axios.get("api/script")
    .then(res => {      // .then : 응닡(μƒνƒœμ½”λ“œ200~300미만)μ„±κ³΅μ‹œ
      console.log(res.data);
      setWords(res.data.split(" ")); // λ°›μ•„μ˜¨ Script λ¬Έμžμ—΄ 처리
    })
    .catch(error => {
      console.log(error);
    });


  // const handleInput = (e) => {
  //   setWords(e.target.value.split(" "));
  //   progress && setProgress(0);
  // };

  const handleListening = () => {
    if (listening) {
      setListening(false);
    } else {
      setProgress(0);
      setListening(true);
    }
  };

  const handleReset = () => setProgress(0);

  const handleChange = (progress) => setProgress(progress);

  return (
    <>
      <GlobalStyles />
      <StyledApp>
        <Controls>
          <Buttons>
            <Button onClick={handleListening}>{listening ? "Stop" : "Start"}</Button>
            <Button onClick={handleReset} disabled={listening} secondary>Reset</Button>
          </Buttons>
        </Controls>
        <Teleprompter words={words} listening={listening} progress={progress} onChange={handleChange} />
      </StyledApp>
    </>
  );
}

export default PrompterPage;