From b15f3c71f47da8f493aeb7fd9110eea2ba240c72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alberto=20Caparr=C3=B3s=20Trigo?= Date: Sun, 1 Nov 2020 17:06:52 +0100 Subject: [PATCH] #3-Ace-Editor-example-review --- front/package.json | 2 + front/src/pods/student/student.component.tsx | 30 ++++++++++++-- front/src/pods/student/student.styles.ts | 5 ++- .../trainer/components/new-text.component.tsx | 41 +++++++++++++++---- .../trainer/components/new-text.styles.ts | 6 +-- .../trainer/components/session.component.tsx | 31 ++++++++++++-- .../pods/trainer/components/session.styles.ts | 6 +-- 7 files changed, 96 insertions(+), 25 deletions(-) diff --git a/front/package.json b/front/package.json index bd17c34..32de9ee 100644 --- a/front/package.json +++ b/front/package.json @@ -27,10 +27,12 @@ "@emotion/core": "^10.0.35", "@material-ui/core": "^4.10.1", "@material-ui/icons": "^4.9.1", + "ace-builds": "^1.4.12", "axios": "^0.19.2", "emotion": "^10.0.27", "lodash.merge": "^4.6.2", "react": "^16.12.0", + "react-ace": "^9.2.0", "react-dom": "^16.12.0", "react-hot-loader": "^4.12.18", "react-router-dom": "^5.2.0", diff --git a/front/src/pods/student/student.component.tsx b/front/src/pods/student/student.component.tsx index 82d4ff3..c681100 100644 --- a/front/src/pods/student/student.component.tsx +++ b/front/src/pods/student/student.component.tsx @@ -3,6 +3,10 @@ import * as classes from './student.styles'; // Material UI ~ components import TextareaAutosize from '@material-ui/core/TextareaAutosize'; import Typography from '@material-ui/core/Typography'; +// Code Editor +import AceEditor from 'react-ace'; +import 'ace-builds/src-noconflict/mode-typescript'; +import 'ace-builds/src-noconflict/theme-monokai'; interface Props { room: string; @@ -22,12 +26,30 @@ export const StudentComponent: React.FC = props => { - handleOnChange(value, e)} + fontSize={14} + showPrintMargin={true} + showGutter={true} + highlightActiveLine={true} + setOptions={{ + enableBasicAutocompletion: false, + enableLiveAutocompletion: true, + enableSnippets: false, + showLineNumbers: true, + tabSize: 2, + showPrintMargin: false, + wrap: true, + }} className={studentBoard} + width="auto" value={log} + readOnly={true} /> diff --git a/front/src/pods/student/student.styles.ts b/front/src/pods/student/student.styles.ts index b4a2a29..3be62bb 100644 --- a/front/src/pods/student/student.styles.ts +++ b/front/src/pods/student/student.styles.ts @@ -11,9 +11,10 @@ export const studentBoard = css` box-sizing: border-box; width: 100%; margin-top: ${spacing(10)}; + margin-bottom: ${spacing(10)}; padding: ${spacing(10)}; - font-family: ${typography.fontFamily}; - background-color: ${palette.background.paper}; + //font-family: ${typography.fontFamily}; + //background-color: ${palette.background.paper}; resize: none; border-radius: ${spacing(4)}; border: 1px solid ${palette.primary.main}; diff --git a/front/src/pods/trainer/components/new-text.component.tsx b/front/src/pods/trainer/components/new-text.component.tsx index 49e67d1..1354d94 100644 --- a/front/src/pods/trainer/components/new-text.component.tsx +++ b/front/src/pods/trainer/components/new-text.component.tsx @@ -3,9 +3,13 @@ import * as classes from './new-text.styles'; // Material UI ~ components import Button from '@material-ui/core/Button'; import TextareaAutosize from '@material-ui/core/TextareaAutosize'; +// Code Editor +import AceEditor from 'react-ace'; +import 'ace-builds/src-noconflict/mode-typescript'; +import 'ace-builds/src-noconflict/theme-monokai'; interface Props { - handleAppendTrainerText: (trainerText: string,) => void; + handleAppendTrainerText: (trainerText: string) => void; } export const NewTextComponent: React.FC = props => { @@ -27,9 +31,12 @@ export const NewTextComponent: React.FC = props => { trainerTextRef.current = ''; }; - const handleOnChange = (e: React.ChangeEvent): void => { - trainerTextRef.current = e.target.value; - setTrainerText(e.target.value); + const handleOnChange = ( + value: string, + e: React.ChangeEvent + ): void => { + trainerTextRef.current = value; + setTrainerText(value); }; React.useEffect(() => { @@ -48,13 +55,29 @@ export const NewTextComponent: React.FC = props => { - handleOnChange(e)} + handleOnChange(value, e)} + fontSize={14} + showPrintMargin={true} + showGutter={true} + highlightActiveLine={true} value={trainerText} + setOptions={{ + enableBasicAutocompletion: false, + enableLiveAutocompletion: true, + enableSnippets: false, + showLineNumbers: true, + tabSize: 2, + showPrintMargin: false, + }} + className={editTextArea} + width="auto" /> +