Skip to content

Commit

Permalink
fix: serialize spectra object
Browse files Browse the repository at this point in the history
  • Loading branch information
hamed-musallam committed Nov 22, 2023
1 parent 9dd6895 commit d23ef5d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/NMRiumWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { useLoadSpectra } from './hooks/useLoadSpectra';
import { usePreferences } from './hooks/usePreferences';
import { useWhiteList } from './hooks/useWhiteList';
import AboutUsModal from './modal/AboutUsModal';
import { mapSpectra } from './utilities/mapSpectra';

const styles: Record<'container' | 'loadingContainer', CSSProperties> = {
container: {
Expand Down Expand Up @@ -39,7 +40,13 @@ export default function NMRiumWrapper() {

const { workspace, preferences, defaultEmptyMessage } = usePreferences();
const dataChangeHandler = useCallback<NMRiumChangeCb>((state, source) => {
events.trigger('data-change', { state, source });
//TODO: remove map spectra once this issue resolved
//a temporary fix by remove the `logger` and `keepSource` objects from each spectrum, this should removed once we solve the issue in nmr-load-save
state.data.spectra = mapSpectra(state.data.spectra);
events.trigger('data-change', {
state,
source,
});
}, []);

const { load: loadSpectra, isLoading, data: loadedData } = useLoadSpectra();
Expand Down
15 changes: 15 additions & 0 deletions src/utilities/mapSpectra.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* eslint-disable @typescript-eslint/dot-notation */
import { Spectrum } from 'nmr-load-save';

export function mapSpectra(spectra: Spectrum[]) {
return spectra.map((spectrum) => {
const cloneSpectrum = { ...spectrum };
if ('logger' in cloneSpectrum || 'keepSource' in cloneSpectrum) {
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
delete cloneSpectrum['logger'];
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
delete cloneSpectrum['keepSource'];
}
return cloneSpectrum;
}, []);
}

0 comments on commit d23ef5d

Please sign in to comment.