11/** @jsxImportSource @emotion /react */
22import { css } from '@emotion/react' ;
33import NMRium , { NMRiumData } from 'nmrium' ;
4+ import Button from 'nmrium/lib/component/elements/Button' ;
5+ import { useEffect , useState } from 'react' ;
6+ import events from './events' ;
47import useActions from './hooks/useActions' ;
58
69const 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