Skip to content

Commit da86dac

Browse files
refactor: pass nmrium data object in load event
1 parent a1b8224 commit da86dac

2 files changed

Lines changed: 17 additions & 23 deletions

File tree

src/NMRiumWrapper.tsx

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,26 +23,25 @@ const styles = {
2323
`,
2424
};
2525

26+
const testData = {
27+
spectra: [
28+
{
29+
source: {
30+
jcampURL:
31+
'https://cheminfo.github.io/nmr-dataset-demo/cytisine/13c.jdx',
32+
},
33+
},
34+
],
35+
};
36+
2637
export default function NMRiumWrapper() {
2738
const [data, setDate] = useState<NMRiumData>();
2839

2940
const actionHandler = useActions();
3041

3142
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({
38-
source: {
39-
jcampURL,
40-
},
41-
});
42-
}
43-
setDate({
44-
spectra,
45-
});
43+
events.on('load', (_data) => {
44+
setDate(_data);
4645
});
4746
});
4847

@@ -51,11 +50,7 @@ export default function NMRiumWrapper() {
5150
<div css={styles.header}>
5251
<Button.Done
5352
onClick={() => {
54-
events.trigger('load', {
55-
urls: [
56-
'https://cheminfo.github.io/nmr-dataset-demo/cytisine/13c.jdx',
57-
],
58-
});
53+
events.trigger('load', testData);
5954
}}
6055
>
6156
Test Load from external URL

src/events/types.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1+
import { NMRiumData } from 'nmrium';
2+
13
type Actions = 'load' | 'test';
24

3-
interface LoadSpectra {
4-
urls: string[];
5-
}
65
interface TestData {
76
testData: string;
87
}
98

109
type EventData<T extends Actions> = T extends 'load'
11-
? LoadSpectra
10+
? NMRiumData
1211
: T extends 'test'
1312
? TestData
1413
: never;

0 commit comments

Comments
 (0)