Skip to content

Commit

Permalink
auto update robot picture every 500ms
Browse files Browse the repository at this point in the history
  • Loading branch information
00magikarp committed Jul 23, 2024
1 parent 6f51aa7 commit 88937b8
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions scoutingapp/src/components/img/RobotImage.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from "react"
import React, {useEffect, useState} from "react"
import { ComponentSetup } from "../interface"
import QRCode from "react-qr-code";

export const emptyImage = <img
style={{width: "80%", height: "80%", alignItems: 'center', justifyContent: 'center'}}
Expand All @@ -8,6 +9,7 @@ export const emptyImage = <img
/>

export function RobotImage(props: ComponentSetup) {
const [componentInside, setComponentInside] = useState(<></>)
const robotNumber = props.getValue["TeamNumber"]

const makeAltText = (robotNumber: string) => {
Expand All @@ -18,11 +20,20 @@ export function RobotImage(props: ComponentSetup) {
}
}

return (
<img
style={{ height: "60%", alignItems: 'center', justifyContent: 'center', margin: "auto" }}
src={`./src/components/img/${robotNumber}.png`}
alt={makeAltText(robotNumber)}
/>
)
useEffect(() => {
const interval = setInterval(() => {
setComponentInside(
<img
style={{height: "60%", alignItems: 'center', justifyContent: 'center', margin: "auto"}}
src={`./src/components/img/${robotNumber}.png`}
alt={makeAltText(robotNumber)}
/>
)
}, 500);
return () => clearInterval(interval);
})

return (<>
{componentInside}
</>)
}

0 comments on commit 88937b8

Please sign in to comment.