-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathsession.component.tsx
More file actions
74 lines (65 loc) · 2.19 KB
/
session.component.tsx
File metadata and controls
74 lines (65 loc) · 2.19 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
import React from 'react';
import { cx } from 'emotion';
import TextareaAutosize from '@material-ui/core/TextareaAutosize';
import ArrowForwardRoundedIcon from '@material-ui/icons/ArrowForwardRounded';
import UndoIcon from '@material-ui/icons/Undo';
import Button from '@material-ui/core/Button';
import * as innerClasses from './session.styles';
import { DownloadTxtFile } from 'common-app';
interface Props {
log: string;
handleSendFullContentLog: (fullContent: string) => void;
className?: string;
}
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, className } = props;
React.useEffect(() => {
handleSetSessionContent(log);
}, [log]);
return (
<form className={cx(innerClasses.root, className)}>
<label className={innerClasses.label} htmlFor="session">
Session
</label>
<TextareaAutosize
id="session"
rowsMax={20}
rowsMin={20}
className={innerClasses.textarea}
/>
<Button
variant="contained"
color="secondary"
disableElevation
className={innerClasses.undoButton}
onClick={() => handleSetSessionContent(log)}
>
<UndoIcon className={innerClasses.undoIcon} />
Undo
</Button>
<Button
variant="contained"
color="primary"
disableElevation
className={innerClasses.sendButton}
onClick={() => handleSendFullContentLog(getFullContent(log))}
>
Send Full Content
<ArrowForwardRoundedIcon className={innerClasses.sendIcon} />
</Button>
<DownloadTxtFile />
</form>
);
};