-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* removced prefetch of images * fixed e2e
- Loading branch information
Showing
14 changed files
with
40 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,25 @@ | ||
import { Translate } from 'app/I18N'; | ||
import React, { useState, useEffect } from 'react'; | ||
import React, { useState } from 'react'; | ||
|
||
interface ImageViewerProps { | ||
key?: string; | ||
className?: string; | ||
src: string; | ||
alt: string; | ||
className?: string; | ||
} | ||
|
||
const ImageViewer = ({ alt, src, className }: ImageViewerProps) => { | ||
const [imageExists, setImageExists] = useState<boolean | null>(null); | ||
const ImageViewer = (props: ImageViewerProps) => { | ||
const [errorFlag, setErrorFlag] = useState(false); | ||
|
||
useEffect(() => { | ||
const checkImageExists = async (url: string) => { | ||
try { | ||
const response = await fetch(url, { method: 'GET' }); | ||
setImageExists(Boolean(response.ok)); | ||
} catch (error) { | ||
setImageExists(false); | ||
} | ||
}; | ||
|
||
// eslint-disable-next-line no-void | ||
void checkImageExists(src); | ||
}, [src]); | ||
if (imageExists === false) { | ||
return ( | ||
<div className="media-error"> | ||
<Translate>Image not found</Translate> | ||
</div> | ||
); | ||
} | ||
|
||
if (errorFlag) { | ||
return ( | ||
<div className="media-error"> | ||
<Translate>This file type is not supported on media fields</Translate> | ||
<Translate>Error loading your image</Translate> | ||
</div> | ||
); | ||
} | ||
|
||
if (imageExists === null) { | ||
return <Translate>Loading</Translate>; | ||
} | ||
|
||
return <img className={className} src={src} onError={() => setErrorFlag(true)} alt={alt} />; | ||
return <img {...props} onError={() => setErrorFlag(true)} alt={props.alt} />; | ||
}; | ||
|
||
export { ImageViewer, type ImageViewerProps }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters