tweak(phone/utils): Moved isImageValid util to common dir

This commit is contained in:
Taso authored and Taso committed 2021-03-03 22:19:59 -05:00
1 parent 18c1676c01
commit 41b50d6429
3 files changed
+18 -18

No files matched your search

@@ -4,7 +4,8 @@ import { v4 as uuidv4 } from 'uuid';
import Nui from '../../../os/nui-events/utils/Nui';
import Modal from '../../../ui/components/Modal';
import { IMAGE_DELIMITER, isImageValid } from '../utils/images';
import { IMAGE_DELIMITER } from '../utils/images';
import { isImageValid } from '../../../common/utils/isImageValid';
import { useModal } from '../hooks/useModal';
import EmojiSelect from './EmojiSelect';
import ImageDisplay from './images/ImageDisplay';
-17
View File
@@ -4,20 +4,3 @@
// within specification). To get around this we have our own delimiter
// here we'll use to join and split these strings
export const IMAGE_DELIMITER = '||!||';
/**
* Returns a Promise that validates that the URL successfully
* loads in the browser. If the URL doesn't load the promise is
* rejected.
* @param {string} link - a URL we are trying to validate
* @returns {Promise<string>} link - Will resolve the promise with the link string
* if valid. Will reject if failed.
*/
export function isImageValid(link: string): Promise<string> {
return new Promise((res, rej) => {
const image = new Image();
image.src = link;
image.onerror = () => rej(`Invalid image, ${link}`);
image.onload = () => res(link);
});
}
+16
View File
@@ -0,0 +1,16 @@
/**
* Returns a Promise that validates that the URL successfully
* loads in the browser. If the URL doesn't load the promise is
* rejected.
* @param {string} link - a URL we are trying to validate
* @returns {Promise<string>} link - Will resolve the promise with the link string
* if valid. Will reject if failed.
*/
export function isImageValid(link: string): Promise<string> {
return new Promise((res, rej) => {
const image = new Image();
image.src = link;
image.onerror = () => rej(`Invalid image, ${link}`);
image.onload = () => res(link);
});
}