DongyoungKwon

Complete Project for Local Server

...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
15 15
16 ```bash 16 ```bash
17 Teleprompter-SST 17 Teleprompter-SST
18 -β”œβ”€β”€ client ---> Front-end 18 +β”œβ”€β”€ client ---> Front-end [React]
19 β”‚ β”œβ”€β”€ public ---> 정적 파일 보관 19 β”‚ β”œβ”€β”€ public ---> 정적 파일 보관
20 β”‚ β”‚ β”œβ”€β”€ favicon.ico 20 β”‚ β”‚ β”œβ”€β”€ favicon.ico
21 β”‚ β”‚ β”œβ”€β”€ index.html 21 β”‚ β”‚ β”œβ”€β”€ index.html
...@@ -46,7 +46,7 @@ Teleprompter-SST ...@@ -46,7 +46,7 @@ Teleprompter-SST
46 β”œβ”€β”€ package-lock.json 46 β”œβ”€β”€ package-lock.json
47 β”œβ”€β”€ package.json 47 β”œβ”€β”€ package.json
48 β”œβ”€β”€ README.md 48 β”œβ”€β”€ README.md
49 -β”œβ”€β”€ server.js ---> Back-end 49 +β”œβ”€β”€ server.js ---> Back-end [Node Express]
50 └── yarn.lock 50 └── yarn.lock
51 ``` 51 ```
52 52
......
...@@ -2,15 +2,14 @@ import React, { Component } from 'react'; ...@@ -2,15 +2,14 @@ import React, { Component } from 'react';
2 import { Route } from 'react-router-dom'; 2 import { Route } from 'react-router-dom';
3 import MainPage from './pages/MainPage'; 3 import MainPage from './pages/MainPage';
4 import PrompterPage from './pages/PrompterPage'; 4 import PrompterPage from './pages/PrompterPage';
5 -// import test from './pages/test';
6 5
7 class App extends Component { 6 class App extends Component {
7 +
8 render() { 8 render() {
9 return ( 9 return (
10 <> 10 <>
11 <Route path="/" component={MainPage} exact={true} /> 11 <Route path="/" component={MainPage} exact={true} />
12 - <Route path="/prompter" component={PrompterPage} exact={true} /> 12 + <Route path="/prompter:script" component={PrompterPage} exact={true} />
13 - {/* <Route path="/prompter" component={test} exact={true} /> */}
14 </> 13 </>
15 ); 14 );
16 } 15 }
......
...@@ -7,7 +7,7 @@ const StyledTeleprompter = styled.div` ...@@ -7,7 +7,7 @@ const StyledTeleprompter = styled.div`
7 width: 100%; 7 width: 100%;
8 height: 56rem; 8 height: 56rem;
9 scroll-behavior: smooth; 9 scroll-behavior: smooth;
10 - overflow: scroll; 10 + overflow: auto;
11 display: block; 11 display: block;
12 margin-bottom: 1rem; 12 margin-bottom: 1rem;
13 ` 13 `
......
1 import React, { Component, Fragment } from 'react'; 1 import React, { Component, Fragment } from 'react';
2 import { post } from 'axios'; 2 import { post } from 'axios';
3 import { withStyles, Typography, Paper, Button, TextField } from '@material-ui/core'; 3 import { withStyles, Typography, Paper, Button, TextField } from '@material-ui/core';
4 -// import PrompterPage from './PrompterPage';
5 4
6 const styles = theme => ({ 5 const styles = theme => ({
7 root: { 6 root: {
...@@ -71,12 +70,12 @@ class MainPage extends Component { ...@@ -71,12 +70,12 @@ class MainPage extends Component {
71 this.setState({ 70 this.setState({
72 script: '' 71 script: ''
73 }) 72 })
74 - this.props.history.push('/prompter'); 73 + this.props.history.push(`/prompter:${this.script}`);
75 } 74 }
76 75
77 // Send script to Server 76 // Send script to Server
78 addScript = () => { 77 addScript = () => {
79 - const url = '/api/script'; 78 + const url = `/api/this.props.script`;
80 let scriptJSON = { script : this.script }; 79 let scriptJSON = { script : this.script };
81 const config = { 80 const config = {
82 headers: { 81 headers: {
......
1 import React, { Fragment } from 'react'; 1 import React, { Fragment } from 'react';
2 import axios from 'axios' 2 import axios from 'axios'
3 +import { withStyles, Button} from '@material-ui/core';
3 import { 4 import {
4 GlobalStyles, 5 GlobalStyles,
5 StyledApp, 6 StyledApp,
6 StyledTeleprompter as Teleprompter, 7 StyledTeleprompter as Teleprompter,
7 - Controls,
8 - Buttons,
9 - Button,
10 } from "../styles"; 8 } from "../styles";
11 -// import { withStyles, Typography, Paper, Button, TextField} from '@material-ui/core';
12 9
13 -// const styles = theme => ({ 10 +const styles = theme => ({
14 -// root: { 11 + button: {
15 -// '& .MuiTextField-root': { 12 + fontSize: '1.2rem',
16 -// margin: theme.spacing(1), 13 + },
17 -// width: '100%', 14 +});
18 -// minWidth: 1080
19 -// },
20 -// },
21 -// title: {
22 -// marginTop: theme.spacing.unit * 5,
23 -// textAlign: 'center',
24 -// display: 'none',
25 -// fontSize: '2.0rem',
26 -// [theme.breakpoints.up('sm')]: {
27 -// display: 'block',
28 -// }
29 -// },
30 -// paper: {
31 -// marginTop: theme.spacing.unit * 5,
32 -// marginLeft: theme.spacing.unit * 20,
33 -// marginRight: theme.spacing.unit * 20
34 -// },
35 -// button: {
36 -// marginTop: theme.spacing.unit * 1,
37 -// marginLeft: theme.spacing.unit * 20,
38 -// fontSize: '1rem',
39 -// },
40 -// });
41 15
42 -// const INITIAL_TEXT = ``;
43 16
44 -function PrompterPage() { 17 +function PrompterPage({match}) {
18 + const classes = styles();
45 const [listening, setListening] = React.useState(false); 19 const [listening, setListening] = React.useState(false);
46 const [words, setWords] = React.useState("".split(" ")); 20 const [words, setWords] = React.useState("".split(" "));
47 - // const [words, setWords] = React.useState("");
48 const [progress, setProgress] = React.useState(0); 21 const [progress, setProgress] = React.useState(0);
49 22
50 // Serverλ‘œλΆ€ν„° Script λ°›μ•„μ˜΄ 23 // Serverλ‘œλΆ€ν„° Script λ°›μ•„μ˜΄
51 - axios.get("api/script") 24 + axios.get(`api/${match.params["script"].slice(1)}`)
52 .then(res => { // .then : 응닡(μƒνƒœμ½”λ“œ200~300미만)μ„±κ³΅μ‹œ 25 .then(res => { // .then : 응닡(μƒνƒœμ½”λ“œ200~300미만)μ„±κ³΅μ‹œ
53 console.log(res.data); 26 console.log(res.data);
54 setWords(res.data.split(" ")); // λ°›μ•„μ˜¨ Script λ¬Έμžμ—΄ 처리 27 setWords(res.data.split(" ")); // λ°›μ•„μ˜¨ Script λ¬Έμžμ—΄ 처리
...@@ -57,12 +30,6 @@ function PrompterPage() { ...@@ -57,12 +30,6 @@ function PrompterPage() {
57 console.log(error); 30 console.log(error);
58 }); 31 });
59 32
60 -
61 - // const handleInput = (e) => {
62 - // setWords(e.target.value.split(" "));
63 - // progress && setProgress(0);
64 - // };
65 -
66 const handleListening = () => { 33 const handleListening = () => {
67 if (listening) { 34 if (listening) {
68 setListening(false); 35 setListening(false);
...@@ -78,18 +45,14 @@ function PrompterPage() { ...@@ -78,18 +45,14 @@ function PrompterPage() {
78 45
79 return ( 46 return (
80 <> 47 <>
48 + <Button className={classes.button} variant="contained" color="primary" size="medium" onClick={handleListening}>{listening ? "Stop" : "Start"}</Button>
49 + <Button className={classes.button} variant="contained" color="secondary" size="medium" disabled={listening} onClick={handleReset}>Reset</Button>
81 <GlobalStyles /> 50 <GlobalStyles />
82 <StyledApp> 51 <StyledApp>
83 - <Controls>
84 - <Buttons>
85 - <Button onClick={handleListening}>{listening ? "Stop" : "Start"}</Button>
86 - <Button onClick={handleReset} disabled={listening} secondary>Reset</Button>
87 - </Buttons>
88 - </Controls>
89 <Teleprompter words={words} listening={listening} progress={progress} onChange={handleChange} /> 52 <Teleprompter words={words} listening={listening} progress={progress} onChange={handleChange} />
90 </StyledApp> 53 </StyledApp>
91 </> 54 </>
92 ); 55 );
93 } 56 }
94 57
95 -export default PrompterPage;
...\ No newline at end of file ...\ No newline at end of file
58 +export default withStyles(styles)(PrompterPage);
...\ No newline at end of file ...\ No newline at end of file
......
1 -import styled, { createGlobalStyle, css } from "styled-components"; 1 +import styled, { createGlobalStyle } from "styled-components";
2 import Teleprompter from "./components/Teleprompter"; 2 import Teleprompter from "./components/Teleprompter";
3 3
4 export const GlobalStyles = createGlobalStyle` 4 export const GlobalStyles = createGlobalStyle`
...@@ -29,60 +29,5 @@ export const StyledTeleprompter = styled(Teleprompter)` ...@@ -29,60 +29,5 @@ export const StyledTeleprompter = styled(Teleprompter)`
29 flex-direction: column; 29 flex-direction: column;
30 justify-content: space-around; 30 justify-content: space-around;
31 height: 100%; 31 height: 100%;
32 -`;
33 -
34 -export const Controls = styled.div`
35 - display: flex;
36 - flex-direction: column;
37 - margin-bottom: 1rem;
38 -`;
39 -
40 -export const Buttons = styled.div`
41 - display: flex;
42 - justify-content: flex-start;
43 -`;
44 32
45 -export const Input = styled.textarea`
46 - height: 5rem;
47 - border: 1px solid rgb(0, 0, 0, 0.25);
48 - padding: 0.5rem;
49 - font-family: Tahoma, sans-serif;
50 - background: transparent;
51 - margin-bottom: 1rem;
52 - width: 100%;
53 -`;
54 -
55 -export const Button = styled.button`
56 - display: inline-block;
57 - border: none;
58 - padding: 0.5rem 1rem;
59 - margin: 0;
60 - text-decoration: none;
61 - background: #666ba5;
62 - border: 1px solid rgb(0, 0, 0, 0.25);
63 - color: white;
64 - font-size: 1rem;
65 - cursor: pointer;
66 - text-align: center;
67 - transition: background 250ms ease-in-out, transform 150ms ease;
68 - margin-right: 1rem;
69 - min-width: 5rem;
70 - ${(p) =>
71 - p.secondary &&
72 - css`
73 - background: #666;
74 - `}
75 - &:last-child {
76 - margin-right: 0;
77 - }
78 - &:hover,
79 - &:focus {
80 - transform: scale(1.1);
81 - }
82 - &:focus {
83 - outline: 1px solid #fff;
84 - }
85 - &:active {
86 - transform: scale(0.99);
87 - }
88 `; 33 `;
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -9,13 +9,13 @@ app.use(bodyParser.urlencoded({ extended: true})); ...@@ -9,13 +9,13 @@ app.use(bodyParser.urlencoded({ extended: true}));
9 9
10 let scriptReceived = ""; 10 let scriptReceived = "";
11 11
12 -app.get('/api/script', (req, res) => { 12 +app.get('/api/:script', (req, res) => {
13 res.send( 13 res.send(
14 scriptReceived 14 scriptReceived
15 ) 15 )
16 }); 16 });
17 17
18 -app.post('/api/script', (req, res) => { 18 +app.post('/api/:script', (req, res) => {
19 scriptReceived = req.body.script; 19 scriptReceived = req.body.script;
20 }); 20 });
21 21
......