Skip to content

Commit

Permalink
fix: ph0 value starts from zero (#2315)
Browse files Browse the repository at this point in the history
ph0 input value should start from its last changed value

close #2314
  • Loading branch information
hamed-musallam committed Apr 24, 2023
1 parent 8035c82 commit 5d08c1a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 18 deletions.
4 changes: 2 additions & 2 deletions src/component/header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import AutoPeakPickingOptionPanel from './AutoPeakPickingOptionPanel';
import BaseLineCorrectionPanel from './BaseLineCorrectionPanel';
import { HeaderContainer } from './HeaderContainer';
import { LogsHistory } from './LogsHistory';
import ManualPhaseCorrectionPanel from './ManualPhaseCorrectionPanel';
import PhaseCorrectionPanel from './PhaseCorrectionPanel';
import RangesPickingOptionPanel from './RangesPickingOptionPanel';
import ZeroFillingOptionsPanel from './ZeroFillingOptionsPanel';
import Zones2DOptionPanel from './Zones2DOptionPanel';
Expand Down Expand Up @@ -109,7 +109,7 @@ function HeaderInner(props: HeaderInnerProps) {
case options.zeroFilling.id:
return <ZeroFillingOptionsPanel />;
case options.phaseCorrection.id:
return <ManualPhaseCorrectionPanel />;
return <PhaseCorrectionPanel />;
case options.peakPicking.id:
return <AutoPeakPickingOptionPanel />;
case options.rangePicking.id:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const algorithms = [
];
const emptyData = { datum: {}, filter: null };

export default function ManualPhaseCorrectionPanel() {
export default function PhaseCorrectionPanel() {
const {
toolOptions: {
data: { pivot },
Expand Down Expand Up @@ -139,6 +139,12 @@ export default function ManualPhaseCorrectionPanel() {
[data.re, dispatch, pivot?.index],
);

const updateInputRangeInitialValue = useCallback((value) => {
// update InputRange initial value
ph0Ref.current.setValue(value.ph0);
ph1Ref.current.setValue(value.ph1);
}, []);

const handleInput = useCallback(
(e) => {
const { name, value } = e.target;
Expand All @@ -148,34 +154,23 @@ export default function ManualPhaseCorrectionPanel() {
if (String(value).trim() !== '-') {
calcPhaseCorrectionHandler(newValue, name);
}

// update InputRange initial value
switch (name) {
case 'ph0':
ph0Ref.current.setValue(newValue.ph0);
break;
case 'ph1':
ph1Ref.current.setValue(newValue.ph1);
break;
default:
break;
}

updateInputRangeInitialValue(newValue);
valueRef.current = newValue;
setValue(valueRef.current);
}
},
[calcPhaseCorrectionHandler],
[calcPhaseCorrectionHandler, updateInputRangeInitialValue],
);

const handleRangeChange = useCallback(
(e) => {
const newValue = { ...valueRef.current, [e.name]: e.value };
calcPhaseCorrectionHandler(newValue, e.name);
updateInputRangeInitialValue(newValue);
valueRef.current = newValue;
setValue(valueRef.current);
},
[calcPhaseCorrectionHandler],
[calcPhaseCorrectionHandler, updateInputRangeInitialValue],
);

const handleCancelFilter = useCallback(() => {
Expand Down

0 comments on commit 5d08c1a

Please sign in to comment.