Skip to content

Commit a86a249

Browse files
committed
Add height in cm
1 parent e49a7b0 commit a86a249

File tree

1 file changed

+28
-6
lines changed

1 file changed

+28
-6
lines changed

web/components/optional-profile-form.tsx

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -459,13 +459,12 @@ export const OptionalProfileUserForm = (props: {
459459
setHeightFeet(undefined)
460460
} else {
461461
setHeightFeet(Number(e.target.value))
462-
const heightInInches =
463-
Number(e.target.value) * 12 + (heightInches ?? 0)
462+
const heightInInches = Number(e.target.value) * 12 + (heightInches ?? 0)
464463
setProfile('height_in_inches', heightInInches)
465464
}
466465
}}
467466
className={'w-16'}
468-
value={heightFeet ?? ''}
467+
value={heightFeet ? Math.floor(heightFeet) : ''}
469468
/>
470469
</Col>
471470
<Col>
@@ -477,13 +476,36 @@ export const OptionalProfileUserForm = (props: {
477476
setHeightInches(undefined)
478477
} else {
479478
setHeightInches(Number(e.target.value))
480-
const heightInInches =
481-
Number(e.target.value) + 12 * (heightFeet ?? 0)
479+
const heightInInches = Number(e.target.value) + 12 * (heightFeet ?? 0)
482480
setProfile('height_in_inches', heightInInches)
483481
}
484482
}}
485483
className={'w-16'}
486-
value={heightInches ?? ''}
484+
value={heightInches ? Math.floor(heightInches) : ''}
485+
/>
486+
</Col>
487+
<div className="self-end mb-2 text-ink-700 mx-2">OR</div>
488+
<Col>
489+
<span>Centimeters</span>
490+
<Input
491+
type="number"
492+
onChange={(e) => {
493+
if (e.target.value === '') {
494+
setHeightFeet(undefined)
495+
setHeightInches(undefined)
496+
setProfile('height_in_inches', null)
497+
} else {
498+
// Convert cm to inches
499+
const totalInches = Number(e.target.value) / 2.54
500+
setHeightFeet(Math.floor(totalInches / 12))
501+
setHeightInches(totalInches % 12)
502+
setProfile('height_in_inches', totalInches)
503+
}
504+
}}
505+
className={'w-20'}
506+
value={heightFeet !== undefined && heightInches !== undefined
507+
? Math.round((heightFeet * 12 + heightInches) * 2.54)
508+
: ''}
487509
/>
488510
</Col>
489511
</Row>

0 commit comments

Comments
 (0)