Skip to content

Commit

Permalink
fix: apply baseline correction on the fly when opening its options panel
Browse files Browse the repository at this point in the history
  • Loading branch information
hamed-musallam committed Jul 9, 2024
1 parent a164387 commit 1b8ebdc
Showing 1 changed file with 23 additions and 10 deletions.
33 changes: 23 additions & 10 deletions src/component/header/BaseLineCorrectionPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Checkbox } from '@blueprintjs/core';
import { Select } from '@blueprintjs/select';
import { yupResolver } from '@hookform/resolvers/yup';
import { Filter, Filters, BaselineCorrectionOptions } from 'nmr-processing';
import { memo, useRef } from 'react';
import { memo, useCallback, useEffect, useRef } from 'react';
import { useForm } from 'react-hook-form';
import { Button, useSelect } from 'react-science/ui';
import * as Yup from 'yup';
Expand Down Expand Up @@ -107,6 +107,23 @@ function BaseLineCorrectionInnerPanel(
itemTextKey: 'label',
});

const onChange = useCallback(
(values) => {
const { livePreview, ...options } = values;

if (livePreview || previousPreviewRef !== livePreview) {
dispatch({
type: 'CALCULATE_BASE_LINE_CORRECTION_FILTER',
payload: {
options,
livePreview,
},
});
}
},
[dispatch],
);

const handleApplyFilter = (
values,
triggerSource: 'apply' | 'onChange' = 'apply',
Expand All @@ -115,15 +132,7 @@ function BaseLineCorrectionInnerPanel(

switch (triggerSource) {
case 'onChange': {
if (livePreview || previousPreviewRef !== livePreview) {
dispatch({
type: 'CALCULATE_BASE_LINE_CORRECTION_FILTER',
payload: {
options,
livePreview,
},
});
}
onChange(values);
break;
}

Expand Down Expand Up @@ -167,6 +176,10 @@ function BaseLineCorrectionInnerPanel(
const { onChange: onLivePreviewChange, ...otherLivePreviewRegisterOptions } =
register(`livePreview`);

useEffect(() => {
void handleSubmit((values) => onChange(values))();
}, [handleSubmit, onChange]);

return (
<HeaderContainer>
<Label title="Algorithm: " style={headerLabelStyle}>
Expand Down

0 comments on commit 1b8ebdc

Please sign in to comment.