From 9d3bea9f3ecb2da4563a8cf7f444f478f88e9c38 Mon Sep 17 00:00:00 2001 From: Ashutosh Bishnoi Date: Mon, 15 Feb 2021 12:35:02 +0530 Subject: More Code Improvements --- modern/src/common/converter.js | 34 +++++++++++++-------------------- modern/src/settings/MaintenancePage.js | 12 +++--------- modern/src/settings/MaintenancesPage.js | 2 +- 3 files changed, 17 insertions(+), 31 deletions(-) (limited to 'modern/src') diff --git a/modern/src/common/converter.js b/modern/src/common/converter.js index 26e2a82b..9cdc6239 100644 --- a/modern/src/common/converter.js +++ b/modern/src/common/converter.js @@ -1,47 +1,39 @@ -const speedConverter = (value, unit, back = false) => { - let factor; +const speedConverter = unit => { switch (unit) { case 'kmh': - factor = 1.852; - break; + return 1.852; case 'mph': - factor = 1.15078; - break; + return 1.15078; case 'kn': default: - factor = 1; + return 1; } - return back ? value / factor: value * factor; }; -const distanceConverter = (value, unit, back = false) => { - let factor; +const distanceConverter = unit => { switch (unit) { case 'mi': - factor = 0.000621371; - break; + return 0.000621371; case 'nmi': - factor = 0.000539957; - break; + return 0.000539957; case 'km': default: - factor = 0.001; - } - return back ? value / factor : value * factor; + return 0.001; + } } export const speedFromKnots = (value, unit) => { - return speedConverter(value, unit); + return value * speedConverter(unit); } export const speedToKnots = (value, unit) => { - return speedConverter(value, unit, true); + return value / speedConverter(unit); } export const distanceFromMeters = (value, unit) => { - return distanceConverter(value, unit); + return value * distanceConverter(unit); } export const distanceToMeters = (value, unit) => { - return distanceConverter(value, unit, true); + return value / distanceConverter(unit); } diff --git a/modern/src/settings/MaintenancePage.js b/modern/src/settings/MaintenancePage.js index 5ac98c93..9263ee30 100644 --- a/modern/src/settings/MaintenancePage.js +++ b/modern/src/settings/MaintenancePage.js @@ -38,7 +38,7 @@ const MaintenancePage = () => { const onMaintenanceTypeChange = event => { const newValue = event.target.value; - setItem({...item, type: newValue, start: 0, period: 0}); + setItem({ ...item, type: newValue, start: 0, period: 0 }); const attribute = positionAttributes[newValue]; if (attribute && attribute.dataType) { @@ -55,7 +55,7 @@ const MaintenancePage = () => { } } - const rawToValue = (value) => { + const rawToValue = value => { const attribute = positionAttributes[item.type]; if (attribute && attribute.dataType) { @@ -64,15 +64,12 @@ const MaintenancePage = () => { return speedFromKnots(value, speedUnit); case 'distance': return distanceFromMeters(value, distanceUnit); - default: - return value; } } - return value; } - const valueToRaw = (value) => { + const valueToRaw = value => { const attribute = positionAttributes[item.type]; if (attribute && attribute.dataType) { @@ -81,11 +78,8 @@ const MaintenancePage = () => { return speedToKnots(value, speedUnit); case 'distance': return distanceToMeters(value, distanceUnit); - default: - return value; } } - return value; } diff --git a/modern/src/settings/MaintenancesPage.js b/modern/src/settings/MaintenancesPage.js index 5e74e5a6..7ba4bd29 100644 --- a/modern/src/settings/MaintenancesPage.js +++ b/modern/src/settings/MaintenancesPage.js @@ -63,7 +63,7 @@ const MaintenancesView = ({ updateTimestamp, onMenuClick }) => { {items.map(item => ( - onMenuClick(event.currentTarget, item.id)}> + onMenuClick(event.currentTarget, item.id)}> -- cgit v1.2.3