-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathsession.component.tsx
More file actions
87 lines (80 loc) · 2.44 KB
/
session.component.tsx
File metadata and controls
87 lines (80 loc) · 2.44 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
import React from 'react';
import * as classes from './session.styles';
// Material UI ~ components
import TextareaAutosize from '@material-ui/core/TextareaAutosize';
import Button from '@material-ui/core/Button';
// Code Editor
import AceEditor from 'react-ace';
import 'ace-builds/src-noconflict/mode-typescript';
import 'ace-builds/src-noconflict/theme-monokai';
interface Props {
log: string;
handleSendFullContentLog: (fullContent: string) => void;
}
const getTextArea = (elementId: string): HTMLInputElement =>
document.getElementById('session') as HTMLInputElement;
const handleSetSessionContent = (sessionContent: string) => {
const sessionTextArea: HTMLInputElement = getTextArea('session');
sessionTextArea ? (sessionTextArea.value = sessionContent) : undefined;
};
const getFullContent = (currenSessionContent: string) => {
const sessionTextArea: HTMLInputElement = getTextArea('session');
return sessionTextArea && sessionTextArea.value != currenSessionContent
? sessionTextArea.value
: undefined;
};
export const SessionComponent: React.FC<Props> = props => {
const { log, handleSendFullContentLog } = props;
const { labelTextarea, studentBoard, sendBtn, undoBtn } = classes;
React.useEffect(() => {
handleSetSessionContent(log);
}, [log]);
return (
<div>
<label className={labelTextarea} htmlFor="session">
Session
</label>
<AceEditor
//id="session"
placeholder=""
mode="typescript"
theme="monokai"
name="blah2"
//onChange={(value, e) => 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}
/>
<Button
variant="contained"
color="secondary"
className={undoBtn}
onClick={() => handleSetSessionContent(log)}
>
Undo
</Button>
<Button
variant="contained"
color="primary"
className={sendBtn}
onClick={() => handleSendFullContentLog(getFullContent(log))}
>
Send Full Content
</Button>
</div>
);
};