From 41b50d64298bfe0aa767aaae20f4e46b30332b7d Mon Sep 17 00:00:00 2001 From: Taso Date: Wed, 3 Mar 2021 22:16:43 -0500 Subject: [PATCH] tweak(phone/utils): Moved isImageValid util to common dir --- .../apps/twitter/components/AddTweetModal.tsx | 3 ++- phone/src/apps/twitter/utils/images.ts | 17 ----------------- phone/src/common/utils/isImageValid.ts | 16 ++++++++++++++++ 3 files changed, 18 insertions(+), 18 deletions(-) create mode 100644 phone/src/common/utils/isImageValid.ts diff --git a/phone/src/apps/twitter/components/AddTweetModal.tsx b/phone/src/apps/twitter/components/AddTweetModal.tsx index a2f8d34..13263c7 100644 --- a/phone/src/apps/twitter/components/AddTweetModal.tsx +++ b/phone/src/apps/twitter/components/AddTweetModal.tsx @@ -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'; diff --git a/phone/src/apps/twitter/utils/images.ts b/phone/src/apps/twitter/utils/images.ts index 6bd1144..7c923be 100644 --- a/phone/src/apps/twitter/utils/images.ts +++ b/phone/src/apps/twitter/utils/images.ts @@ -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} link - Will resolve the promise with the link string - * if valid. Will reject if failed. - */ -export function isImageValid(link: string): Promise { - return new Promise((res, rej) => { - const image = new Image(); - image.src = link; - image.onerror = () => rej(`Invalid image, ${link}`); - image.onload = () => res(link); - }); -} diff --git a/phone/src/common/utils/isImageValid.ts b/phone/src/common/utils/isImageValid.ts new file mode 100644 index 0000000..9fd56f1 --- /dev/null +++ b/phone/src/common/utils/isImageValid.ts @@ -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} link - Will resolve the promise with the link string + * if valid. Will reject if failed. + */ +export function isImageValid(link: string): Promise { + return new Promise((res, rej) => { + const image = new Image(); + image.src = link; + image.onerror = () => rej(`Invalid image, ${link}`); + image.onload = () => res(link); + }); +}