aboutsummaryrefslogtreecommitdiff
path: root/modern/src/common
diff options
context:
space:
mode:
Diffstat (limited to 'modern/src/common')
-rw-r--r--modern/src/common/formatter.js17
-rw-r--r--modern/src/common/usePersistedState.js6
2 files changed, 16 insertions, 7 deletions
diff --git a/modern/src/common/formatter.js b/modern/src/common/formatter.js
index e937165..5db7a42 100644
--- a/modern/src/common/formatter.js
+++ b/modern/src/common/formatter.js
@@ -1,7 +1,10 @@
import moment from 'moment';
-import t from '../LocalizationProvider';
+import { useTranslation } from '../LocalizationProvider';
-export const formatBoolean = (value) => (value ? t('sharedYes') : t('sharedNo'));
+export const formatBoolean = (value) => {
+ const t = useTranslation();
+ return value ? t('sharedYes') : t('sharedNo');
+}
export const formatNumber = (value, precision = 1) => Number(value.toFixed(precision));
@@ -36,6 +39,7 @@ export const formatPosition = (value, key) => {
};
export const formatDistance = (value, unit) => {
+ const t = useTranslation();
switch (unit) {
case 'mi':
return `${(value * 0.000621371).toFixed(2)} ${t('sharedMi')}`;
@@ -48,6 +52,7 @@ export const formatDistance = (value, unit) => {
};
export const formatSpeed = (value, unit) => {
+ const t = useTranslation();
switch (unit) {
case 'kmh':
return `${(value * 1.852).toFixed(2)} ${t('sharedKmh')}`;
@@ -60,6 +65,7 @@ export const formatSpeed = (value, unit) => {
};
export const formatVolume = (value, unit) => {
+ const t = useTranslation();
switch (unit) {
case 'impGal':
return `${(value / 4.546).toFixed(2)} ${t('sharedGallonAbbreviation')}`;
@@ -74,8 +80,11 @@ export const formatVolume = (value, unit) => {
export const formatHours = (value) => moment.duration(value).humanize();
export const formatCoordinate = (key, value, unit) => {
- let hemisphere; let degrees; let minutes; let
- seconds;
+ let hemisphere;
+ let degrees;
+ let minutes;
+ let seconds;
+
if (key === 'latitude') {
hemisphere = value >= 0 ? 'N' : 'S';
} else {
diff --git a/modern/src/common/usePersistedState.js b/modern/src/common/usePersistedState.js
index 0a6627c..a3a60d7 100644
--- a/modern/src/common/usePersistedState.js
+++ b/modern/src/common/usePersistedState.js
@@ -1,13 +1,13 @@
-import { useState } from 'react';
+import { useEffect, useState } from 'react';
-export default usePersistedState = (key, defaultValue) => {
+export const usePersistedState = (key, defaultValue) => {
const [value, setValue] = useState(() => {
const stickyValue = window.localStorage.getItem(key);
return stickyValue ? JSON.parse(stickyValue) : defaultValue;
});
- React.useEffect(() => {
+ useEffect(() => {
window.localStorage.setItem(key, JSON.stringify(value));
}, [key, value]);