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

Vibration toggle #28

Merged
merged 8 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Plant App</title>
<title>VibeGrow</title>
</head>
<body>
<div id="root"></div>
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
},
"dependencies": {
"json-server": "^1.0.0-beta.1",
"@deco3801-mortein/mortein-sdk": "^1.0.0",
"@deco3801-mortein/mortein-sdk": "^2.0.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-icons": "^5.3.0",
Expand Down
21 changes: 0 additions & 21 deletions src/components/Navbar.css

This file was deleted.

48 changes: 43 additions & 5 deletions src/pages/Detail.css
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,50 @@
color: #d67f7f;
}

.vibration-button {
.vibration {
display: flex;
flex-direction: column;
align-items: center;
margin-top: 0.2vh;
width: 10vh;
height: 5vh;
font-size: 1.5rem;
}

.vibration-container-off {
cursor: pointer;
display: flex;
align-items: center;
justify-content: flex-start;
width: 80px;
height: 30px;
background-color: lightgreen;
border-radius: 25px;
position: relative;
border: 1.5px solid black;
}

.vibration-container-on {
cursor: pointer;
display: flex;
align-items: center;
justify-content: flex-end;
width: 80px;
height: 30px;
background-color: rgb(1, 146, 1);
border-radius: 25px;
position: relative;
border: 1.5px solid black;
}

.vibration-button {
margin: 0;
width: 30%;
background-color: white;
border: 1.5px solid black;
height: 80%;
border-radius: 25px;
position: absolute;
}

.vibration-status {
font-size: 2rem;
}

.vibration-heading {
Expand Down
34 changes: 24 additions & 10 deletions src/pages/Detail.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useParams } from "react-router-dom";
import { useEffect, useState } from "react";
import { Device, HealthcheckData } from "@deco3801-mortein/mortein-sdk/services.gen";
import { Command, Device, HealthcheckData } from "@deco3801-mortein/mortein-sdk/services.gen";
import Meter from "../components/Meter";
import "../pages/Detail.css";
import Header from "../components/Header";
Expand Down Expand Up @@ -35,14 +35,19 @@ function Detail() {

const [currentHealthData, setCurrentHealthData] = useState(null);

//const [vibrationToggled, setVibrationToggled] = useState(false);

const [toggleButtonOn, setToggleButtonOn] = useState(null);

useEffect(() => {
if (device) {
HealthcheckData.getDeviceByDeviceIdHealthcheckDataLatest(device)
.then((data) => {
setCurrentHealthData(data);
setToggleButtonOn(data.isVibrating);
})
.catch((error) => {
console.log(error.message);
console.error(error.message);
setDataNotFound(true);
});
}
Expand Down Expand Up @@ -76,6 +81,15 @@ function Detail() {
}
};

const toggleVibration = async () => {
try {
await Command.postDeviceByDeviceIdCommandToggle({ deviceId: id });
setToggleButtonOn((prev) => !prev);
} catch (error) {
console.error(error);
}
};

return (
<div className="detail">
<Header left="Back" title="Detail" showGuide={true} />
Expand Down Expand Up @@ -112,12 +126,17 @@ function Detail() {
<div className="vibration">
<h2 className="vibration-heading">Vibration</h2>
<button
className="vibration-button"
className={
toggleButtonOn
? "vibration-container-on"
: "vibration-container-off"
}
value={device.deviceId}
//onClick={props.toggleVibration}
onClick={() => toggleVibration()}
>
{currentHealthData.isVibrating ? "Off" : "On"}
<div className="vibration-button"></div>
</button>
<p>{`Vibration is currently ${toggleButtonOn ? "on" : "off"}`}</p>
</div>
</div>
)}
Expand All @@ -127,9 +146,4 @@ function Detail() {
);
}

// Detail.propTypes = {
// userData: PropTypes.array,
// toggleVibration: PropTypes.func,
// };

export default Detail;