Skip to content

Commit

Permalink
fix: data change does not re-initiate the state
Browse files Browse the repository at this point in the history
  • Loading branch information
hamed-musallam committed Apr 14, 2022
1 parent 1024c2e commit 1b96235
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
6 changes: 5 additions & 1 deletion src/component/reducer/Reducer.ts
Expand Up @@ -461,7 +461,11 @@ export function dispatchMiddleware(dispatch) {
}

function innerSpectrumReducer(draft: Draft<State>, action) {
if (![types.LOAD_JSON_FILE, types.LOAD_NMREDATA_FILE].includes(action.type)) {
if (
![types.LOAD_JSON_FILE, types.LOAD_NMREDATA_FILE, types.INITIATE].includes(
action.type,
)
) {
draft.actionType = action.type;
}

Expand Down
17 changes: 12 additions & 5 deletions src/component/reducer/actions/LoadActions.ts
Expand Up @@ -7,7 +7,7 @@ import { UsedColors } from '../../../types/UsedColors';
import { Molecules, NMRiumPreferences, Spectra } from '../../NMRium';
import { DefaultTolerance } from '../../panels/SummaryPanel/CorrelationTable/Constants';
import { getInitialState, State } from '../Reducer';
import { LOAD_JSON_FILE, LOAD_NMREDATA_FILE } from '../types/Types';
import { INITIATE, LOAD_JSON_FILE, LOAD_NMREDATA_FILE } from '../types/Types';

import { changeSpectrumVerticalAlignment } from './PreferencesActions';
import { setActiveTab } from './ToolsActions';
Expand Down Expand Up @@ -38,6 +38,7 @@ function setData(
multipleAnalysis: {},
exclusionZones: [],
};

setColors(draft, usedColors);
draft.data = spectra;
draft.molecules = MoleculeManager.fromJSON(molecules);
Expand Down Expand Up @@ -94,11 +95,17 @@ function setPreferences(draft: Draft<State>, data) {
}

function initiate(draft: Draft<State>, action) {
setData(draft, action.payload);
const state = getInitialState();

setData(state, action.payload);
const preferences = action.payload?.preferences || {};
setActiveTab(draft, { tab: preferences?.activeTab || '' });
setPreferences(draft, action.payload);
draft.isLoading = false;
setActiveTab(state, { tab: preferences?.activeTab || '' });
setPreferences(state, action.payload);
state.width = draft.width;
state.height = draft.height;
state.isLoading = false;
state.actionType = INITIATE;
return state;
}

function loadJDFFile(draft: Draft<State>, actions) {
Expand Down

0 comments on commit 1b96235

Please sign in to comment.