From 19cea0b51bdba911a0411444898c7df08edfcc8d Mon Sep 17 00:00:00 2001 From: gokhangunduz Date: Thu, 21 Dec 2023 09:36:17 +0300 Subject: [PATCH] feat(version): release 0.25.2 version --- package.json | 2 +- src/components/Connections/Connections.tsx | 21 +++--- src/contexts/RobotContext.tsx | 81 +++++++++++++++------- src/hooks/useRobot.tsx | 5 +- 4 files changed, 70 insertions(+), 39 deletions(-) diff --git a/package.json b/package.json index e082278c..c93a7e11 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ui", - "version": "0.25.1", + "version": "0.25.2", "private": true, "scripts": { "dev": "react-scripts start", diff --git a/src/components/Connections/Connections.tsx b/src/components/Connections/Connections.tsx index d2247bc1..e06d6ea0 100644 --- a/src/components/Connections/Connections.tsx +++ b/src/components/Connections/Connections.tsx @@ -3,13 +3,16 @@ import StateCell from "../TableInformationCells/StateCell"; import { envApplication } from "../../helpers/envProvider"; import { useKeycloak } from "@react-keycloak/web"; import useRobot from "../../hooks/useRobot"; -import { ReactElement } from "react"; +import { ReactElement, useEffect } from "react"; export default function Connections(): ReactElement { - const { responseRobot, isSettedCookie, isRosConnected, isVDIConnected } = - useRobot(); + const { responseRobot, isSettedCookie, connectionsReducer } = useRobot(); const { keycloak } = useKeycloak(); + useEffect(() => { + console.log("connectionsReducer", connectionsReducer); + }, [connectionsReducer]); + return (
{!envApplication && ( @@ -17,9 +20,9 @@ export default function Connections(): ReactElement { { const [ros, setRos] = useState(null); const [topicList, setTopicList] = useState([]); - const [isRosConnected, setIsRosConnected] = useState(null); - const [isVDIConnected, setIsVDIConnected] = useState(null); + const [connectionsReducer, dispatcher] = useReducer(handleReducer, { + ros: null, + virtualIDE: null, + physicalIDE: null, + vdi: null, + }); + + function handleReducer(state: any, action: any) { + switch (action.type) { + case "ros": + return { + ...state, + ros: action.payload, + }; + case "virtualIDE": + return { + ...state, + virtualIDE: action.payload, + }; + case "physicalIDE": + return { + ...state, + physicalIDE: action.payload, + }; + case "vdi": + return { + ...state, + vdi: action.payload, + }; + default: + return state; + } + } // Main Functions useEffect(() => { @@ -192,13 +223,16 @@ export default ({ children }: any) => { setRos(ros); rosClient?.on("connection", function () { - isRosConnected === null && setIsRosConnected(true); + connectionsReducer?.ros === null && + dispatcher({ type: "ros", payload: true }); }); rosClient?.on("error", function (error) { - isRosConnected === null && setIsRosConnected(false); + connectionsReducer?.ros === null && + dispatcher({ type: "ros", payload: false }); }); rosClient?.on("close", function () { - isRosConnected === null && setIsRosConnected(false); + connectionsReducer?.ros === null && + dispatcher({ type: "ros", payload: false }); }); return () => { @@ -252,37 +286,37 @@ export default ({ children }: any) => { // VDI Test Connection useEffect(() => { - const vdiClient = - isSettedCookie && isVDIConnected === null + const vdiClient: WebSocket | null = + isSettedCookie && connectionsReducer?.vdi === null ? new WebSocket(responseRobot?.vdiIngressEndpoint + "ws?password=admin") : null; vdiClient?.addEventListener("open", () => { - if (isVDIConnected === null) { - setIsVDIConnected(true); - vdiClient?.close(); - } + dispatcher({ + type: "vdi", + payload: true, + }); }); vdiClient?.addEventListener("error", () => { - if (isVDIConnected === null) { - setIsVDIConnected(false); - vdiClient?.close(); - } + dispatcher({ + type: "vdi", + payload: false, + }); }); vdiClient?.addEventListener("close", () => { - if (isVDIConnected === null) { - setIsVDIConnected(false); - vdiClient?.close(); - } + dispatcher({ + type: "vdi", + payload: false, + }); }); return () => { vdiClient?.close(); }; // eslint-disable-next-line react-hooks/exhaustive-deps - }, [isSettedCookie, isVDIConnected]); + }, [isSettedCookie, connectionsReducer?.vdi]); // VDI Test Connection function handleGetOrganization() { @@ -468,10 +502,7 @@ export default ({ children }: any) => { topicList, isSettedCookie, setIsSettedCookie, - isRosConnected, - setIsRosConnected, - isVDIConnected, - setIsVDIConnected, + connectionsReducer, setTopicList, handleForceUpdate, handleResetRobot, diff --git a/src/hooks/useRobot.tsx b/src/hooks/useRobot.tsx index 490d6786..2695de1b 100644 --- a/src/hooks/useRobot.tsx +++ b/src/hooks/useRobot.tsx @@ -15,10 +15,7 @@ interface IuseRobot { setTopicList: any; isSettedCookie: boolean | null; setIsSettedCookie: any; - isRosConnected: boolean | null; - setIsRosConnected: any; - isVDIConnected: boolean | null; - setIsVDIConnected: any; + connectionsReducer: any; handleForceUpdate: any; handleResetRobot: () => void; }