Skip to content

Commit 3703d6e

Browse files
Merge pull request #140 from ViktorSvertoka/Dima_Diary
2 parents cbf955a + e0a974f commit 3703d6e

File tree

5 files changed

+43
-10
lines changed

5 files changed

+43
-10
lines changed

src/components/DailyStatsCards/DailyStatsCards.jsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,15 @@ const DailyStatsCards = ({
2626
<Label>{label}</Label>
2727
</KeyWrap>
2828

29-
<KeyValue>{keyValue}</KeyValue>
29+
<KeyValue>{String(keyValue)}</KeyValue>
3030
</CardWrap>
3131
);
3232
};
3333

3434
DailyStatsCards.propTypes = {
3535
icon: PropTypes.string.isRequired,
36-
keyValue: PropTypes.string.isRequired,
36+
keyValue: PropTypes.oneOfType([PropTypes.string, PropTypes.number])
37+
.isRequired,
3738
label: PropTypes.string.isRequired,
3839
border: PropTypes.oneOf(['green', 'red', 'default']),
3940
fill: PropTypes.oneOf(['true', 'false']),

src/components/DairyStatisticList/DairyStatisticList.jsx

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,40 @@ import { List } from './DairyStatisticList.styled';
22
import DailyStatsCards from '../DailyStatsCards/DailyStatsCards';
33
import { useSelector } from 'react-redux';
44
import { selectUser } from '../../redux/auth/selectors';
5+
import {
6+
getBurnedCalories,
7+
getCalories,
8+
getDoneExercisesTime,
9+
} from '../../redux/diary/selectors';
510

611
const DairyStatisticList = () => {
712
const user = useSelector(selectUser);
13+
const consumedCalories = useSelector(getCalories);
14+
const doneExercisesTime = useSelector(getDoneExercisesTime);
15+
const burnedCalories = useSelector(getBurnedCalories);
16+
17+
const defaultDayTime = 110;
18+
const bmr = user.bmr;
19+
const restCalories = bmr - consumedCalories;
20+
21+
function secondsToMinutesAndSeconds(seconds) {
22+
const minutes = Math.floor(seconds / 60);
23+
const remainingSeconds = seconds % 60;
24+
25+
return { minutes, seconds: remainingSeconds };
26+
}
27+
28+
const totalMinutes = doneExercisesTime / 60;
29+
const result = secondsToMinutesAndSeconds(totalMinutes * 60);
30+
let resultTime = defaultDayTime - result.minutes;
831

932
return (
1033
<List>
1134
<DailyStatsCards
1235
icon="icon-fork-knife"
1336
fill="true"
1437
label="Daily calorie intake"
15-
keyValue={user.bmr !== undefined ? String(user.bmr) : '2200'}
38+
keyValue={bmr !== undefined ? String(bmr) : '2200'}
1639
></DailyStatsCards>
1740
<DailyStatsCards
1841
icon="icon-dumbbell"
@@ -23,22 +46,26 @@ const DairyStatisticList = () => {
2346
<DailyStatsCards
2447
icon="icon-apple"
2548
label="Сalories consumed"
26-
keyValue={'0'}
49+
keyValue={
50+
consumedCalories !== undefined ? String(consumedCalories) : '0'
51+
}
2752
></DailyStatsCards>
2853
<DailyStatsCards
2954
icon="icon-fire"
3055
label="Сalories burned"
31-
keyValue={'0'}
56+
keyValue={burnedCalories}
3257
></DailyStatsCards>
3358
<DailyStatsCards
3459
icon="icon-bubble"
3560
label="The rest of the calories"
36-
keyValue={'2200'}
61+
keyValue={restCalories !== undefined ? String(restCalories) : '0'}
62+
border={restCalories < 0 ? 'red' : 'green'}
3763
></DailyStatsCards>
3864
<DailyStatsCards
3965
icon="icon-running-figure"
4066
label="The rest of sports"
41-
keyValue={'110 min'}
67+
keyValue={resultTime !== undefined ? String(resultTime) + ' min' : '0'}
68+
border={resultTime > defaultDayTime ? 'green' : 'default'}
4269
></DailyStatsCards>
4370
</List>
4471
);

src/components/DiaryTable/DiaryTable.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ const TableForDiary = ({
6767
<Cell>{item.amount}</Cell>
6868
<Cell>
6969
<BeforeForCell
70-
bgcolor={item.recommend ? '#419B09' : '#E9101D'}
70+
bgcolor={item.recommended ? '#419B09' : '#E9101D'}
7171
/>
72-
{item.recommend ? 'Yes' : 'No'}
72+
{item.recommended ? 'Yes' : 'No'}
7373
</Cell>
7474
<Cell>
7575
<DeleteBtn onClick={() => onDelete({ id: item._id })}>

src/redux/diary/operations.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ export const deleteProduct = createAsyncThunk(
5454
'deleteProduct',
5555
async (productDetails, { rejectWithValue }) => {
5656
const { id, date } = productDetails;
57-
console.log('productDetailsDELETE', productDetails);
5857

5958
try {
6059
await axios.delete(`/diary/deleteproduct?id=${id}&date=${date}`);

src/redux/diary/selectors.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ export const getDiaryExercises = state => state.diary.exercises;
44

55
export const getIsLoadingDiary = state => state.diary.isLoading;
66

7+
export const getCalories = state => state.diary.consumedCalories;
8+
9+
export const getDoneExercisesTime = state => state.diary.doneExercisesTime;
10+
11+
export const getBurnedCalories = state => state.diary.burnedCalories;
12+
713
export const getError = state => state.diary.error;
814

915
export const getErrorProductsAndExercisesError = state =>

0 commit comments

Comments
 (0)