From 638752a0c8f6e447103ee90f9a46647f2d919632 Mon Sep 17 00:00:00 2001 From: Eddasol Date: Thu, 9 Nov 2023 13:33:37 +0100 Subject: [PATCH] Prevent all robots from showing while loading --- .../FrontPage/RobotCards/RobotStatusView.tsx | 33 ++++++++----------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/frontend/src/components/Pages/FrontPage/RobotCards/RobotStatusView.tsx b/frontend/src/components/Pages/FrontPage/RobotCards/RobotStatusView.tsx index 1efbfdf46..c65fb2679 100644 --- a/frontend/src/components/Pages/FrontPage/RobotCards/RobotStatusView.tsx +++ b/frontend/src/components/Pages/FrontPage/RobotCards/RobotStatusView.tsx @@ -18,12 +18,13 @@ const RobotView = styled.div` grid-column: 1/ -1; gap: 1rem; ` + export function RobotStatusSection() { const { TranslateText } = useLanguageContext() const { installationCode } = useInstallationContext() - const [robots, setRobots] = useState([]) const { enabledRobots } = useRobotContext() const { safeZoneStatus, switchSafeZoneStatus } = useSafeZoneContext() + const [robots, setRobots] = useState([]) useEffect(() => { const sortRobotsByStatus = (robots: Robot[]): Robot[] => { @@ -32,7 +33,13 @@ export function RobotStatusSection() { ) return sortedRobots } - setRobots(sortRobotsByStatus(enabledRobots)) + const relevantRobots = sortRobotsByStatus( + enabledRobots.filter(function (robot) { + return robot.currentInstallation.toLocaleLowerCase() === installationCode.toLocaleLowerCase() + }) + ) + setRobots(relevantRobots) + const missionQueueFozenStatus = enabledRobots .map((robot: Robot) => { return robot.missionQueueFrozen @@ -41,26 +48,12 @@ export function RobotStatusSection() { if (missionQueueFozenStatus.length > 0 && !safeZoneStatus) switchSafeZoneStatus(true) else switchSafeZoneStatus(false) - }, [enabledRobots]) - - const filteredRobots = robots.filter(function (robot) { - return ( - robot.currentInstallation.toLocaleLowerCase() === installationCode.toLocaleLowerCase() || - (typeof robot.currentInstallation === 'string' && robot.currentInstallation.includes('default')) || - !robot.currentInstallation - ) - }) + }, [enabledRobots, installationCode]) const getRobotDisplay = () => { - if (installationCode === '') { - return robots.map(function (robot) { - return - }) - } else { - return filteredRobots.map(function (robot) { - return - }) - } + return robots.map(function (robot) { + return + }) } return (