Skip to content

Commit d7dbd1f

Browse files
authored
solve the bowtie loading error (#1353)
1 parent 652f396 commit d7dbd1f

File tree

1 file changed

+29
-13
lines changed

1 file changed

+29
-13
lines changed

pages/tools/components/ToolingDetailModal.tsx

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -353,24 +353,40 @@ const BowtieReportBadge = ({ uri }: { uri: string }) => {
353353
const [loading, setLoading] = useState(true);
354354
const [error, setError] = useState(false);
355355

356+
useEffect(() => {
357+
const checkImage = async () => {
358+
try {
359+
const response = await fetch(
360+
`https://img.shields.io/endpoint?url=${encodeURIComponent(uri)}`,
361+
);
362+
if (response.ok) {
363+
setLoading(false);
364+
} else {
365+
setLoading(false);
366+
setError(true);
367+
}
368+
} catch (err) {
369+
setLoading(false);
370+
setError(true);
371+
}
372+
};
373+
checkImage();
374+
}, [uri]);
375+
356376
return (
357377
<div className='my-1'>
358378
{loading && !error && (
359379
<div className='animate-pulse bg-gray-300 dark:bg-slate-600 h-6 w-[176px] rounded-md'></div>
360380
)}
361-
<Image
362-
src={`https://img.shields.io/endpoint?url=${encodeURIComponent(uri)}`}
363-
onLoad={() => setLoading(false)}
364-
onError={() => {
365-
setLoading(false);
366-
setError(true);
367-
}}
368-
width={100}
369-
height={20}
370-
style={{ display: loading ? 'none' : 'block' }}
371-
alt='Bowtie Badge'
372-
className='my-1'
373-
/>
381+
{!loading && !error && (
382+
<Image
383+
src={`https://img.shields.io/endpoint?url=${encodeURIComponent(uri)}`}
384+
alt='Bowtie Badge'
385+
className='my-1'
386+
width={100}
387+
height={20}
388+
/>
389+
)}
374390
{error && (
375391
<div className='text-red-500 text-sm mt-1'>Failed to load badge</div>
376392
)}

0 commit comments

Comments
 (0)