Repository navigation
Expand file tree
/
Copy pathCopybook.js
More file actions
74 lines (68 loc) · 2.3 KB
/
Copy pathCopybook.js
File metadata and controls
74 lines (68 loc) · 2.3 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, { useRef } from 'react';
import { Button, Dropdown, Modal } from 'semantic-ui-react';
import Loading from "./Loading";
import useCodeHighlighting from './hooks/useCodeHighlighting';
export default function Copybook(props) {
const codeEl = useCodeHighlighting([props.copybookFileContent, props.copybookVisible]);
const editorEl = useRef(null);
function handleClose() {
props.onCloseCopybook();
}
function handleDropdownChange(e, { searchQuery, value }) {
if (value != props.copybookSelectedFile.path) {
props.onRequestCopybookFile(
props.copybookFileList.find(f => f.path === value)
);
}
}
function renderDropdownItem() {
if (!props.copybookFileList) {
return null;
}
return props.copybookFileList.map((file, idx) => {
return {
key: file.path,
value: file.path,
text: (idx + 1) + '. ' + file.path
}
});
}
if (!props.copybookVisible || !props.copybookFileList || !props.copybookFileContent) {
return (
<Modal open={props.copybookVisible} onClose={handleClose}
centered={false} closeIcon className={props.className} size='large'>
<Modal.Header>
<div className='title'>Daily Algorithm Copybook</div>
</Modal.Header>
<Modal.Content>
<Loading />
<pre><code className='prettyprint' ref={codeEl}></code></pre>
</Modal.Content>
</Modal>
);
}
return (
<Modal open={props.copybookVisible} onClose={handleClose}
centered={false} closeIcon className={props.className} size='large'>
<Modal.Header>
<div className='title'>Daily Algorithm Copybook</div>
<Button size='tiny' as='a' basic
href={props.copybookSelectedFile.link}
target='_blank'>View In GitHub</Button>
<Dropdown
search
selection
onChange={handleDropdownChange}
value={props.copybookSelectedFile.path}
options={renderDropdownItem()} />
</Modal.Header>
<Modal.Content>
{props.copybookRequesting ? <Loading /> : ''}
<pre>
<code className='prettyprint' ref={codeEl}>{props.copybookFileContent.content}</code>
<div className='editor' contentEditable={true} ref={editorEl}></div>
</pre>
</Modal.Content>
</Modal>
)
}