generated from layer5io/layer5-repo-template
-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: sudhanshu dasgupta <[email protected]>
- Loading branch information
1 parent
2e5995f
commit e5c042a
Showing
4 changed files
with
33 additions
and
1 deletion.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
packages/components/src/custom/Helpers/UrlValidator/image-url-validation.tsx
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
type DispatchImageFunction = (url: string) => void; | ||
|
||
const handleImageValidation = async (url: string, dispatchImage: DispatchImageFunction): Promise<boolean> => { | ||
try { | ||
const img = new Image(); | ||
img.src = url; | ||
|
||
await new Promise<void>((resolve, reject) => { | ||
img.onload = () => resolve(); | ||
img.onerror = () => reject(); | ||
}); | ||
|
||
dispatchImage(url); | ||
return true; // Image loaded successfully | ||
} catch (error) { | ||
return false; // Image failed to load | ||
} | ||
}; | ||
|
||
export default handleImageValidation; |
3 changes: 3 additions & 0 deletions
3
packages/components/src/custom/Helpers/UrlValidator/index.tsx
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import handleImageValidation from './image-url-validation'; | ||
|
||
export { handleImageValidation }; |
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