mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-25 00:49:10 +00:00
refactor: hide logo on error
This commit is contained in:
committed by
Carlos Valente
parent
eb897a2a23
commit
6e5805977a
@@ -1,3 +1,5 @@
|
|||||||
|
import { useRef } from 'react';
|
||||||
|
|
||||||
import { projectLogoPath } from '../../api/constants';
|
import { projectLogoPath } from '../../api/constants';
|
||||||
|
|
||||||
import './ViewLogo.scss';
|
import './ViewLogo.scss';
|
||||||
@@ -7,13 +9,19 @@ interface ViewLogoProps {
|
|||||||
className: string;
|
className: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function ViewLogo(props: ViewLogoProps) {
|
export default function ViewLogo({ name, className }: ViewLogoProps) {
|
||||||
const { name, className } = props;
|
const imageRef = useRef<HTMLImageElement>(null);
|
||||||
|
|
||||||
|
const hideImage = () => {
|
||||||
|
if (!imageRef.current) return;
|
||||||
|
|
||||||
|
imageRef.current.style.display = 'none';
|
||||||
|
};
|
||||||
|
|
||||||
// we wrap the image in a div to help maintain the aspect ratio
|
// we wrap the image in a div to help maintain the aspect ratio
|
||||||
return (
|
return (
|
||||||
<div className={className}>
|
<div className={className}>
|
||||||
<img alt='' src={`${projectLogoPath}/${name}`} className='viewLogo' />
|
<img ref={imageRef} alt='' src={`${projectLogoPath}/${name}`} className='viewLogo' onError={hideImage} />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user