Skip to content

Commit 1ff85ce

Browse files
authored
Merge pull request #1 from dawalberto/develop
Additional settings feature
2 parents 64dad63 + dd08dcc commit 1ff85ce

File tree

4 files changed

+54
-17
lines changed

4 files changed

+54
-17
lines changed

src/components/AdditionalSettings.tsx

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { useCallback, useState } from 'react'
2+
import { BMRSelector } from './BMRSelector'
3+
import { LBMSelector } from './LBMSelector'
4+
5+
export const AdditionalSettings = () => {
6+
const [showMore, setShowMore] = useState(false)
7+
8+
const handleOnClick = useCallback(() => {
9+
setShowMore((shown) => !shown)
10+
window.scrollTo({
11+
top: document.documentElement.scrollHeight,
12+
behavior: 'smooth',
13+
})
14+
}, [])
15+
16+
return (
17+
<div className='mt-6 w-full'>
18+
<button
19+
onClick={handleOnClick}
20+
className='mx-auto block w-full rounded-sm bg-amber-400 px-4 py-2 text-center text-amber-950 shadow-md hover:shadow-lg active:border-amber-500 active:shadow-none active:ring-amber-500'
21+
>
22+
Additional settings 👇
23+
</button>
24+
{showMore && (
25+
<div className='mt-6 flex flex-col gap-6'>
26+
<div>
27+
<LBMSelector />
28+
</div>
29+
<div>
30+
<BMRSelector />
31+
</div>
32+
</div>
33+
)}
34+
</div>
35+
)
36+
}

src/components/BMRSelector.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
import { defaultBMREquation } from '@lib/defaults'
1+
import { useStore } from '@nanostores/react'
2+
import { $userAttributes } from '@store/user-attributes'
23
import { selectStyles } from '@styles/selects'
34
import { calculateAndUpdateBMR } from '@utils/bmr-functions'
45
import clsx from 'clsx'
56
import type { BMREquation } from 'src/types'
67

78
export const BMRSelector = () => {
9+
const { bmrAndExercise } = useStore($userAttributes)
10+
811
const handleBMREquationChange = (event: React.ChangeEvent<HTMLSelectElement>) => {
912
const equation: BMREquation = event.target.value as unknown as BMREquation
1013
calculateAndUpdateBMR({ equation })
@@ -18,7 +21,7 @@ export const BMRSelector = () => {
1821
<select
1922
id='BMREquation'
2023
name='BMREquation'
21-
defaultValue={defaultBMREquation}
24+
defaultValue={bmrAndExercise.equation}
2225
onChange={handleBMREquationChange}
2326
className={clsx(selectStyles, 'border-amber-300 bg-amber-50 text-amber-900 focus:border-amber-500 focus:ring-amber-500')}
2427
>

src/components/LBMSelector.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
import { defaultLBMFormula } from '@lib/defaults'
1+
import { useStore } from '@nanostores/react'
2+
import { $userAttributes } from '@store/user-attributes'
23
import { selectStyles } from '@styles/selects'
34
import { calculateAndUpdateLBM } from '@utils/lbm-functions'
45
import clsx from 'clsx'
56
import { useCallback, useState } from 'react'
67
import type { LBMFormula } from 'src/types'
78

89
export const LBMSelector = () => {
9-
const [showManualLBMInput, setShowManualLBMInput] = useState(false)
10+
const { lbm } = useStore($userAttributes)
11+
const [showManualLBMInput, setShowManualLBMInput] = useState(lbm.formula === 'Manual')
1012

1113
const handleLBMFormulaChange = useCallback((event: React.ChangeEvent<HTMLSelectElement>) => {
1214
const formula: LBMFormula = event.target.value as unknown as LBMFormula
@@ -30,7 +32,7 @@ export const LBMSelector = () => {
3032
<select
3133
id='LBMFormula'
3234
name='LBMFormula'
33-
defaultValue={defaultLBMFormula}
35+
defaultValue={lbm.formula}
3436
onChange={handleLBMFormulaChange}
3537
className={clsx(
3638
selectStyles,
@@ -47,10 +49,11 @@ export const LBMSelector = () => {
4749
type='number'
4850
name='manualLBMInput'
4951
onChange={handleManualLBMInputChange}
52+
defaultValue={lbm.lbmKg}
5053
placeholder='LBM in Kg'
5154
className={clsx(
5255
showManualLBMInput ? 'block w-2/5' : 'hidden',
53-
'block h-10 max-h-12 min-h-9 rounded-none border border-lime-300 bg-lime-50 p-2.5 text-sm text-lime-900 focus:border-lime-500 focus:ring-lime-500'
56+
'block h-10 max-h-12 min-h-9 rounded-none border border-lime-300 bg-lime-50 p-2.5 text-sm text-lime-900 shadow-md focus:border-lime-500 focus:ring-lime-500'
5457
)}
5558
/>
5659
</div>

src/pages/index.astro

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
---
2-
import { BMRSelector } from '@components/BMRSelector'
2+
import { AdditionalSettings } from '@components/AdditionalSettings'
33
import ChartMacros from '@components/ChartMacros.astro'
44
import { Dashboard } from '@components/Dashboard'
55
import { ExerciseMultiplier } from '@components/ExerciseMultiplier'
66
import { GoalSelector } from '@components/GoalSelector'
7-
import { LBMSelector } from '@components/LBMSelector'
87
import '@styles/selects.css'
98
---
109

@@ -26,28 +25,24 @@ import '@styles/selects.css'
2625
<meta name='language' content='English' />
2726
<meta name='author' content='Alberto García Sola' />
2827
</head>
29-
<body class='mx-auto mt-4 w-full max-w-screen-xl p-2'>
28+
<body class='mx-auto mt-4 w-full max-w-screen-xl p-2 text-slate-700'>
3029
<div class='mx-auto lg:w-1/2 xl:w-[40%] 2xl:w-1/3'>
3130
<div class='flex flex-col gap-6'>
3231
<div>
3332
<Dashboard client:load />
3433
</div>
35-
<div>
36-
<GoalSelector client:load />
37-
</div>
3834
<div>
3935
<ExerciseMultiplier client:load />
4036
</div>
4137
<div>
42-
<ChartMacros />
43-
</div>
44-
<div>
45-
<LBMSelector client:load />
38+
<GoalSelector client:load />
4639
</div>
4740
<div>
48-
<BMRSelector client:load />
41+
<ChartMacros />
4942
</div>
43+
<AdditionalSettings client:load />
5044
</div>
45+
<!-- <Development client:load /> -->
5146
</div>
5247
</body>
5348
</html>

0 commit comments

Comments
 (0)