-
Notifications
You must be signed in to change notification settings - Fork 74
Expand file tree
/
Copy pathindex.jsx
More file actions
102 lines (84 loc) · 2.12 KB
/
Copy pathindex.jsx
File metadata and controls
102 lines (84 loc) · 2.12 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import React, {
useCallback,
useState,
} from 'react';
import {
useDispatch,
useSelector,
} from 'react-redux';
import { useTranslation } from 'react-i18next';
import {
clear as clearLog,
selectLog,
selectLogTimestamped,
} from './logSlice';
import './style.scss';
function Log() {
const { t } = useTranslation('common');
const dispatch = useDispatch();
const messages = useSelector(selectLogTimestamped);
const log = useSelector(selectLog);
const [ expanded, setExpanded] = useState(false);
const messageElements = messages.slice(0).reverse()
.map((message, index) => (
<div key={index}>
<span className="date">
{message.date}
@
</span>
<span className="time">
{message.time}
--
</span>
{message.html}
</div>
));
const toggleExpanded = useCallback(() => {
setExpanded(!expanded);
}, [expanded]);
const handleSaveLog = useCallback(() => {
const element = document.createElement("a");
const file = new Blob([log.join("\n")], { type: 'text/plain' });
element.href = URL.createObjectURL(file);
element.download = "esc-configurator-log.txt";
document.body.appendChild(element);
element.click();
dispatch(clearLog());
}, [dispatch, log]);
const handleClearLog = useCallback(() => {
dispatch(clearLog());
}, [dispatch]);
return (
<div
className={expanded ? 'expanded' : ''}
id="log"
>
<div className="logswitch">
<button
onClick={handleSaveLog}
type="button"
>
{t('escButtonSaveLog')}
</button>
<button
onClick={handleClearLog}
type="button"
>
{t('escButtonClearLog')}
</button>
<button
id="showlog"
onClick={toggleExpanded}
type="button"
>
{expanded ? t('hideLog') : t('showLog')}
</button>
</div>
<div id="scrollicon" />
<div className="wrapper">
{messageElements}
</div>
</div>
);
}
export default React.memo(Log);