Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hackathon - Heart Essential 8 #289

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 112 additions & 0 deletions src/components/container/HeartEssentialEight/HeartEssentialEight.css
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this file could use an auto format and some TODO cleanup. Let me know once you are done with the revisions here and I'll take another look at it.

Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
.mdhui-heart-e8-container {
display: flex;
align-items: center;
}

.mdhui-heart-e8-container .mdhui-heart-e8-score-container {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}

.mdhui-heart-e8-container .mdhui-heart-e8-score-container .score{
font-size: 65px;
font-weight: bold;
display: flex;
justify-content: center;
}

.mdhui-heart-e8-container .mdhui-heart-e8-score-container .scoreSubText{
font-size: 20px;
font-weight: bold;
color: rgb(109, 110, 113);
display: flex;
justify-content: center;
}

.mdhui-heart-e8-container .mdhui-heart-e8-feedback {
display: flex;
flex-direction: column;
justify-content: left;
margin-left: 20px;
}

.mdhui-heart-e8-container .mdhui-heart-e8-feedback .achievementSection{
display: flex;
align-items: center;
}

.bulletPoint{
width: 20px;
height: 20px;
-moz-border-radius: 50px;
-webkit-border-radius: 50px;
border-radius: 50px;
margin-right: 15px;
}

.improve {
background-color: rgb(234, 140, 28);;
reneefromhold marked this conversation as resolved.
Show resolved Hide resolved
}

.celebrate {
background-color: rgb(127, 180, 57);
}

.circle{
width: 40px;
height: 40px;
display: flex;
justify-content: center;
align-content: center;
-moz-border-radius: 50px;
-webkit-border-radius: 50px;
border-radius: 50px;
overflow: hidden;
}

.circle img{
width: 40px;
height: 40px;
}

.activity{
background-color: rgb(1, 131, 191);
color: white;
}

.bloodPressure{
background-color: rgb(102, 88, 166);
color: white;
}

.bloodSugar{
background-color: rgb(2, 128, 131);
color: white;
}

.bmi{
background-color: rgb(234, 140, 28);
color: white;
}

.cholesterol{
background-color: rgb(158, 31, 99);
color: white;
}

.diet{
background-color: rgb(127, 180, 57);
color: white;
}

.nicotine{
background-color: rgb(193, 14, 33);
color: white;
}

