From ef5b21e7ae829cb2533ee4d99f5c31a165bcaa28 Mon Sep 17 00:00:00 2001 From: alex Date: Mon, 23 Oct 2023 18:46:57 +0200 Subject: [PATCH] fixed some errors --- src/Contexts/WebSocketContext.js | 13 ++++----- src/Handlers/WebSocketMessageHandler.js | 38 ++++++++++++++++--------- src/Pages/Robotics/Robots/index.js | 5 ++++ 3 files changed, 35 insertions(+), 21 deletions(-) diff --git a/src/Contexts/WebSocketContext.js b/src/Contexts/WebSocketContext.js index 0151d70..a695691 100644 --- a/src/Contexts/WebSocketContext.js +++ b/src/Contexts/WebSocketContext.js @@ -126,17 +126,14 @@ export default function WebSocketProvider({ }; const SendSocketMessage = (cmd, body) => { - if (isWebSocketReady && ws.current !== null) { + if ( + isWebSocketReady && + ws.current !== null && + ws.current.readyState === 1 + ) { ws.current.send(JSON.stringify({ Cmd: cmd, Body: body })); } else { - /*notificationApi["error"]({ - message: `Websocket is not ready`, - description: `Please check your internet connection`, - }); */ - wsMessageCache.current.push({ Cmd: cmd, Body: body }); - - // message.error(`Websocket is not ready`); } }; diff --git a/src/Handlers/WebSocketMessageHandler.js b/src/Handlers/WebSocketMessageHandler.js index 2c3c4de..f3e9be1 100644 --- a/src/Handlers/WebSocketMessageHandler.js +++ b/src/Handlers/WebSocketMessageHandler.js @@ -238,10 +238,8 @@ export function handleWebSocketMessage( }); console.log( - "a", - scannerContext - .checkboxAutomaticRecognitionOfEquipmentDocumentationCheckedRef - .current + "here1", + scannerContext.checkboxAutomaticFillingOfInputFieldsCheckedRef.current ); if ( @@ -250,19 +248,33 @@ export function handleWebSocketMessage( .current && IsScannedQrCodeValid(body) ) { - OpenScannedEquipmentDocumentation({ - navigate: navigate, - scannedEquipment: JSON.parse(body).stockitem.toString(), - }); - } else if ( + let item = null; + + // check if body is json + try { + item = JSON.parse(body).stockitem.toString(); + } catch (error) {} + + if (item !== null) { + OpenScannedEquipmentDocumentation({ + navigate: navigate, + scannedEquipment: item, + }); + } + } + + if ( scannerContext.checkboxAutomaticFillingOfInputFieldsCheckedRef.current ) { // get the current focused input on the page and set the value const foundInput = document.activeElement; - - if (!foundInput) break; - - setNativeValue(foundInput, body); + console.log( + "here", + scannerContext.checkboxAutomaticFillingOfInputFieldsCheckedRef.current + ); + if (foundInput) { + setNativeValue(foundInput, body); + } } break; diff --git a/src/Pages/Robotics/Robots/index.js b/src/Pages/Robotics/Robots/index.js index 8a7aad4..3c13654 100644 --- a/src/Pages/Robotics/Robots/index.js +++ b/src/Pages/Robotics/Robots/index.js @@ -350,6 +350,8 @@ export default function Robots() { const getRobotsTableItems = (robots) => { let items = []; + if (robots === undefined || robots.length === 0) return items; + robots.sort((a, b) => new Date(b.CreatedAt) - new Date(a.CreatedAt)); robots.forEach((robot) => @@ -471,6 +473,9 @@ export default function Robots() { const getUnauthorizedTableItems = (unauthorizedRobots) => { let items = []; + if (unauthorizedRobots === undefined || unauthorizedRobots.length === 0) + return items; + unauthorizedRobots.forEach((robot) => { items.push({ key: robot.Id,