Merge pull request #2004 from Lanthoiba2022/AgentImageFix1

Fix #1983: Agent image fallback added
This commit is contained in:
Alex
2025-10-06 14:47:26 +01:00
committed by GitHub
7 changed files with 57 additions and 29 deletions

View File

@@ -0,0 +1,40 @@
import { useState, useEffect } from 'react';
import Robot from '../assets/robot.svg';
type AgentImageProps = {
src?: string | null;
alt?: string;
className?: string;
fallbackSrc?: string;
};
export default function AgentImage({
src,
alt = 'agent',
className = '',
fallbackSrc = Robot,
}: AgentImageProps) {
const [currentSrc, setCurrentSrc] = useState(
src && src.trim() !== '' ? src : fallbackSrc,
);
useEffect(() => {
const newSrc = src && src.trim() !== '' ? src : fallbackSrc;
if (newSrc !== currentSrc) {
setCurrentSrc(newSrc);
}
}, [src, fallbackSrc]);
return (
<img
src={currentSrc}
alt={alt}
className={className}
referrerPolicy="no-referrer"
crossOrigin="anonymous"
onError={() => {
if (currentSrc !== fallbackSrc) setCurrentSrc(fallbackSrc);
}}
/>
);
}