feat: gesturepage with gesture button
ref: N25B-345
This commit is contained in:
51
src/pages/GesturePage/GesturePage.tsx
Normal file
51
src/pages/GesturePage/GesturePage.tsx
Normal file
@@ -0,0 +1,51 @@
|
||||
import { useState } from 'react'
|
||||
|
||||
/**
|
||||
*
|
||||
* @returns A JSX element representing the app’s gesture page.
|
||||
*/
|
||||
export default function GesturePage() {
|
||||
|
||||
const [tags, setTags] = useState([])
|
||||
function getTags(){
|
||||
fetch(
|
||||
"http://localhost:8000/robot/get_available_gesture_tags",
|
||||
{
|
||||
method: "GET"
|
||||
}
|
||||
).then((res) => {
|
||||
if (!res.ok) throw new Error("Failed communicating with the backend.")
|
||||
res.json().then((jsonRes) => setTags(jsonRes["tags"]))
|
||||
|
||||
}).catch(() => console.log("Failed to send program to the backend."));
|
||||
}
|
||||
|
||||
const gesture = {endpoint: "actuate/gesture/tag", data: "happy"}
|
||||
function doGesture(){
|
||||
fetch(
|
||||
"http://localhost:8000/robot/command",
|
||||
{
|
||||
method: "POST",
|
||||
headers: {"Content-Type": "application/json"},
|
||||
body: JSON.stringify(gesture),
|
||||
}
|
||||
).then((res) => {
|
||||
if (!res.ok) throw new Error("Failed communicating with the backend.")
|
||||
console.log("Successfully sent the gesture command to the backend.");
|
||||
}).catch(() => console.log("Failed to send gesture command to the backend."));
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="card">
|
||||
<button onClick={getTags}>
|
||||
Get Tags
|
||||
</button>
|
||||
|
||||
<button onClick={doGesture}>
|
||||
Do Gesture
|
||||
</button>
|
||||
|
||||
|
||||
</div>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user