Skip to content

Commit

Permalink
Prevent all robots from showing while loading
Browse files Browse the repository at this point in the history
  • Loading branch information
Eddasol committed Nov 9, 2023
1 parent 61678f3 commit 638752a
Showing 1 changed file with 13 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<Robot[]>([])
const { enabledRobots } = useRobotContext()
const { safeZoneStatus, switchSafeZoneStatus } = useSafeZoneContext()
const [robots, setRobots] = useState<Robot[]>([])

useEffect(() => {
const sortRobotsByStatus = (robots: Robot[]): Robot[] => {
Expand All @@ -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
Expand All @@ -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 <RobotStatusCard key={robot.id} robot={robot} />
})
} else {
return filteredRobots.map(function (robot) {
return <RobotStatusCard key={robot.id} robot={robot} />
})
}
return robots.map(function (robot) {
return <RobotStatusCard key={robot.id} robot={robot} />
})
}

return (
Expand Down

0 comments on commit 638752a

Please sign in to comment.