Skip to content

Commit

Permalink
show gray placeholder image when no number inputted, change alt text
Browse files Browse the repository at this point in the history
  • Loading branch information
00magikarp committed Jul 24, 2024
1 parent 7436aed commit 3fc408d
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions scoutingapp/src/components/img/RobotImage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,26 @@ export function RobotImage(props: ComponentSetup) {
const [componentInside, setComponentInside] = useState(<></>)
const robotNumber = props.getValue["TeamNumber"]

const makeAltText = (robotNumber: string) => {
if (robotNumber) {
return `Picture of robot ${robotNumber}`
} else {
return 'Insert robot number above'
}
}

useEffect(() => {
const interval = setInterval(() => {
setComponentInside(
<img
style={{ width: "50%", height: "50%", alignItems: 'center', justifyContent: 'center', margin: "auto"}}
src={`./src/components/img/${robotNumber}.png`}
alt={makeAltText(robotNumber)}
/>
)
}, 500);
if (robotNumber) {
setComponentInside(
<img
style={{ width: "50%", height: "50%", alignItems: 'center', justifyContent: 'center', margin: "auto"}}
src={`./src/components/img/${robotNumber}.png`}
alt={`Image of robot ${robotNumber} not found.`}
/>
)
} else {
setComponentInside(
<img
style={{ width: "50%", height: "50%", alignItems: 'center', justifyContent: 'center', margin: "auto"}}
src={`./src/components/img/gray.png`}
alt={'Insert robot number above'}
/>
)
}
}, 500)
return () => clearInterval(interval);
})

Expand Down

0 comments on commit 3fc408d

Please sign in to comment.