.sleep{
background-color: rgb(111, 207, 190);
color: white;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export var previewHeartEssentialData: { [key: string]: string } = {
Activity: "75",
BloodPressure: "100",
BloodSugar: "50",
BMI: "100",
Cholesterol: "100",
Diet: "100",
Nicotine: "100",
Sleep: "80",
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import React from "react";
import { Meta, StoryObj } from "@storybook/react";
import Layout from "../../presentational/Layout";
import { Card } from "../../presentational";
import HeartEssentialEight, {
HeartEssentialEightProps,
} from "./HeartEssentialEight";

const meta: Meta<typeof HeartEssentialEight> = {
title: "Container/HeartEssentialEight",
component: HeartEssentialEight,
parameters: {
layout: "fullscreen",
},
};

export default meta;
type Story = StoryObj<typeof HeartEssentialEight>;

const render = (args: HeartEssentialEightProps) => {
return (
<Layout colorScheme="auto">
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider setting up the story to allow for swapping between color schemes for easier review of light/dark/auto modes.

Similarly, the preview state can be set up as a toggle on a single story if you'd like.

An example: https://github.com/CareEvolution/MyDataHelpsUI/blob/main/src/components/container/ConnectDexcom/ConnectDexcom.stories.tsx

<Card>
<HeartEssentialEight {...args} />
</Card>
</Layout>
);
};

export const Default: Story = {
args: {
previewState: "Default",
customFieldDictionary: {
Activity: "Activity",
BloodPressure: "BloodPressure",
BloodSugar: "BloodSugar",
BMI: "BMI",
Cholesterol: "Cholesterol",
Diet: "Diet",
Nicotine: "Nicotine",
Sleep: "Sleep",
},
},
render: render,
};

export const NoData: Story = {
args: {
previewState: "NoData",
customFieldDictionary: {
Activity: "Activity",
BloodPressure: "BloodPressure",
BloodSugar: "BloodSugar",
BMI: "BMI",
Cholesterol: "Cholesterol",
Diet: "Diet",
Nicotine: "Nicotine",
Sleep: "Sleep",
},
},
render: render,
};
184 changes: 184 additions & 0 deletions src/components/container/HeartEssentialEight/HeartEssentialEight.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
import MyDataHelps from "@careevolution/mydatahelps-js";
import { useInitializeView } from "../../../helpers";
import { Action, LoadingIndicator, ProgressRing } from "../../presentational";
import React, { useState } from "react";
import { previewHeartEssentialData } from "./HeartEssentialEight.previewdata";
import "./HeartEssentialEight.css";
import iconCholesterol from "./controlcholesterol.svg";
import iconEatWell from "./eatwell.svg";
import iconGetActive from "./getactive.svg";
import iconLoseWeight from "./loseweight.svg";
import iconManageBloodPressure from "./managebloodpressure.svg";
import iconReduceBloodSugar from "./reducebloodsugar.svg";
import iconSleep from "./sleep.svg";
import iconStopSmoking from "./stopsmoking.svg";

export type HeartEssentialEightScores =
| "Activity"
| "BloodPressure"
| "BloodSugar"
| "BMI"
| "Cholesterol"
| "Diet"
| "Nicotine"
| "Sleep";

export interface HeartEssentialEightProps {
previewState?: "Default" | "NoData";
customFieldDictionary: Record<HeartEssentialEightScores, string> & {
[key: string]: string;
};
innerRef?: React.Ref<HTMLDivElement>;
}

export default function (props: HeartEssentialEightProps) {
const { customFieldDictionary } = props;
let [score, setScore] = React.useState<number>();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can just be useState<number>(). No need for the React prefix.

let [achievementMap, setAchievementMap] =
useState<Record<HeartEssentialEightScores, boolean>>();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use const for state variables.

The use of let for score and achievementMap is unconventional. Consider using const as these variables are managed by React state hooks.

- let [score, setScore] = React.useState<number>();
- let [achievementMap, setAchievementMap] = useState<Record<HeartEssentialEightScores, boolean>>();
+ const [score, setScore] = React.useState<number>();
+ const [achievementMap, setAchievementMap] = useState<Record<HeartEssentialEightScores, boolean>>();
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export default function (props: HeartEssentialEightProps) {
const { customFieldDictionary } = props;
let [score, setScore] = React.useState<number>();
let [achievementMap, setAchievementMap] =
useState<Record<HeartEssentialEightScores, boolean>>();
export default function (props: HeartEssentialEightProps) {
const { customFieldDictionary } = props;
const [score, setScore] = React.useState<number>();
const [achievementMap, setAchievementMap] =
useState<Record<HeartEssentialEightScores, boolean>>();

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: Some of this file appears to be rather "narrow" with regard to formatting. We probably don't need to wrap things quite this aggressively.


async function initialize() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you need the async keyword here. No calls to this function are awaiting or expecting a promise.

if (props.previewState) {
if (["Default", "NoData"].includes(props.previewState ?? "")) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You shouldn't need the ?? "" here. The includes(...) function should handle an undefined preview state without any issues.

const data =
props.previewState === "Default" ? previewHeartEssentialData : {};
loadScoresFromCustomFieldData(data);
} else {
MyDataHelps.getParticipantInfo().then((participantInfo) => {
loadScoresFromCustomFieldData(participantInfo.customFields);
});
}
}
}

function loadScoresFromCustomFieldData(
customFieldData: Record<string, string>
) {
let newScore: number = 0;
let newAchievementMap = {} as Record<HeartEssentialEightScores, boolean>;

for (const key in customFieldDictionary) {
if (customFieldDictionary[key]) {
let surveyScore = customFieldData[customFieldDictionary[key]];
let numericScore = parseInt(surveyScore);
if (!Number.isNaN(numericScore)) {
newScore += numericScore;
newAchievementMap[key as HeartEssentialEightScores] =
numericScore >= 100;
} else {
newAchievementMap[key as HeartEssentialEightScores] = false;
}
}
}

if (newScore > 0){
newScore = (newScore / 800) * 100;
}

setScore(parseFloat(newScore.toFixed(1)));
setAchievementMap(newAchievementMap);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Improve type safety for newAchievementMap.

Consider initializing newAchievementMap with a more explicit type to enhance type safety.

- let newAchievementMap = {} as Record<HeartEssentialEightScores, boolean>;
+ let newAchievementMap: Record<HeartEssentialEightScores, boolean> = {};
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
function loadScoresFromCustomFieldData(
customFieldData: Record<string, string>
) {
let newScore: number = 0;
let newAchievementMap = {} as Record<HeartEssentialEightScores, boolean>;
for (const key in customFieldDictionary) {
if (customFieldDictionary[key]) {
let surveyScore = customFieldData[customFieldDictionary[key]];
let numericScore = parseInt(surveyScore);
if (!Number.isNaN(numericScore)) {
newScore += numericScore;
newAchievementMap[key as HeartEssentialEightScores] =
numericScore >= 100;
} else {
newAchievementMap[key as HeartEssentialEightScores] = false;
}
}
}
if (newScore > 0){
newScore = (newScore / 800) * 100;
}
setScore(parseFloat(newScore.toFixed(1)));
setAchievementMap(newAchievementMap);
}
function loadScoresFromCustomFieldData(
customFieldData: Record<string, string>
) {
let newScore: number = 0;
let newAchievementMap: Record<HeartEssentialEightScores, boolean> = {};
for (const key in customFieldDictionary) {
if (customFieldDictionary[key]) {
let surveyScore = customFieldData[customFieldDictionary[key]];
let numericScore = parseInt(surveyScore);
if (!Number.isNaN(numericScore)) {
newScore += numericScore;
newAchievementMap[key as HeartEssentialEightScores] =
numericScore >= 100;
} else {
newAchievementMap[key as HeartEssentialEightScores] = false;
}
}
}
if (newScore > 0){
newScore = (newScore / 800) * 100;
}
setScore(parseFloat(newScore.toFixed(1)));
setAchievementMap(newAchievementMap);
}


function generateAchievementMap(
didAchieve: boolean,
newAchievementMap: Record<HeartEssentialEightScores, boolean>
) {
const map = newAchievementMap as Record<string, boolean>;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you need to do this conversion.

const achievementList: any[] = [];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be typed as React.JSX.Element[].

for (const key in map) {
const vv = map[key];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you use a more meaningful variable name here?

if (vv === didAchieve) {
const title = key.replace(/([A-Z])/g, " $1").replace(/^./, (str) => {
return str.toUpperCase();
});
let icon: any;
let url: string;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't look like the URL variable ever gets set. Are we still deciding what to do with these actions when clicked?

const circleClasses: string[] = ["circle"];
switch (key) {
case "Activity":
icon = iconGetActive;
circleClasses.push("activity");
break;
case "BloodPressure":
icon = iconManageBloodPressure;
circleClasses.push("bloodPressure");
break;
case "BloodSugar":
icon = iconReduceBloodSugar;
circleClasses.push("bloodSugar");
break;
case "BMI":
icon = iconLoseWeight;
circleClasses.push("bmi");
break;
case "Cholesterol":
icon = iconCholesterol;
circleClasses.push("cholesterol");
break;
case "Diet":
icon = iconEatWell;
circleClasses.push("diet");
break;
case "Nicotine":
icon = iconStopSmoking;
circleClasses.push("nicotine");
break;
case "Sleep":
icon = iconSleep;
circleClasses.push("sleep");
break;
default:
icon = null;
}

const achievementIcon = (
<div className={circleClasses.join(" ")}>
<img src={icon} />
</div>
);

const achievement = (
<Action key={`achievement-${key}`}
title={title}
titleIcon={achievementIcon}
onClick={() => MyDataHelps.openExternalUrl(url)}
/>
);
achievementList.push(achievement);
}
}

return achievementList;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Enhance type safety and readability.

Consider using more specific types for map and achievementList to enhance type safety and readability.

- const map = newAchievementMap as Record<string, boolean>;
- const achievementList: any[] = [];
+ const map: Record<HeartEssentialEightScores, boolean> = newAchievementMap;
+ const achievementList: JSX.Element[] = [];
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
function generateAchievementMap(
didAchieve: boolean,
newAchievementMap: Record<HeartEssentialEightScores, boolean>
) {
const map = newAchievementMap as Record<string, boolean>;
const achievementList: any[] = [];
for (const key in map) {
const vv = map[key];
if (vv === didAchieve) {
const title = key.replace(/([A-Z])/g, " $1").replace(/^./, (str) => {
return str.toUpperCase();
});
let icon: any;
let url: string;
const circleClasses: string[] = ["circle"];
switch (key) {
case "Activity":
icon = iconGetActive;
circleClasses.push("activity");
break;
case "BloodPressure":
icon = iconManageBloodPressure;
circleClasses.push("bloodPressure");
break;
case "BloodSugar":
icon = iconReduceBloodSugar;
circleClasses.push("bloodSugar");
break;
case "BMI":
icon = iconLoseWeight;
circleClasses.push("bmi");
break;
case "Cholesterol":
icon = iconCholesterol;
circleClasses.push("cholesterol");
break;
case "Diet":
icon = iconEatWell;
circleClasses.push("diet");
break;
case "Nicotine":
icon = iconStopSmoking;
circleClasses.push("nicotine");
break;
case "Sleep":
icon = iconSleep;
circleClasses.push("sleep");
break;
default:
icon = null;
}
const achievementIcon = (
<div className={circleClasses.join(" ")}>
<img src={icon} />
</div>
);
const achievement = (
<Action key={`achievement-${key}`}
title={title}
titleIcon={achievementIcon}
onClick={() => MyDataHelps.openExternalUrl(url)}
/>
);
achievementList.push(achievement);
}
}
return achievementList;
}
function generateAchievementMap(
didAchieve: boolean,
newAchievementMap: Record<HeartEssentialEightScores, boolean>
) {
const map: Record<HeartEssentialEightScores, boolean> = newAchievementMap;
const achievementList: JSX.Element[] = [];
for (const key in map) {
const vv = map[key];
if (vv === didAchieve) {
const title = key.replace(/([A-Z])/g, " $1").replace(/^./, (str) => {
return str.toUpperCase();
});
let icon: any;
let url: string;
const circleClasses: string[] = ["circle"];
switch (key) {
case "Activity":
icon = iconGetActive;
circleClasses.push("activity");
break;
case "BloodPressure":
icon = iconManageBloodPressure;
circleClasses.push("bloodPressure");
break;
case "BloodSugar":
icon = iconReduceBloodSugar;
circleClasses.push("bloodSugar");
break;
case "BMI":
icon = iconLoseWeight;
circleClasses.push("bmi");
break;
case "Cholesterol":
icon = iconCholesterol;
circleClasses.push("cholesterol");
break;
case "Diet":
icon = iconEatWell;
circleClasses.push("diet");
break;
case "Nicotine":
icon = iconStopSmoking;
circleClasses.push("nicotine");
break;
case "Sleep":
icon = iconSleep;
circleClasses.push("sleep");
break;
default:
icon = null;
}
const achievementIcon = (
<div className={circleClasses.join(" ")}>
<img src={icon} />
</div>
);
const achievement = (
<Action key={`achievement-${key}`}
title={title}
titleIcon={achievementIcon}
onClick={() => MyDataHelps.openExternalUrl(url)}
/>
);
achievementList.push(achievement);
}
}
return achievementList;
}


useInitializeView(initialize, [], [props.previewState]);

return (
<>
{/* <LoadingIndicator /> */}
{/* {score === undefined && <LoadingIndicator />} */}
<div className="mdhui-heart-e8-container">
<div className="mdhui-heart-e8-score-container">
<ProgressRing
percentCompleted={score}
color="rgb(193, 14, 33)"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this use one of the existing color variables?

children={
<div className="scoreContainer">
<div className="score">{score}</div>
<div className="scoreSubText">out of 100</div>
</div>
}
animate={true}
/>
</div>
{achievementMap && <div className="mdhui-heart-e8-feedback">
<div className="achievementSection"><div className="bulletPoint improve" /><h3>IMPROVE</h3></div>
<div className="achievementSection">{generateAchievementMap(false, achievementMap)}</div>
<div className="achievementSection"><div className="bulletPoint celebrate" /><h3>CELEBRATE</h3></div>
<div className="achievementSection">{generateAchievementMap(true, achievementMap)}</div>
</div>}
</div>

</>
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid using the children prop directly in JSX.

The ProgressRing component should use JSX syntax to pass children, as recommended by React best practices.

- <ProgressRing
-   percentCompleted={score}
-   color="rgb(193, 14, 33)"
-   children={
-     <div className="scoreContainer">
-       <div className="score">{score}</div>
-       <div className="scoreSubText">out of 100</div>
-     </div>
-   }
-   animate={true}
- />
+ <ProgressRing percentCompleted={score} color="rgb(193, 14, 33)" animate={true}>
+   <div className="scoreContainer">
+     <div className="score">{score}</div>
+     <div className="scoreSubText">out of 100</div>
+   </div>
+ </ProgressRing>
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
return (
<>
{/* <LoadingIndicator /> */}
{/* {score === undefined && <LoadingIndicator />} */}
<div className="mdhui-heart-e8-container">
<div className="mdhui-heart-e8-score-container">
<ProgressRing
percentCompleted={score}
color="rgb(193, 14, 33)"
children={
<div className="scoreContainer">
<div className="score">{score}</div>
<div className="scoreSubText">out of 100</div>
</div>
}
animate={true}
/>
</div>
{achievementMap && <div className="mdhui-heart-e8-feedback">
<div className="achievementSection"><div className="bulletPoint improve" /><h3>IMPROVE</h3></div>
<div className="achievementSection">{generateAchievementMap(false, achievementMap)}</div>
<div className="achievementSection"><div className="bulletPoint celebrate" /><h3>CELEBRATE</h3></div>
<div className="achievementSection">{generateAchievementMap(true, achievementMap)}</div>
</div>}
</div>
</>
);
return (
<>
{/* <LoadingIndicator /> */}
{/* {score === undefined && <LoadingIndicator />} */}
<div className="mdhui-heart-e8-container">
<div className="mdhui-heart-e8-score-container">
<ProgressRing percentCompleted={score} color="rgb(193, 14, 33)" animate={true}>
<div className="scoreContainer">
<div className="score">{score}</div>
<div className="scoreSubText">out of 100</div>
</div>
</ProgressRing>
</div>
{achievementMap && <div className="mdhui-heart-e8-feedback">
<div className="achievementSection"><div className="bulletPoint improve" /><h3>IMPROVE</h3></div>
<div className="achievementSection">{generateAchievementMap(false, achievementMap)}</div>
<div className="achievementSection"><div className="bulletPoint celebrate" /><h3>CELEBRATE</h3></div>
<div className="achievementSection">{generateAchievementMap(true, achievementMap)}</div>
</div>}
</div>
</>
);
Tools
Biome

[error] 166-166: Avoid passing children using a prop

The canonical way to pass children in React is to use JSX elements

(lint/correctness/noChildrenProp)

}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid using the children prop directly in JSX.

The ProgressRing component should use JSX syntax to pass children, as recommended by React best practices.

- <ProgressRing
-   percentCompleted={score}
-   color="rgb(193, 14, 33)"
-   children={
-     <div className="scoreContainer">
-       <div className="score">{score}</div>
-       <div className="scoreSubText">out of 100</div>
-     </div>
-   }
-   animate={true}
- />
+ <ProgressRing percentCompleted={score} color="rgb(193, 14, 33)" animate={true}>
+   <div className="scoreContainer">
+     <div className="score">{score}</div>
+     <div className="scoreSubText">out of 100</div>
+   </div>
+ </ProgressRing>
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export default function (props: HeartEssentialEightProps) {
const { customFieldDictionary } = props;
let [score, setScore] = React.useState<number>();
let [achievementMap, setAchievementMap] =
useState<Record<HeartEssentialEightScores, boolean>>();
async function initialize() {
if (props.previewState) {
if (["Default", "NoData"].includes(props.previewState ?? "")) {
const data =
props.previewState === "Default" ? previewHeartEssentialData : {};
loadScoresFromCustomFieldData(data);
} else {
MyDataHelps.getParticipantInfo().then((participantInfo) => {
loadScoresFromCustomFieldData(participantInfo.customFields);
});
}
}
}
function loadScoresFromCustomFieldData(
customFieldData: Record<string, string>
) {
let newScore: number = 0;
let newAchievementMap = {} as Record<HeartEssentialEightScores, boolean>;
for (const key in customFieldDictionary) {
if (customFieldDictionary[key]) {
let surveyScore = customFieldData[customFieldDictionary[key]];
let numericScore = parseInt(surveyScore);
if (!Number.isNaN(numericScore)) {
newScore += numericScore;
newAchievementMap[key as HeartEssentialEightScores] =
numericScore >= 100;
} else {
newAchievementMap[key as HeartEssentialEightScores] = false;
}
}
}
if (newScore > 0){
newScore = (newScore / 800) * 100;
}
setScore(parseFloat(newScore.toFixed(1)));
setAchievementMap(newAchievementMap);
}
function generateAchievementMap(
didAchieve: boolean,
newAchievementMap: Record<HeartEssentialEightScores, boolean>
) {
const map = newAchievementMap as Record<string, boolean>;
const achievementList: any[] = [];
for (const key in map) {
const vv = map[key];
if (vv === didAchieve) {
const title = key.replace(/([A-Z])/g, " $1").replace(/^./, (str) => {
return str.toUpperCase();
});
let icon: any;
let url: string;
const circleClasses: string[] = ["circle"];
switch (key) {
case "Activity":
icon = iconGetActive;
circleClasses.push("activity");
break;
case "BloodPressure":
icon = iconManageBloodPressure;
circleClasses.push("bloodPressure");
break;
case "BloodSugar":
icon = iconReduceBloodSugar;
circleClasses.push("bloodSugar");
break;
case "BMI":
icon = iconLoseWeight;
circleClasses.push("bmi");
break;
case "Cholesterol":
icon = iconCholesterol;
circleClasses.push("cholesterol");
break;
case "Diet":
icon = iconEatWell;
circleClasses.push("diet");
break;
case "Nicotine":
icon = iconStopSmoking;
circleClasses.push("nicotine");
break;
case "Sleep":
icon = iconSleep;
circleClasses.push("sleep");
break;
default:
icon = null;
}
const achievementIcon = (
<div className={circleClasses.join(" ")}>
<img src={icon} />
</div>
);
const achievement = (
<Action key={`achievement-${key}`}
title={title}
titleIcon={achievementIcon}
onClick={() => MyDataHelps.openExternalUrl(url)}
/>
);
achievementList.push(achievement);
}
}
return achievementList;
}
useInitializeView(initialize, [], [props.previewState]);
return (
<>
{/* <LoadingIndicator /> */}
{/* {score === undefined && <LoadingIndicator />} */}
<div className="mdhui-heart-e8-container">
<div className="mdhui-heart-e8-score-container">
<ProgressRing
percentCompleted={score}
color="rgb(193, 14, 33)"
children={
<div className="scoreContainer">
<div className="score">{score}</div>
<div className="scoreSubText">out of 100</div>
</div>
}
animate={true}
/>
</div>
{achievementMap && <div className="mdhui-heart-e8-feedback">
<div className="achievementSection"><div className="bulletPoint improve" /><h3>IMPROVE</h3></div>
<div className="achievementSection">{generateAchievementMap(false, achievementMap)}</div>
<div className="achievementSection"><div className="bulletPoint celebrate" /><h3>CELEBRATE</h3></div>
<div className="achievementSection">{generateAchievementMap(true, achievementMap)}</div>
</div>}
</div>
</>
);
}
return (
<>
{/* <LoadingIndicator /> */}
{/* {score === undefined && <LoadingIndicator />} */}
<div className="mdhui-heart-e8-container">
<div className="mdhui-heart-e8-score-container">
<ProgressRing percentCompleted={score} color="rgb(193, 14, 33)" animate={true}>
<div className="scoreContainer">
<div className="score">{score}</div>
<div className="scoreSubText">out of 100</div>
</div>
</ProgressRing>
</div>
{achievementMap && <div className="mdhui-heart-e8-feedback">
<div className="achievementSection"><div className="bulletPoint improve" /><h3>IMPROVE</h3></div>
<div className="achievementSection">{generateAchievementMap(false, achievementMap)}</div>
<div className="achievementSection"><div className="bulletPoint celebrate" /><h3>CELEBRATE</h3></div>
<div className="achievementSection">{generateAchievementMap(true, achievementMap)}</div>
</div>}
</div>
</>
);
Tools
Biome

[error] 165-165: Avoid passing children using a prop

The canonical way to pass children in React is to use JSX elements

(lint/correctness/noChildrenProp)

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions src/components/container/HeartEssentialEight/eatwell.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/components/container/HeartEssentialEight/getactive.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading