-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathRefAPI.tsx
More file actions
79 lines (73 loc) · 2.26 KB
/
RefAPI.tsx
File metadata and controls
79 lines (73 loc) · 2.26 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
import { FileCollection } from 'file-collection';
import { useCallback, useRef } from 'react';
import { Button, DropZone } from 'react-science/ui';
import type { NMRiumRefAPI } from '../../component/main/index.js';
import { NMRium } from '../../component/main/index.js';
import { saveAs } from '../../component/utility/save_as.ts';
export default function RefAPI() {
const nmriumRef = useRef<NMRiumRefAPI>(null);
const dropLoadFileCollectionHandler = useCallback((dropFiles: File[]) => {
const fileCollection = new FileCollection();
void fileCollection.appendFileList(dropFiles).then(() => {
nmriumRef.current?.loadFileCollection(fileCollection);
});
}, []);
const dropLoadFilesHandler = useCallback((dropFiles: File[]) => {
nmriumRef.current?.loadFiles(dropFiles);
}, []);
async function saveAsNMRiumFile() {
const blob = await nmriumRef.current?.getNMRiumFile({
settings: true,
view: true,
dataType: 'SELF_CONTAINED',
});
if (!blob) return;
saveAs({ blob, name: 'experiment', extension: '.nmrium.zip' });
}
return (
<div
style={{
height: '100%',
marginLeft: 30,
}}
>
<Button onClick={saveAsNMRiumFile}>Save as NMRium File</Button>
<div
style={{
display: 'flex',
minHeight: '100vh',
padding: '20px 0',
}}
>
<div style={{ flex: 9 }}>
<NMRium ref={nmriumRef} />
</div>
<div
style={{
display: 'flex',
flexDirection: 'column',
padding: '10px',
flex: 3,
}}
>
<div style={{ flex: 3, display: 'flex', flexDirection: 'column' }}>
<div style={{ flex: 1 }}>
<DropZone
onDrop={dropLoadFileCollectionHandler}
emptyTitle="Drop data files"
emptyDescription="To load with ref.loadFileCollection API"
/>
</div>
<div style={{ flex: 1 }}>
<DropZone
onDrop={dropLoadFilesHandler}
emptyTitle="Drop data files"
emptyDescription="To load with ref.loadFiles API"
/>
</div>
</div>
</div>
</div>
</div>
);
}