|
1 | 1 | /** @jsxImportSource @emotion/react */ |
2 | 2 | import { css } from '@emotion/react'; |
3 | | -import { useState, useCallback } from 'react'; |
4 | 3 | import NMRium, { NMRiumData } from 'nmrium'; |
5 | | - |
6 | | -// import { |
7 | | -// addJcampFromURL, |
8 | | -// addJcamp, |
9 | | -// toJSON, |
10 | | -// } from "nmrium/lib/data/SpectraManager"; |
| 4 | +import useActions from './hooks/useActions'; |
11 | 5 |
|
12 | 6 | const styles = { |
13 | 7 | container: css` |
@@ -36,212 +30,25 @@ export default function NMRiumWrapper(props: NMRWrapperProps) { |
36 | 30 | { |
37 | 31 | source: { |
38 | 32 | jcampURL: |
39 | | - 'https://cheminfo.github.io/nmr-dataset-demo/cytisine/13c.fid.jdx', |
| 33 | + 'https://cheminfo.github.io/nmr-dataset-demo/cytisine/13c.jdx', |
40 | 34 | }, |
41 | 35 | }, |
42 | 36 | ], |
43 | 37 | }, |
44 | 38 | } = props; |
45 | 39 |
|
46 | | - const [action, setAction] = useState(); |
47 | | - |
48 | | - // componentDidMount() { |
49 | | - // this.loadJcamp(); |
50 | | - // } |
51 | | - |
52 | | - // componentDidUpdate(prevProps) { |
53 | | - // if (prevProps.jcampURL !== this.props.jcampURL) { |
54 | | - // this.loadJcampURL(); |
55 | | - // } |
56 | | - // if (prevProps.jcamp !== this.props.jcamp) { |
57 | | - // this.loadJcamp(); |
58 | | - // } |
59 | | - // if (prevProps.jcampFile !== this.props.jcampFile) { |
60 | | - // this.loadLocalJcampFile(); |
61 | | - // } |
62 | | - // } |
63 | | - |
64 | | - const loadJcampURL = useCallback((event) => { |
65 | | - // console.log(event.target.value) |
66 | | - // this.setState({ operationSelected: event.target.value }) |
67 | | - setAction(event.targe?.value); |
68 | | - }, []); |
69 | | - |
70 | | - // loadJcampURL() { |
71 | | - // const { jcampURL } = this.props; |
72 | | - |
73 | | - // const spectra = []; |
74 | | - |
75 | | - // fetch('/api/v1/chemspectra/nmr_displayer/'+jcampURL, { |
76 | | - // method: 'GET', |
77 | | - // headers: { |
78 | | - // 'Accept': 'application/json', |
79 | | - // 'Content-Type': 'application/json', |
80 | | - // } |
81 | | - // }).then((response) => { |
82 | | - // return response.json(); |
83 | | - // }); |
84 | | - // .then((json) => { |
85 | | - // // console.log(json.jcamp) |
86 | | - // addJcamp(spectra, json.jcamp, {}) |
87 | | - // const spectraData = {spectra: spectra} |
88 | | - // this.setState({spectraData: spectraData}) |
89 | | - // }) |
90 | | - // .catch((err) => { |
91 | | - // console.error(err); |
92 | | - // }) |
93 | | - // } |
94 | | - |
95 | | - // const loadJcamp = useCallback(() =>{ |
96 | | - // const { jcamp } = this.props; |
97 | | - // if (typeof jcamp === 'string') { |
98 | | - // const spectra = []; |
99 | | - // addJcamp(spectra, jcamp, {}) |
100 | | - // const spectraData = {spectra: spectra} |
101 | | - // setData({spectraData: spectraData}) |
102 | | - // } |
103 | | - // },[]) |
104 | | - |
105 | | - // loadLocalJcampFile() { |
106 | | - // const { jcampFile } = this.props; |
107 | | - // if (jcampFile) { |
108 | | - // const spectra = []; |
109 | | - // } |
110 | | - // } |
111 | | - |
112 | | - // savePeaks() { |
113 | | - // const {workingData} = this.state; |
114 | | - // if (workingData) { |
115 | | - // const exportedData = toJSON(workingData) |
116 | | - // // console.log(exportedData) |
117 | | - // const spectra = exportedData.spectra; |
118 | | - // if (spectra && spectra.length > 0) { |
119 | | - // const firstSpc = spectra[0]; |
120 | | - // const spcPeaks = firstSpc.peaks.values; |
121 | | - // const peaks = spcPeaks.map((pVal) => { |
122 | | - // return pVal.delta.toFixed(2); |
123 | | - // }) |
124 | | - // const info = firstSpc.info; |
125 | | - // if (window.parent) { |
126 | | - // window.parent.postMessage({type: 'peaks', data: peaks, layout: info.nucleus}, "*"); |
127 | | - // } |
128 | | - |
129 | | - // } |
130 | | - // } |
131 | | - // } |
132 | | - |
133 | | - // saveIntegrals() { |
134 | | - // const {workingData} = this.state; |
135 | | - // if (workingData) { |
136 | | - // const exportedData = toJSON(workingData) |
137 | | - // // console.log(exportedData) |
138 | | - // const spectra = exportedData.spectra |
139 | | - // if (spectra && spectra.length > 0) { |
140 | | - // const firstSpc = spectra[0] |
141 | | - // const spcIntegral = firstSpc.integrals.values |
142 | | - // const integrals = spcIntegral.map((pVal) => { |
143 | | - // return pVal.integral |
144 | | - // }) |
145 | | - // // console.log(integrals) |
146 | | - |
147 | | - // } |
148 | | - // } |
149 | | - // } |
150 | | - |
151 | | - // saveRanges() { |
152 | | - // const {workingData} = this.state; |
153 | | - // if (workingData) { |
154 | | - // const exportedData = toJSON(workingData) |
155 | | - // // console.log(exportedData) |
156 | | - // const spectra = exportedData.spectra |
157 | | - // if (spectra && spectra.length > 0) { |
158 | | - // const firstSpc = spectra[0] |
159 | | - // const ranges = firstSpc.ranges |
160 | | - // const spcPeaks = firstSpc.peaks.values; |
161 | | - // const peaks = spcPeaks.map((pVal) => { |
162 | | - // return pVal.delta.toFixed(2); |
163 | | - // }) |
164 | | - // const info = firstSpc.info; |
165 | | - // if (window.parent) { |
166 | | - // window.parent.postMessage({type: 'ranges', data: {peaks: peaks, ranges: ranges}, layout: info.nucleus}, "*"); |
167 | | - // } |
168 | | - // } |
169 | | - // } |
170 | | - // } |
171 | | - |
172 | | - // handleSubmit(event) { |
173 | | - // const {operationSelected} = this.state; |
174 | | - // if (operationSelected === 'write_peaks') { |
175 | | - // this.savePeaks() |
176 | | - // } |
177 | | - // else if (operationSelected === 'write_integrals') { |
178 | | - // this.saveIntegrals() |
179 | | - // } |
180 | | - // else if (operationSelected === 'save_ranges') { |
181 | | - // this.saveRanges() |
182 | | - // } |
183 | | - // } |
184 | | - |
185 | | - // handleDataChange(data) { |
186 | | - // if (data && data.data) { |
187 | | - // this.setState({workingData: data}) |
188 | | - // // const exportedData = toJSON(data) |
189 | | - // // // console.log(exportedData) |
190 | | - // // const spectra = exportedData.spectra |
191 | | - // // if (spectra && spectra.length > 0) { |
192 | | - // // const firstSpc = spectra[0] |
193 | | - // // const spcPeaks = firstSpc.peaks.values |
194 | | - // // const peaks = spcPeaks.map((pVal) => { |
195 | | - // // return pVal.delta |
196 | | - // // }) |
197 | | - // // console.log(peaks) |
198 | | - // // } |
199 | | - // } |
200 | | - |
201 | | - // } |
202 | | - |
203 | | - const dataChangeHandle = useCallback((data) => { |
204 | | - console.log(data); |
205 | | - }, []); |
206 | | - |
207 | | - const actionChangeHandler = useCallback((event) => { |
208 | | - // console.log(event.target.value) |
209 | | - // this.setState({ operationSelected: event.target.value }) |
210 | | - setAction(event.targe?.value); |
211 | | - }, []); |
| 40 | + const actionHandler = useActions(); |
212 | 41 |
|
213 | 42 | return ( |
214 | 43 | <div css={styles.container}> |
215 | 44 | <div css={styles.header}> |
216 | 45 | <span>header</span> |
217 | 46 | </div> |
218 | | - {/* <FormControl> |
219 | | - <InputLabel className="select-sv-bar-label">Submit</InputLabel> |
220 | | - <Select |
221 | | - variant="outlined" |
222 | | - onChange={actionChangeHandler} |
223 | | - input={ |
224 | | - <OutlinedInput className="input-sv-bar-operation" labelWidth={50} /> |
225 | | - } |
226 | | - > |
227 | | - <MenuItem value="write_peaks"> |
228 | | - <span>Write peaks</span> |
229 | | - </MenuItem> */} |
230 | | - {/* <MenuItem value="write_integrals"> |
231 | | - <span>Write integrals</span> |
232 | | - </MenuItem> */} |
233 | | - {/* <MenuItem value="save_ranges"> |
234 | | - <span>Write ranges</span> |
235 | | - </MenuItem> |
236 | | - </Select> |
237 | | - </FormControl> |
238 | | - <FormControl> */} |
239 | | - {/* <Button onClick={this.handleSubmit}>Submit</Button> */} |
240 | | - {/* </FormControl> */} |
| 47 | + |
241 | 48 | <div css={styles.wrapper}> |
242 | 49 | <NMRium |
243 | 50 | data={data} |
244 | | - onDataChange={dataChangeHandle} |
| 51 | + onDataChange={actionHandler} |
245 | 52 | preferences={{ |
246 | 53 | toolBarButtons: { |
247 | 54 | hideImport: true, |
|
0 commit comments