Skip to content

Commit 682922b

Browse files
authored
Merge pull request #114 from oss-slu/websocket-switch-ui
Replace full-width WebSocket banner with toggle switch
2 parents 3da19e7 + 15859e2 commit 682922b

File tree

3 files changed

+69
-8
lines changed

3 files changed

+69
-8
lines changed

frontend/src/App.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import StanceTimeChart from './StanceTimeChart';
77
import StanceTimeGraph from './StanceTimeGraph';
88
import ResearcherToolbar from './components/ResearcherToolbar';
99
import PatientView from './PatientView';
10+
import WebSocketSwitch from './components/WebSocketSwitch';
1011

1112
function App() {
1213
const [currentView, setCurrentView] = useState('StanceTimeTreadmill');
@@ -20,8 +21,8 @@ function App() {
2021
}
2122
});
2223

23-
const [isWebSocketConnected, setIsWebSocketConnected] = useState(false);
24-
const [webSocketError, setWebSocketError] = useState(null);
24+
const [isWebSocketConnected, setIsWebSocketConnected] = useState(false);
25+
const [webSocketError, setWebSocketError] = useState(null);
2526

2627
const [movingAverageFactor, setMovingAverageFactor] = useState(0);
2728
const [threshold, setThreshold] = useState(0);
@@ -143,12 +144,7 @@ function App() {
143144

144145
return (
145146
<div className="App">
146-
<div className={`WebSocketBanner ${isWebSocketConnected ? 'connected' : 'disconnected'}`}>
147-
{isWebSocketConnected
148-
? "Connection established"
149-
: webSocketError || "Waiting for WebSocket connection..."}
150-
{!isWebSocketConnected && <button onClick={reconnectWebsocket}>Reconnect</button>}
151-
</div>
147+
<WebSocketSwitch isConnected={isWebSocketConnected} reconnect={reconnectWebsocket} />
152148
<Navigation setCurrentView={setCurrentView}/>
153149
{patientWindow && <PatientView borderColor={borderColor} patientWindow={patientWindow} view={views[currentPatientView]}/>}
154150
<div className="main-layout">
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
.websocket-toggle {
2+
position: fixed;
3+
top: 16px;
4+
right: 16px;
5+
z-index: 1000;
6+
}
7+
8+
.websocket-toggle input[type="checkbox"] {
9+
display: none;
10+
}
11+
12+
.switch-track {
13+
width: 44px;
14+
height: 24px;
15+
border-radius: 9999px;
16+
position: relative;
17+
transition: background-color 0.3s;
18+
}
19+
20+
.switch-track.connected {
21+
background-color: #22c55e; /* green */
22+
}
23+
24+
.switch-track.disconnected {
25+
background-color: #ef4444; /* red */
26+
}
27+
28+
.switch-thumb {
29+
width: 16px;
30+
height: 16px;
31+
background: white;
32+
border-radius: 50%;
33+
position: absolute;
34+
top: 4px;
35+
left: 4px;
36+
transition: transform 0.3s;
37+
}
38+
39+
input[type="checkbox"]:checked + .switch-track .switch-thumb {
40+
transform: translateX(20px);
41+
}
42+
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import React from 'react';
2+
import './WebSocketSwitch.css';
3+
4+
const WebSocketSwitch = ({ isConnected, reconnect }) => {
5+
const handleToggle = () => {
6+
if (!isConnected) {
7+
reconnect();
8+
}
9+
};
10+
11+
return (
12+
<div className="websocket-toggle" title={isConnected ? 'Connected' : 'Disconnected'}>
13+
<label>
14+
<input type="checkbox" checked={isConnected} onChange={handleToggle} />
15+
<div className={`switch-track ${isConnected ? 'connected' : 'disconnected'}`}>
16+
<div className="switch-thumb"></div>
17+
</div>
18+
</label>
19+
</div>
20+
);
21+
};
22+
23+
export default WebSocketSwitch;

0 commit comments

Comments
 (0)