Skip to content

Commit

Permalink
Changing to use isValidGPSInputNew
Browse files Browse the repository at this point in the history
  • Loading branch information
zhenga5 committed Dec 3, 2024
1 parent a3e8c09 commit eb66706
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 13 deletions.
4 changes: 0 additions & 4 deletions src/client/app/components/groups/EditGroupModalComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -298,10 +298,6 @@ export default function EditGroupModalComponent(props: EditGroupModalComponentPr
latitude: gpsValues[latitudeIndex]
};
} else if ((gpsInput as string).length !== 0) {
// GPS not okay and there since non-zero length value.
// TODO isValidGPSInput currently pops up an alert so not doing it here, may change
// so leaving code commented out.
// showErrorNotification(translate('input.gps.range') + groupState.gps + '.');
showErrorNotification(message);
inputOk = false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,6 @@ export default function CreateMeterModalComponent(props: CreateMeterModalProps):
};
} else if (gpsInput.length !== 0) {
// GPS not okay. Only true if some input.
// TODO isValidGPSInput currently pops up an alert so not doing it here, may change
// so leaving code commented out.
// showErrorNotification(translate('input.gps.range') + state.gps + '.');
showErrorNotification(message);
inputOk = false;
}
Expand Down
9 changes: 4 additions & 5 deletions src/client/app/components/meters/EditMeterModalComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { tooltipBaseStyle } from '../../styles/modalStyle';
import { TrueFalseType } from '../../types/items';
import { MeterData, MeterTimeSortType, MeterType } from '../../types/redux/meters';
import { UnitRepresentType } from '../../types/redux/units';
import { GPSPoint, isValidGPSInput } from '../../utils/calibration';
import { GPSPoint, isValidGPSInputNew } from '../../utils/calibration';
import { AreaUnitType } from '../../utils/getAreaUnitConversion';
import { getGPSString, nullToEmptyString } from '../../utils/input';
import { showErrorNotification } from '../../utils/notifications';
Expand Down Expand Up @@ -105,7 +105,8 @@ export default function EditMeterModalComponent(props: EditMeterModalComponentPr
// If the user input a value then gpsInput should be a string.
// null came from the DB and it is okay to just leave it - Not a string.
if (typeof gpsInput === 'string') {
if (isValidGPSInput(gpsInput)) {
const {validGps, message} = isValidGPSInputNew(gpsInput);
if (validGps) {
// Clearly gpsInput is a string but TS complains about the split so cast.
const gpsValues = (gpsInput as string).split(',').map((value: string) => parseFloat(value));
// It is valid and needs to be in this format for routing.
Expand All @@ -116,9 +117,7 @@ export default function EditMeterModalComponent(props: EditMeterModalComponentPr
// gpsInput must be of type string but TS does not think so so cast.
} else if ((gpsInput as string).length !== 0) {
// GPS not okay.
// TODO isValidGPSInput currently tops up an alert so not doing it here, may change
// so leaving code commented out.
// showErrorNotification(translate('input.gps.range') + state.gps + '.');
showErrorNotification(message);
inputOk = false;
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/client/app/utils/calibration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ export interface Dimensions {
export function itemMapInfoOk(itemID: number, type: DataType, map: MapMetadata, gps?: GPSPoint): boolean {
if (map === undefined) { return false; }
if ((gps === null || gps === undefined) || map.origin === undefined || map.opposite === undefined) { return false; }
if (!isValidGPSInput(`${gps.latitude},${gps.longitude}`)) {
const {validGps} = isValidGPSInputNew(`${gps.latitude},${gps.longitude}`);
if (!validGps) {
logToServer('error', `Found invalid ${type === DataType.Meter ? 'meter' : 'group'} gps stored in database, id = ${itemID}`)();
return false;
}
Expand Down

0 comments on commit eb66706

Please sign in to comment.