Skip to content

Commit d2d1540

Browse files
authored
Merge pull request #521 from LiamMorrow/fix-decimals
2 parents 3740ab7 + 68f365d commit d2d1540

12 files changed

Lines changed: 79 additions & 15 deletions

app/app.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@
3232
"project": "app",
3333
"organization": "liftlog"
3434
}
35-
]
35+
],
36+
"expo-localization"
3637
],
3738
"experiments": {
3839
"typedRoutes": true,

app/components/presentation/bodyweight-stat-graph-card.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,5 @@ export default function BodyweightStatGraphCard(props: {
5858
* @param value
5959
*/
6060
function formatNumber(value: number) {
61-
return value % 1 === 0 ? value.toString() : value.toFixed(2);
61+
return value.toLocaleString(undefined, { maximumFractionDigits: 2 });
6262
}

app/components/presentation/editable-incrementer.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
import {
2+
localeFormatBigNumber,
3+
localeParseBigNumber,
4+
} from '@/utils/locale-bignumber';
15
import BigNumber from 'bignumber.js';
26
import { useEffect, useState } from 'react';
37
import { View } from 'react-native';
@@ -14,7 +18,7 @@ interface EditableIncrementerProps {
1418

1519
export default function EditableIncrementer(props: EditableIncrementerProps) {
1620
const { increment, label, value, onChange } = props;
17-
const [text, setText] = useState(props.value.toFormat());
21+
const [text, setText] = useState(localeFormatBigNumber(props.value));
1822
const [editorValue, setEditorValue] = useState<BigNumber>(value);
1923

2024
const handleTextChange = (text: string) => {
@@ -24,14 +28,14 @@ export default function EditableIncrementer(props: EditableIncrementerProps) {
2428
return;
2529
}
2630

27-
const parsed = BigNumber(text);
31+
const parsed = localeParseBigNumber(text);
2832
if (!parsed.isNaN()) {
2933
setEditorValue(parsed);
3034
return;
3135
}
3236
};
3337
useEffect(() => {
34-
setText(value?.toFormat() ?? '');
38+
setText(localeFormatBigNumber(value));
3539
setEditorValue(value);
3640
}, [value]);
3741

app/components/presentation/exercise-stat-graph-card.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,5 +71,5 @@ export default function ExerciseStatGraphCard(props: {
7171
* @param value
7272
*/
7373
function formatNumber(value: number) {
74-
return value % 1 === 0 ? value.toString() : value.toFixed(2);
74+
return value.toLocaleString(undefined, { maximumFractionDigits: 2 });
7575
}

app/components/presentation/exercise-summary.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { SurfaceText } from '@/components/presentation/surface-text';
22
import WeightFormat from '@/components/presentation/weight-format';
33
import { spacing, useAppTheme } from '@/hooks/useAppTheme';
44
import { RecordedExercise } from '@/models/session-models';
5+
import { localeFormatBigNumber } from '@/utils/locale-bignumber';
56
import { DateTimeFormatter } from '@js-joda/core';
67
import BigNumber from 'bignumber.js';
78
import Enumerable from 'linq';
@@ -167,7 +168,7 @@ function getPlannedChipData(
167168
exercise: RecordedExercise,
168169
): PotentialSetChipData[] {
169170
return Enumerable.from(exercise.potentialSets)
170-
.groupBy((x) => x.weight.toString())
171+
.groupBy((x) => localeFormatBigNumber(x.weight))
171172
.select((x) => ({
172173
repTarget: exercise.blueprint.repsPerSet,
173174
numSets: x.count(),

app/components/presentation/weight-dialog.tsx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import WeightFormat from '@/components/presentation/weight-format';
22
import { spacing } from '@/hooks/useAppTheme';
33
import { useWeightSuffix } from '@/hooks/useWeightSuffix';
4+
import {
5+
localeFormatBigNumber,
6+
localeParseBigNumber,
7+
} from '@/utils/locale-bignumber';
48
import { T } from '@tolgee/react';
59
import BigNumber from 'bignumber.js';
610
import { ReactNode, useEffect, useState } from 'react';
@@ -35,14 +39,14 @@ type WeightDialogProps = {
3539

3640
export default function WeightDialog(props: WeightDialogProps) {
3741
const theme = useTheme();
38-
const [text, setText] = useState(props.weight?.toFormat() ?? '');
42+
const [text, setText] = useState(localeFormatBigNumber(props.weight));
3943
const [editorWeight, setEditorWeight] = useState<BigNumber | undefined>(
4044
props.weight,
4145
);
4246
const weightSuffix = useWeightSuffix();
4347

4448
useEffect(() => {
45-
setText(props.weight?.toFormat() ?? '');
49+
setText(localeFormatBigNumber(props.weight));
4650
setEditorWeight(props.weight);
4751
}, [props.open, props.weight, setText]);
4852

@@ -55,14 +59,14 @@ export default function WeightDialog(props: WeightDialogProps) {
5559
return;
5660
}
5761
setEditorWeight(editorWeight.plus(nonZeroIncrement));
58-
setText(editorWeight.plus(nonZeroIncrement).toFormat());
62+
setText(localeFormatBigNumber(editorWeight.plus(nonZeroIncrement)));
5963
};
6064
const decrementWeight = () => {
6165
if (editorWeight === undefined) {
6266
return;
6367
}
6468
setEditorWeight(editorWeight.minus(nonZeroIncrement));
65-
setText(editorWeight.minus(nonZeroIncrement).toFormat());
69+
setText(localeFormatBigNumber(editorWeight.minus(nonZeroIncrement)));
6670
};
6771

6872
const handleTextChange = (text: string) => {
@@ -72,8 +76,8 @@ export default function WeightDialog(props: WeightDialogProps) {
7276
return;
7377
}
7478

75-
if (!BigNumber(text).isNaN()) {
76-
setEditorWeight(new BigNumber(text));
79+
if (!localeParseBigNumber(text).isNaN()) {
80+
setEditorWeight(localeParseBigNumber(text));
7781
return;
7882
}
7983
};

app/components/presentation/weight-format.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
useAppTheme,
66
} from '@/hooks/useAppTheme';
77
import { useWeightSuffix } from '@/hooks/useWeightSuffix';
8+
import { localeFormatBigNumber } from '@/utils/locale-bignumber';
89
import BigNumber from 'bignumber.js';
910
import { Text, TextStyle } from 'react-native';
1011

@@ -16,7 +17,8 @@ interface WeightFormatProps {
1617
fontWeight?: TextStyle['fontWeight'];
1718
}
1819
export default function WeightFormat(props: WeightFormatProps) {
19-
const weightDisplay = props.weight?.decimalPlaces(4).toFormat() ?? '-';
20+
const weightDisplay =
21+
localeFormatBigNumber(props.weight?.decimalPlaces(4)) || '-';
2022
const suffix = useWeightSuffix();
2123
const { colors } = useAppTheme();
2224

app/ios/LiftLog.xcodeproj/project.pbxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@
291291
"${PODS_CONFIGURATION_BUILD_DIR}/EXConstants/ExpoConstants_privacy.bundle",
292292
"${PODS_CONFIGURATION_BUILD_DIR}/EXNotifications/ExpoNotifications_privacy.bundle",
293293
"${PODS_CONFIGURATION_BUILD_DIR}/ExpoFileSystem/ExpoFileSystem_privacy.bundle",
294+
"${PODS_CONFIGURATION_BUILD_DIR}/ExpoLocalization/ExpoLocalization_privacy.bundle",
294295
"${PODS_CONFIGURATION_BUILD_DIR}/PurchasesHybridCommon/PurchasesHybridCommon.bundle",
295296
"${PODS_CONFIGURATION_BUILD_DIR}/RCT-Folly/RCT-Folly_privacy.bundle",
296297
"${PODS_CONFIGURATION_BUILD_DIR}/RNPermissions/RNPermissionsPrivacyInfo.bundle",
@@ -312,6 +313,7 @@
312313
"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/ExpoConstants_privacy.bundle",
313314
"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/ExpoNotifications_privacy.bundle",
314315
"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/ExpoFileSystem_privacy.bundle",
316+
"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/ExpoLocalization_privacy.bundle",
315317
"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/PurchasesHybridCommon.bundle",
316318
"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/RCT-Folly_privacy.bundle",
317319
"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/RNPermissionsPrivacyInfo.bundle",

app/ios/Podfile.lock

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,8 @@ PODS:
290290
- ExpoModulesCore
291291
- ExpoLinking (7.1.7):
292292
- ExpoModulesCore
293+
- ExpoLocalization (16.1.6):
294+
- ExpoModulesCore
293295
- ExpoModulesCore (2.5.0):
294296
- DoubleConversion
295297
- glog
@@ -2489,6 +2491,7 @@ DEPENDENCIES:
24892491
- ExpoKeepAwake (from `../node_modules/expo-keep-awake/ios`)
24902492
- ExpoLinearGradient (from `../node_modules/expo-linear-gradient/ios`)
24912493
- ExpoLinking (from `../node_modules/expo-linking/ios`)
2494+
- ExpoLocalization (from `../node_modules/expo-localization/ios`)
24922495
- ExpoModulesCore (from `../node_modules/expo-modules-core`)
24932496
- ExpoSharing (from `../node_modules/expo-sharing/ios`)
24942497
- ExpoSplashScreen (from `../node_modules/expo-splash-screen/ios`)
@@ -2630,6 +2633,8 @@ EXTERNAL SOURCES:
26302633
:path: "../node_modules/expo-linear-gradient/ios"
26312634
ExpoLinking:
26322635
:path: "../node_modules/expo-linking/ios"
2636+
ExpoLocalization:
2637+
:path: "../node_modules/expo-localization/ios"
26332638
ExpoModulesCore:
26342639
:path: "../node_modules/expo-modules-core"
26352640
ExpoSharing:
@@ -2824,6 +2829,7 @@ SPEC CHECKSUMS:
28242829
ExpoKeepAwake: bf0811570c8da182bfb879169437d4de298376e7
28252830
ExpoLinearGradient: 7734c8059972fcf691fb4330bcdf3390960a152d
28262831
ExpoLinking: d5c183998ca6ada66ff45e407e0f965b398a8902
2832+
ExpoLocalization: 999a1ff61a7f5917d65c2bd9234883009019ca9f
28272833
ExpoModulesCore: 00a1b5c73248465bd0b93f59f8538c4573dac579
28282834
ExpoSharing: b0377be82430d07398c6a4cd60b5a15696accbd3
28292835
ExpoSplashScreen: 0ad5acac1b5d2953c6e00d4319f16d616f70d4dd

app/package-lock.json

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)