diff --git a/src/components/DailyStatsCards/DailyStatsCards.jsx b/src/components/DailyStatsCards/DailyStatsCards.jsx index 9ea0772..b1b2729 100644 --- a/src/components/DailyStatsCards/DailyStatsCards.jsx +++ b/src/components/DailyStatsCards/DailyStatsCards.jsx @@ -26,14 +26,15 @@ const DailyStatsCards = ({ - {keyValue} + {String(keyValue)} ); }; DailyStatsCards.propTypes = { icon: PropTypes.string.isRequired, - keyValue: PropTypes.string.isRequired, + keyValue: PropTypes.oneOfType([PropTypes.string, PropTypes.number]) + .isRequired, label: PropTypes.string.isRequired, border: PropTypes.oneOf(['green', 'red', 'default']), fill: PropTypes.oneOf(['true', 'false']), diff --git a/src/components/DairyStatisticList/DairyStatisticList.jsx b/src/components/DairyStatisticList/DairyStatisticList.jsx index 13325f1..0cd2a65 100644 --- a/src/components/DairyStatisticList/DairyStatisticList.jsx +++ b/src/components/DairyStatisticList/DairyStatisticList.jsx @@ -2,9 +2,32 @@ import { List } from './DairyStatisticList.styled'; import DailyStatsCards from '../DailyStatsCards/DailyStatsCards'; import { useSelector } from 'react-redux'; import { selectUser } from '../../redux/auth/selectors'; +import { + getBurnedCalories, + getCalories, + getDoneExercisesTime, +} from '../../redux/diary/selectors'; const DairyStatisticList = () => { const user = useSelector(selectUser); + const consumedCalories = useSelector(getCalories); + const doneExercisesTime = useSelector(getDoneExercisesTime); + const burnedCalories = useSelector(getBurnedCalories); + + const defaultDayTime = 110; + const bmr = user.bmr; + const restCalories = bmr - consumedCalories; + + function secondsToMinutesAndSeconds(seconds) { + const minutes = Math.floor(seconds / 60); + const remainingSeconds = seconds % 60; + + return { minutes, seconds: remainingSeconds }; + } + + const totalMinutes = doneExercisesTime / 60; + const result = secondsToMinutesAndSeconds(totalMinutes * 60); + let resultTime = defaultDayTime - result.minutes; return ( @@ -12,7 +35,7 @@ const DairyStatisticList = () => { icon="icon-fork-knife" fill="true" label="Daily calorie intake" - keyValue={user.bmr !== undefined ? String(user.bmr) : '2200'} + keyValue={bmr !== undefined ? String(bmr) : '2200'} > { defaultDayTime ? 'green' : 'default'} > ); diff --git a/src/components/DiaryTable/DiaryTable.jsx b/src/components/DiaryTable/DiaryTable.jsx index 69a4895..6b4b925 100644 --- a/src/components/DiaryTable/DiaryTable.jsx +++ b/src/components/DiaryTable/DiaryTable.jsx @@ -67,9 +67,9 @@ const TableForDiary = ({ {item.amount} - {item.recommend ? 'Yes' : 'No'} + {item.recommended ? 'Yes' : 'No'} onDelete({ id: item._id })}> diff --git a/src/redux/diary/operations.js b/src/redux/diary/operations.js index 4a92203..e3f102a 100644 --- a/src/redux/diary/operations.js +++ b/src/redux/diary/operations.js @@ -54,7 +54,6 @@ export const deleteProduct = createAsyncThunk( 'deleteProduct', async (productDetails, { rejectWithValue }) => { const { id, date } = productDetails; - console.log('productDetailsDELETE', productDetails); try { await axios.delete(`/diary/deleteproduct?id=${id}&date=${date}`); diff --git a/src/redux/diary/selectors.js b/src/redux/diary/selectors.js index 419f5f8..6862b99 100644 --- a/src/redux/diary/selectors.js +++ b/src/redux/diary/selectors.js @@ -4,6 +4,12 @@ export const getDiaryExercises = state => state.diary.exercises; export const getIsLoadingDiary = state => state.diary.isLoading; +export const getCalories = state => state.diary.consumedCalories; + +export const getDoneExercisesTime = state => state.diary.doneExercisesTime; + +export const getBurnedCalories = state => state.diary.burnedCalories; + export const getError = state => state.diary.error; export const getErrorProductsAndExercisesError = state =>