Skip to content

Commit

Permalink
visualize connection information (#633)
Browse files Browse the repository at this point in the history
* visualize connection information

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
PythonFZ and pre-commit-ci[bot] authored Aug 26, 2024
1 parent 9c21271 commit 95a9466
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
9 changes: 9 additions & 0 deletions app/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ export default function App() {
// const [isConnected, setIsConnected] = useState(socket.connected);
// const [fooEvents, setFooEvents] = useState([]);

const [connected, setConnected] = useState<boolean>(false);
const [selectionSchema, setSelectionSchema] = useState({});
const [modifierSchema, setModifierSchema] = useState({});
const [sceneSchema, setSceneSchema] = useState({});
Expand Down Expand Up @@ -226,6 +227,7 @@ export default function App() {

useEffect(() => {
function onConnect() {
setConnected(true);
socket.emit(
"webclient:connect",
(data: { name: string; room: string; authenticated: boolean }) => {
Expand Down Expand Up @@ -277,6 +279,10 @@ export default function App() {
});
}

function onDisconnect() {
setConnected(false);
}

function onSelectionSchema(receivedSchema: any) {
setSelectionSchema(receivedSchema);
}
Expand Down Expand Up @@ -373,6 +379,7 @@ export default function App() {
}

socket.on("connect", onConnect);
socket.on("disconnect", onDisconnect);
socket.on("selection:schema", onSelectionSchema);
socket.on("modifier:schema", onModifierSchema);
socket.on("scene:schema", onSceneSchema);
Expand All @@ -397,6 +404,7 @@ export default function App() {

return () => {
socket.off("connect", onConnect);
socket.off("disconnect", onDisconnect);
socket.off("selection:schema", onSelectionSchema);
socket.off("modifier:schema", onModifierSchema);
socket.off("scene:schema", onSceneSchema);
Expand Down Expand Up @@ -834,6 +842,7 @@ export default function App() {
setBookmarks={setBookmarks}
selectedFrames={selectedFrames}
setSelectedFrames={setSelectedFrames}
connected={connected}
/>
<Plotting
setStep={setStep}
Expand Down
21 changes: 21 additions & 0 deletions app/src/components/progressbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ interface FrameProgressBarProps {
bookmarks: any[]; // Replace with actual type if known
setBookmarks: (bookmarks: any[]) => void; // Replace with actual type if known
setSelectedFrames: (selectedFrames: IndicesState) => void;
connected: boolean;
}

const FrameProgressBar: React.FC<FrameProgressBarProps> = ({
Expand All @@ -259,6 +260,7 @@ const FrameProgressBar: React.FC<FrameProgressBarProps> = ({
bookmarks,
setBookmarks,
setSelectedFrames,
connected,
}) => {
const [linePosition, setLinePosition] = useState<number>(0);
const [disabledFrames, setDisabledFrames] = useState<number[]>([]);
Expand Down Expand Up @@ -398,6 +400,25 @@ const FrameProgressBar: React.FC<FrameProgressBarProps> = ({
>
1
</Col>
{!connected && (
<Col
className="d-flex bg-body justify-content-center align-items-center user-select-none"
style={{ height: 25 }}
>
<OverlayTrigger
placement="top"
delay={{ show: 0, hide: 100 }}
overlay={<Tooltip>Not connected to server</Tooltip>}
>
<div
className="spinner-border spinner-border-sm text-primary"
role="status"
>
<span className="visually-hidden">Loading...</span>
</div>
</OverlayTrigger>
</Col>
)}
</Row>
</Col>
</Row>
Expand Down

0 comments on commit 95a9466

Please sign in to comment.