Skip to content

Commit 12d6631

Browse files
feat: load spectra from external URL
1 parent 929cdeb commit 12d6631

1 file changed

Lines changed: 34 additions & 17 deletions

File tree

src/NMRiumWrapper.tsx

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
/** @jsxImportSource @emotion/react */
22
import { css } from '@emotion/react';
33
import NMRium, { NMRiumData } from 'nmrium';
4+
import Button from 'nmrium/lib/component/elements/Button';
5+
import { useEffect, useState } from 'react';
6+
import events from './events';
47
import useActions from './hooks/useActions';
58

69
const styles = {
@@ -12,37 +15,51 @@ const styles = {
1215
header: css`
1316
height: 40px;
1417
width: 100%;
18+
padding: 5px;
1519
`,
1620
wrapper: css`
1721
flex: 1;
1822
overflow: hidden;
1923
`,
2024
};
2125

22-
interface NMRWrapperProps {
23-
data?: NMRiumData;
24-
}
26+
export default function NMRiumWrapper() {
27+
const [data, setDate] = useState<NMRiumData>();
28+
29+
const actionHandler = useActions();
2530

26-
export default function NMRiumWrapper(props: NMRWrapperProps) {
27-
const {
28-
data = {
29-
spectra: [
30-
{
31+
useEffect(() => {
32+
events.on('load', (result) => {
33+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
34+
const spectra: any[] = [];
35+
// eslint-disable-next-line no-restricted-syntax
36+
for (const jcampURL of result.urls) {
37+
spectra.push({
3138
source: {
32-
jcampURL:
33-
'https://cheminfo.github.io/nmr-dataset-demo/cytisine/13c.jdx',
39+
jcampURL,
3440
},
35-
},
36-
],
37-
},
38-
} = props;
39-
40-
const actionHandler = useActions();
41+
});
42+
}
43+
setDate({
44+
spectra,
45+
});
46+
});
47+
});
4148

4249
return (
4350
<div css={styles.container}>
4451
<div css={styles.header}>
45-
<span>header</span>
52+
<Button.Done
53+
onClick={() => {
54+
events.trigger('load', {
55+
urls: [
56+
'https://cheminfo.github.io/nmr-dataset-demo/cytisine/13c.jdx',
57+
],
58+
});
59+
}}
60+
>
61+
Test Load from external URL
62+
</Button.Done>
4663
</div>
4764

4865
<div css={styles.wrapper}>

0 commit comments

Comments
 (0)