feat: Show connected robots finished with unit test 94% coverage
ref: N25B-142
This commit is contained in:
22
src/App.tsx
22
src/App.tsx
@@ -1,5 +1,4 @@
|
||||
import { Routes, Route, Link } from 'react-router'
|
||||
import { useState } from 'react'
|
||||
import './App.css'
|
||||
import TemplatePage from './pages/TemplatePage/Template.tsx'
|
||||
import Home from './pages/Home/Home.tsx'
|
||||
@@ -9,16 +8,6 @@ import VisProg from "./pages/VisProgPage/VisProg.tsx";
|
||||
|
||||
function App(){
|
||||
|
||||
// Define what our conencted robot should include
|
||||
type Robot = {
|
||||
id: string;
|
||||
name: string;
|
||||
port: number;
|
||||
};
|
||||
|
||||
// (Acces to) the array of connected robots
|
||||
const [connectedRobots, setConnectedRobots] = useState<Robot[]>([]);
|
||||
|
||||
return (
|
||||
<div>
|
||||
<header>
|
||||
@@ -30,16 +19,7 @@ function App(){
|
||||
<Route path="/template" element={<TemplatePage />} />
|
||||
<Route path="/editor" element={<VisProg />} />
|
||||
<Route path="/robot" element={<Robot />} />
|
||||
<Route
|
||||
path="/ConnectedRobots"
|
||||
// Pass the useState to the page to update from there
|
||||
element={
|
||||
<ConnectedRobots
|
||||
connectedRobots={connectedRobots}
|
||||
setConnectedRobots={setConnectedRobots}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
<Route path="/ConnectedRobots" element={<ConnectedRobots />} />
|
||||
</Routes>
|
||||
</main>
|
||||
</div>
|
||||
|
||||
@@ -3,6 +3,9 @@ import { useEffect, useState } from 'react'
|
||||
export default function ConnectedRobots() {
|
||||
|
||||
const [connected, setConnected] = useState<boolean | null>(null);
|
||||
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
// We're excepting a stream of data like that looks like this: `data = False` or `data = True`
|
||||
const eventSource = new EventSource("http://localhost:8000/robot/ping_stream");
|
||||
@@ -33,6 +36,9 @@ export default function ConnectedRobots() {
|
||||
<h1>Is robot currently connected?</h1>
|
||||
<div>
|
||||
<h2>Robot is currently: {connected == null ? "checking..." : (connected ? "connected! 🟢" : "not connected... 🔴")} </h2>
|
||||
<h3>
|
||||
{connected == null ? "If checking continues, make sure CB is properly loaded with robot at least once." : ""}
|
||||
</h3>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user