diff --git a/backend/data/poses.json b/backend/data/poses.json index 3c8b031..159c6e3 100644 --- a/backend/data/poses.json +++ b/backend/data/poses.json @@ -1,14 +1,18 @@ [ { - "name": "Lunges" + "name": "Lunges", + "componentName": "Lunges" }, { - "name": "Warrior" + "name": "Warrior", + "componentName": "Warrior" }, { - "name": "Chair" + "name": "Chair", + "componentName": "Chair" }, { - "name": "Curls" + "name": "Bicep Curls", + "componentName": "Curls" } ] diff --git a/backend/routes/poses.js b/backend/routes/poses.js index fd4ed4f..535c287 100644 --- a/backend/routes/poses.js +++ b/backend/routes/poses.js @@ -10,6 +10,7 @@ router.get("/", (req, res) => { poses.push({ id: pose.name, label: pose.name, + componentName: pose.componentName, }); }); res.send(poses); diff --git a/frontend/src/components/BtnComponent/PosesButtonsGroup.js b/frontend/src/components/BtnComponent/PosesButtonsGroup.js index 5696cb3..6cae348 100644 --- a/frontend/src/components/BtnComponent/PosesButtonsGroup.js +++ b/frontend/src/components/BtnComponent/PosesButtonsGroup.js @@ -1,69 +1,77 @@ import React, { useState, useEffect } from "react"; import axios from "axios"; import "./ButtonComponent.css"; -import WarriorComponent from "./WarriorComponent"; -import LungesComponent from "./LungesComponent"; -import CurlsComponent from "./CurlsComponent"; -import ChairComponent from "./ChairComponent"; import ModalFeedback from "../05_update_video/ModalFeedback"; function PosesButtonsGroup({ onButtonClicked, onModalClosed }) { - const [selectedPose, setSelectedPose] = useState(null); - const [poses, setPoses] = useState([]); + const [selectedPose, setSelectedPose] = useState(null); + const [poses, setPoses] = useState([]); - useEffect(() => { - axios.get("/poses").then((res) => { - setPoses(res.data); - }); - }, []); + useEffect(() => { + axios.get("/poses").then((res) => { + setPoses(res.data); + }); + }, []); - const handleButtonClick = (value) => { - setSelectedPose(value); - onButtonClicked(value); - }; + const handleButtonClick = (value) => { + setSelectedPose(value); + onButtonClicked(value.id); + }; - const resetStates = () => { - setSelectedPose(null); - }; + const resetStates = () => { + setSelectedPose(null); + }; - const renderPoseComponent = () => { - if (selectedPose === "Lunges") { - return ; - } else if (selectedPose === "Warrior") { - return ; - } else if (selectedPose === "Curls") { - return ; - } else if (selectedPose === "Chair") { - return ; - } - }; + const renderPoseComponent = () => { + if (selectedPose) { + try { + const PoseComponent = + require(`./${selectedPose.componentName}Component`).default; + return ; + } catch (error) { + console.log(error); + return null; + } + } + }; - const handleModalClosed = () => { - resetStates(); - onModalClosed(); - }; + const handleModalClosed = () => { + resetStates(); + onModalClosed(); + }; - return ( -
-
-

Choose an exercise

-
- {poses.map((button) => ( - - ))} -
- {renderPoseComponent()} + const Buttons = () => { + return poses.map((pose) => { + const buttonStatus = + selectedPose && selectedPose.id === pose.id + ? "active" + : "inactive"; + + return ( + + ); + }); + }; - -
-
- ); + return ( +
+
+

Choose an exercise

+
+ +
+ {renderPoseComponent()} + + +
+
+ ); } export default PosesButtonsGroup;