Skip to content

Commit

Permalink
chore: fix types
Browse files Browse the repository at this point in the history
  • Loading branch information
hamed-musallam committed Oct 20, 2023
1 parent 1629b22 commit a3823b2
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 51 deletions.
20 changes: 7 additions & 13 deletions src/component/1d/tool/XLabelPointer.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Spectrum1D } from 'nmr-load-save';
import { useCallback, useMemo, CSSProperties } from 'react';
import { useCallback, CSSProperties } from 'react';

import { useBrushTracker } from '../../EventsTrackers/BrushTracker';
import { useMouseTracker } from '../../EventsTrackers/MouseTracker';
import { useChartData } from '../../context/ChartContext';
import { useScaleChecked } from '../../context/ScaleContext';
import { useActiveSpectrum } from '../../hooks/useActiveSpectrum';
import { useFormatNumberByNucleus } from '../../hooks/useFormatNumberByNucleus';
import useSpectrum from '../../hooks/useSpectrum';

const style: CSSProperties = {
cursor: 'crosshair',
Expand All @@ -20,31 +20,25 @@ const style: CSSProperties = {
};

function XLabelPointer() {
const { height, width, margin, data } = useChartData();
const activeSpectrum = useActiveSpectrum();
const { height, width, margin } = useChartData();
const activeSpectrum = useSpectrum(null);
const { scaleX } = useScaleChecked();

const position = useMouseTracker();
const brushState = useBrushTracker();
const activeSpectrumData = useMemo(() => {
const spectrumData = activeSpectrum
? data.find((d) => d.id === activeSpectrum.id)
: null;
return spectrumData;
}, [activeSpectrum, data]);

const format = useFormatNumberByNucleus(
(activeSpectrumData as Spectrum1D)?.info.nucleus,
(activeSpectrum as Spectrum1D)?.info.nucleus,
);

const getXValue = useCallback(
(xVal) => {
if (activeSpectrumData) {
if (activeSpectrum) {
const xInvert = scaleX().invert(xVal);
return format(xInvert);
}
},
[activeSpectrumData, format, scaleX],
[activeSpectrum, format, scaleX],
);

if (
Expand Down
1 change: 1 addition & 0 deletions src/component/header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ function HeaderInner(props: HeaderInnerProps) {
case options.zonePicking.id:
return <Zones2DOptionPanel />;
default:
return null;
break;
}
}, [selectedOptionPanel]);
Expand Down
75 changes: 37 additions & 38 deletions src/component/panels/SummaryPanel/SetShiftTolerancesModal.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/** @jsxImportSource @emotion/react */
import { css } from '@emotion/react';
import { useCallback, useEffect, useMemo, useState } from 'react';
import { useEffect, useState } from 'react';

import CloseButton from '../../elements/CloseButton';

Expand Down Expand Up @@ -99,45 +99,20 @@ export default function SetShiftToleranceModal({
}
}, [previousTolerance]);

const onSaveHandler = useCallback(() => {
function onSaveHandler() {
onSave?.(tolerance);
onClose?.();
}, [onClose, onSave, tolerance]);

const onChangeHandler = useCallback(
(e, atomType: string) => {
const value: string = e.target.value;
if (value.trim().length > 0) {
setTolerance({ ...tolerance, [atomType]: Number(value) });
setIsValid({ ...isValid, [atomType]: true });
} else {
setIsValid({ ...isValid, [atomType]: false });
}
},
[isValid, tolerance],
);
}

const rows = useMemo(() => {
return tolerance
? Object.keys(tolerance).map((atomType) => {
return (
<tr key={`tolerance_${atomType}`}>
<td>{atomType}</td>
<td>
<input
type="number"
onChange={(e) => onChangeHandler(e, atomType)}
defaultValue={tolerance[atomType]}
style={
!isValid[atomType] ? { backgroundColor: 'orange' } : {}
}
/>
</td>
</tr>
);
})
: undefined;
}, [isValid, onChangeHandler, tolerance]);
function onChangeHandler(e, atomType: string) {
const value: string = e.target.value;
if (value.trim().length > 0) {
setTolerance({ ...tolerance, [atomType]: Number(value) });
setIsValid({ ...isValid, [atomType]: true });
} else {
setIsValid({ ...isValid, [atomType]: false });
}
}

return (
<div css={modalContainer}>
Expand All @@ -153,7 +128,13 @@ export default function SetShiftToleranceModal({
<th>Value</th>
</tr>
</thead>
<tbody>{rows}</tbody>
<tbody>
<Rows
onChange={onChangeHandler}
isValid={isValid}
tolerance={tolerance}
/>
</tbody>
</table>
<button
type="button"
Expand All @@ -165,3 +146,21 @@ export default function SetShiftToleranceModal({
</div>
);
}

function Rows({ tolerance, onChange, isValid }) {
return Object.keys(tolerance).map((atomType) => {
return (
<tr key={`tolerance_${atomType}`}>
<td>{atomType}</td>
<td>
<input
type="number"
onChange={(e) => onChange(e, atomType)}
defaultValue={tolerance[atomType]}
style={!isValid[atomType] ? { backgroundColor: 'orange' } : {}}
/>
</td>
</tr>
);
});
}

0 comments on commit a3823b2

Please sign in to comment.