-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #89 from Sokilskill/feature/diary
Feature/diary
- Loading branch information
Showing
12 changed files
with
204 additions
and
183 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
91 changes: 91 additions & 0 deletions
91
src/components/DayDashboard/CardDashboard/CardDashboard.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import styled from 'styled-components'; | ||
import { useSelector } from 'react-redux'; | ||
import sprite from '../../../assets/sprite.svg'; | ||
import diarySelectors from '../../../redux/diary/diarySelectors'; | ||
import { | ||
ContentContainerCard, | ||
TitleTextCard, | ||
ValueTextCard, | ||
WrapperTitleCard, | ||
} from '../DayDashboard.styled'; | ||
import MyLoader from '../../Loader/DiaryLoader'; | ||
|
||
const Icon = styled.svg` | ||
&.orange { | ||
fill: ${({ theme }) => theme.secondaryOrange}; | ||
} | ||
`; | ||
|
||
export const Card = ({ value, children }) => { | ||
const isLoading = useSelector(diarySelectors.getIsLoading); | ||
let icon = ''; | ||
let displayValue = value; | ||
|
||
switch (children) { | ||
case 'Daily calorie intake': | ||
icon = ( | ||
<Icon width={20} height={20} className="orange"> | ||
<use href={`${sprite}#icon-fluent_food-24-filled`}></use> | ||
</Icon> | ||
); | ||
break; | ||
case 'Daily physical activity': | ||
icon = ( | ||
<Icon width={20} height={20} className="orange"> | ||
<use href={`${sprite}#icon-dumbbell`}></use> | ||
</Icon> | ||
); | ||
displayValue = displayValue.toString() + ' min'; | ||
|
||
break; | ||
case 'Calories consumed': | ||
icon = ( | ||
<Icon width={20} height={20} className="orange"> | ||
<use href={`${sprite}#icon-apple`}></use> | ||
</Icon> | ||
); | ||
break; | ||
case 'Calories burned': | ||
icon = ( | ||
<Icon width={20} height={20} className="orange"> | ||
<use href={`${sprite}#icon-calories-1`}></use> | ||
</Icon> | ||
); | ||
break; | ||
case 'Calories remaining': | ||
icon = ( | ||
<Icon width={20} height={20} className="orange"> | ||
<use href={`${sprite}#icon-bubble`}></use> | ||
</Icon> | ||
); | ||
break; | ||
case 'Sports remaining': | ||
icon = ( | ||
<Icon width={20} height={20} className="orange"> | ||
<use href={`${sprite}#icon-running`}></use> | ||
</Icon> | ||
); | ||
displayValue = displayValue.toString() + ' min'; | ||
break; | ||
} | ||
if (children === 'Calories remaining' && value < 0) { | ||
displayValue = '- ' + Math.abs(value).toString(); | ||
} | ||
if (children === 'Sports remaining' && value < 0) { | ||
displayValue = '+ ' + Math.abs(value).toString() + ' min'; | ||
} | ||
if (!displayValue) displayValue = 0; | ||
return ( | ||
<ContentContainerCard value={value} title={children}> | ||
<WrapperTitleCard> | ||
{icon} | ||
<TitleTextCard>{children}</TitleTextCard> | ||
</WrapperTitleCard> | ||
{isLoading ? ( | ||
<MyLoader display={'block'} /> | ||
) : ( | ||
<ValueTextCard> {displayValue}</ValueTextCard> | ||
)} | ||
</ContentContainerCard> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,128 +1,40 @@ | ||
import styled from 'styled-components'; | ||
import { | ||
Container, | ||
ContentContainerCard, | ||
WrapperTitleCard, | ||
ValueTextCard, | ||
TitleTextCard, | ||
} from './DayDashboard.styled'; | ||
import { Container } from './DayDashboard.styled'; | ||
|
||
import sprite from '../../assets/sprite.svg'; | ||
import { useSelector } from 'react-redux'; | ||
import diarySelectors from '../../redux/diary/diarySelectors'; | ||
import authSelectors from '../../redux/auth/auth-selectors'; | ||
import MyLoader from '../Loader/DiaryLoader'; | ||
|
||
const Icon = styled.svg` | ||
&.orange { | ||
fill: ${({ theme }) => theme.secondaryOrange}; | ||
} | ||
`; | ||
// import diarySelectors from '../../redux/diary/diarySelectors'; | ||
import { selectTargetBmr } from '../../redux/auth/auth-selectors'; | ||
import { Card } from './CardDashboard/CardDashboard'; | ||
|
||
const DayDashboard = () => { | ||
const userMetricData = useSelector(authSelectors.getUserMetricData); | ||
const targetBmr = Math.ceil(useSelector(selectTargetBmr)); | ||
|
||
const caloriesIntake = userMetricData ? userMetricData.dailyIntakeCalories : null; | ||
const normOfSports = userMetricData ? userMetricData.dailyNormOfSport : null; | ||
const caloriesIntake = targetBmr; | ||
const normOfSports = 110; | ||
|
||
const caloriesConsumed = useSelector( | ||
diarySelectors.getDiary | ||
).consumedCalories; | ||
const caloriesConsumed = 400; | ||
// const caloriesConsumed = useSelector( | ||
// diarySelectors.getDiary | ||
// ).consumedCalories; | ||
|
||
const caloriesBurned = useSelector(diarySelectors.getDiary).burnedCalories; | ||
const caloriesBurned = 500; | ||
// const caloriesBurned = useSelector(diarySelectors.getDiary).burnedCalories; | ||
|
||
const restOfCalories = caloriesIntake - caloriesConsumed; | ||
|
||
const restOfSports = | ||
normOfSports - | ||
Math.ceil(useSelector(diarySelectors.getDiary).sportTime / 60); | ||
const restOfSports = 777; | ||
// normOfSports - | ||
// Math.ceil(useSelector(diarySelectors.getDiary).sportTime / 60); | ||
|
||
return ( | ||
<Container> | ||
<Card value={caloriesIntake}>Daily calorie intake</Card> | ||
<Card value={normOfSports}>Daily norm of sports</Card> | ||
<Card value={normOfSports}>Daily physical activity</Card> | ||
<Card value={caloriesConsumed}>Calories consumed</Card> | ||
<Card value={caloriesBurned}>Calories burned</Card> | ||
<Card value={restOfCalories}>The rest of the calories</Card> | ||
<Card value={restOfSports}>The rest of sports</Card> | ||
<Card value={restOfCalories}>Calories remaining</Card> | ||
<Card value={restOfSports}>Sports remaining</Card> | ||
</Container> | ||
); | ||
}; | ||
|
||
const Card = ({ value, children }) => { | ||
const isLoading = useSelector(diarySelectors.getIsLoading); | ||
let icon = ''; | ||
let displayValue = value; | ||
|
||
switch (children) { | ||
case 'Daily calorie intake': | ||
icon = ( | ||
<Icon width={20} height={20} className="orange"> | ||
<use href={`${sprite}#icon-fluent_food-24-filled`}></use> | ||
</Icon> | ||
); | ||
break; | ||
case 'Daily norm of sports': | ||
icon = ( | ||
<Icon width={20} height={20} className="orange"> | ||
<use href={`${sprite}#icon-dumbbell`}></use> | ||
</Icon> | ||
); | ||
displayValue = | ||
displayValue !== null && displayValue !== undefined | ||
? displayValue.toString() + ' min' | ||
: 'N/A'; | ||
break; | ||
case 'Calories consumed': | ||
icon = ( | ||
<Icon width={20} height={20} className="orange"> | ||
<use href={`${sprite}#icon-apple`}></use> | ||
</Icon> | ||
); | ||
break; | ||
case 'Calories burned': | ||
icon = ( | ||
<Icon width={20} height={20} className="orange"> | ||
<use href={`${sprite}#icon-calories-1`}></use> | ||
</Icon> | ||
); | ||
break; | ||
case 'The rest of the calories': | ||
icon = ( | ||
<Icon width={20} height={20} className="orange"> | ||
<use href={`${sprite}#icon-bubble`}></use> | ||
</Icon> | ||
); | ||
break; | ||
case 'The rest of sports': | ||
icon = ( | ||
<Icon width={20} height={20} className="orange"> | ||
<use href={`${sprite}#icon-running`}></use> | ||
</Icon> | ||
); | ||
displayValue = displayValue.toString() + ' min'; | ||
break; | ||
} | ||
if (children === 'The rest of the calories' && value < 0) { | ||
displayValue = '- ' + Math.abs(value).toString(); | ||
} | ||
if (children === 'The rest of sports' && value < 0) { | ||
displayValue = '+ ' + Math.abs(value).toString() + ' min'; | ||
} | ||
if (!displayValue) displayValue = 0; | ||
return ( | ||
<ContentContainerCard value={value} title={children}> | ||
<WrapperTitleCard> | ||
{icon} | ||
<TitleTextCard>{children}</TitleTextCard> | ||
</WrapperTitleCard> | ||
{isLoading ? ( | ||
<MyLoader display={'block'} /> | ||
) : ( | ||
<ValueTextCard> {displayValue}</ValueTextCard> | ||
)} | ||
</ContentContainerCard> | ||
); | ||
}; | ||
|
||
export { DayDashboard }; | ||
export { DayDashboard }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.