Skip to content

Commit

Permalink
Fix robotPage fetchrobot
Browse files Browse the repository at this point in the history
  • Loading branch information
OleDrange committed Jul 20, 2023
1 parent 5dd9a25 commit 823c202
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
6 changes: 4 additions & 2 deletions frontend/src/components/Pages/RobotPage/RobotArmMovement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ export function MoveRobotArm({ robot, armPosition, isRobotAvailable }: RobotProp
const moveArmButtonStyle = () => {
if (!usable)
return {
backgroundColor: tokens.colors.text.static_icons__tertiary.hex,
cursor: 'auto',
backgroundColor: tokens.colors.interactive.disabled__fill.hex,
color: tokens.colors.interactive.disabled__text.hex,
borderColor: tokens.colors.interactive.disabled__border.hex,
cursor: 'not-allowed',
}
}
const openPopover = () => {
Expand Down
26 changes: 11 additions & 15 deletions frontend/src/components/Pages/RobotPage/RobotPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,31 +46,27 @@ const VerticalContent = styled.div<{ $alignItems?: string }>`

const updateSiteTimer = 1000
export function RobotPage() {
const { robotId } = useParams()
const [selectedRobot, setSelectedRobot] = useState<Robot>()
const { robotId } = useParams()

useEffect(() => {
if (robotId) {
BackendAPICaller.getRobotById(robotId).then((robot) => {
setSelectedRobot(robot)
})
}
fetchRobotData()
}, [robotId])

useEffect(() => {
const intervalId = setInterval(() => {
if (selectedRobot) {
BackendAPICaller.getRobotById(selectedRobot.id).then((updatedRobot) => {
setSelectedRobot(updatedRobot)
})
}
}, updateSiteTimer)

const intervalId = setInterval(fetchRobotData, updateSiteTimer)
return () => {
clearInterval(intervalId)
}
}, [selectedRobot])
}, [])

const fetchRobotData = () => {
if (robotId) {
BackendAPICaller.getRobotById(robotId).then((robot) => {
setSelectedRobot(robot)
})
}
}
return (
<>
<Header page={'robot'} />
Expand Down

0 comments on commit 823c202

Please sign in to comment.