Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
F
FitUrRing
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
wss9
FitUrRing
Commits
a178d2ef
Commit
a178d2ef
authored
5 months ago
by
문경호
Browse files
Options
Downloads
Patches
Plain Diff
Fix: Fix BmrDisplay and Weight
parent
6c121303
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
front/src/pages/diet/BmrDisplay.jsx
+27
-12
27 additions, 12 deletions
front/src/pages/diet/BmrDisplay.jsx
front/src/pages/diet/WeightBar.css
+11
-0
11 additions, 0 deletions
front/src/pages/diet/WeightBar.css
front/src/pages/diet/WeightBar.jsx
+49
-19
49 additions, 19 deletions
front/src/pages/diet/WeightBar.jsx
with
87 additions
and
31 deletions
front/src/pages/diet/BmrDisplay.jsx
+
27
−
12
View file @
a178d2ef
import
NutrientDisplay
from
'
./NutrientDisplay
'
;
import
React
,
{
useEffect
,
useState
}
from
'
react
'
;
import
{
getUserData
}
from
'
./api
'
;
import
'
./BmrDisplay.css
'
;
function
BmrDisplay
({
user
,
diet
,
activity
})
{
const
[
bmr
,
setBmr
]
=
useState
(
0
);
const
[
achievement
,
setAchievement
]
=
useState
([]);
const
[
userInfo
,
setUserInfo
]
=
useState
([]);
const
[
constants
]
=
useState
([
1.2
,
1.375
,
1.555
,
1.725
,
1.9
]);
useEffect
(()
=>
{
for
(
let
i
=
0
;
i
<
diet
.
length
;
i
++
)
{
if
(
diet
[
i
])
{
setAchievement
(
diet
[
i
].
achievement
);
break
;
const
fetchUserInfo
=
async
()
=>
{
try
{
const
data
=
await
getUserData
();
setUserInfo
(
data
);
}
catch
(
error
){
console
.
error
(
'
Error fetching user info:
'
,
error
);
}
}
},[
diet
]);
};
fetchUserInfo
();
},
[]);
const
calculateBmr
=
()
=>
{
if
(
user
.
user_gender
===
1
)
{
return
66.47
+
(
13.75
*
achievement
.
weight
)
+
(
5
*
achievement
.
height
)
-
(
6.76
*
user
.
user_birth
);
if
(
!
userInfo
.
user_gender
||
!
userInfo
.
user_weight
||
!
userInfo
.
user_height
||
!
userInfo
.
user_birth
)
{
return
0
;
}
const
today
=
new
Date
();
const
birthYear
=
new
Date
(
userInfo
.
user_birth
).
getFullYear
();
const
age
=
today
.
getFullYear
()
-
birthYear
;
if
(
userInfo
.
user_gender
===
1
)
{
return
66.47
+
(
13.75
*
userInfo
.
user_weight
)
+
(
5
*
userInfo
.
user_height
)
-
(
6.76
*
age
);
}
else
{
return
655.1
+
(
9.56
*
achievement
.
weight
)
+
(
1.85
*
achievement
.
height
)
-
(
4.68
*
user
.
user_birth
);
return
655.1
+
(
9.56
*
userInfo
.
user_
weight
)
+
(
1.85
*
userInfo
.
user_
height
)
-
(
4.68
*
age
);
}
};
useEffect
(()
=>
{
const
calculatedBmr
=
calculateBmr
();
if
(
!
isNaN
(
calculatedBmr
))
{
setBmr
(
Math
.
round
(
calculatedBmr
));
});
}
},
[
userInfo
]);
return
(
<
React
.
Fragment
>
...
...
This diff is collapsed.
Click to expand it.
front/src/pages/diet/WeightBar.css
+
11
−
0
View file @
a178d2ef
...
...
@@ -73,3 +73,14 @@
text-align
:
right
;
color
:
#000000
;
}
.suchi
input
{
width
:
50px
;
text-align
:
right
;
padding
:
2px
5px
;
margin-right
:
5px
;
}
.suchi
span
{
cursor
:
pointer
;
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
front/src/pages/diet/WeightBar.jsx
+
49
−
19
View file @
a178d2ef
import
React
,
{
useState
,
useEffect
}
from
'
react
'
;
import
'
./WeightBar.css
'
import
{
getUserData
,
getWeightHistory
}
from
'
./api
'
;
function
WeightBar
({
diet
})
{
const
[
percentage
,
setPercentage
]
=
useState
(
0
);
const
[
goalweight
,
setGoalWeight
]
=
useState
(
0
);
const
[
startweight
,
setStartWeight
]
=
useState
(
0
);
const
[
goalWeight
,
setGoalWeight
]
=
useState
(
''
);
const
[
userInfo
,
setUserInfo
]
=
useState
(
null
);
const
[
weightHistory
,
setWeightHistory
]
=
useState
([]);
const
[
isEditing
,
setIsEditing
]
=
useState
(
false
);
useEffect
(()
=>
{
let
goal_weight
=
-
1
;
let
current_weight
=
-
1
;
let
start_weight
;
if
(
diet
&&
diet
.
array
)
{
diet
.
array
.
forEach
(
element
=>
{
if
(
element
.
achievement
.
weight
)
start_weight
=
element
.
achievement
.
weight
;
if
(
goal_weight
==
-
1
&&
element
.
achievement
.
goal_weight
)
goal_weight
=
element
.
achievement
.
goal_weight
;
if
(
current_weight
==
-
1
&&
element
.
achievement
.
weight
)
current_weight
=
element
.
achievement
.
weight
});
setPercentage
(((
start_weight
-
current_weight
)
/
((
start_weight
-
goal_weight
)
+
0.01
)
*
100
));
setGoalWeight
(
goal_weight
);
setStartWeight
(
start_weight
);
const
fetchData
=
async
()
=>
{
try
{
const
userData
=
await
getUserData
();
const
weightHistoryData
=
await
getWeightHistory
();
setUserInfo
(
userData
);
setWeightHistory
(
weightHistoryData
);
if
(
userData
.
user_weight
&&
goalWeight
)
{
const
startWeight
=
weightHistory
[
0
]?.
weight
||
userData
.
user_weight
;
const
currentWeight
=
userData
.
user_weight
;
const
progress
=
((
startWeight
-
currentWeight
)
/
(
startWeight
-
goalWeight
))
*
100
;
setPercentage
(
Math
.
min
(
Math
.
max
(
progress
,
0
),
100
));
}
}
catch
(
error
)
{
console
.
error
(
'
데이터를 가져오는데 실패했습니다:
'
,
error
);
}
},
[
diet
]);
};
fetchData
();
},
[
goalWeight
]);
const
handleGoalWeightSubmit
=
(
e
)
=>
{
e
.
preventDefault
();
setIsEditing
(
false
);
};
return
(
<
div
className
=
'WeightBar-container'
>
<
h3
>
체중 목표
</
h3
>
<
div
className
=
"weight-bar"
>
<
div
className
=
'per'
>
{
percentage
}
%
</
div
>
<
div
className
=
'per'
>
{
percentage
.
toFixed
(
1
)
}
%
</
div
>
<
div
className
=
"bar"
>
<
div
className
=
"bar-progress"
style
=
{
{
width
:
`
${
percentage
}
%`
}
}
></
div
>
</
div
>
<
div
className
=
'suchi'
>
<
span
>
{
startweight
}
kg
</
span
>
<
span
>
{
goalweight
}
kg
</
span
>
<
span
>
{
weightHistory
[
0
]?.
weight
||
userInfo
?.
user_weight
}
kg
</
span
>
{
isEditing
?
(
<
form
onSubmit
=
{
handleGoalWeightSubmit
}
>
<
input
type
=
"number"
value
=
{
goalWeight
}
onChange
=
{
(
e
)
=>
setGoalWeight
(
e
.
target
.
value
)
}
onBlur
=
{
()
=>
setIsEditing
(
false
)
}
autoFocus
/>
<
span
>
kg
</
span
>
</
form
>
)
:
(
<
span
onClick
=
{
()
=>
setIsEditing
(
true
)
}
>
{
goalWeight
?
`
${
goalWeight
}
kg`
:
'
목표 체중 설정
'
}
</
span
>
)
}
</
div
>
</
div
>
</
div
>
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment