refactor the location

This commit is contained in:
Reinaldo Neto 2022-12-19 12:34:47 -03:00
parent b3e028ce24
commit 257489d85c
3 changed files with 5 additions and 6 deletions

View File

@ -14,6 +14,7 @@ import EventEmitter from '../../lib/methods/helpers/events';
import I18n from '../../i18n'; import I18n from '../../i18n';
import MessageContext from './Context'; import MessageContext from './Context';
import { IUrl } from '../../definitions'; import { IUrl } from '../../definitions';
import { isImage, isValidURL } from '../../lib/methods/helpers';
const styles = StyleSheet.create({ const styles = StyleSheet.create({
button: { button: {
@ -94,11 +95,6 @@ const UrlContent = React.memo(
} }
); );
const isImage = (url: string) => {
const regExpUrlImage = new RegExp(/\.(jpg|jpeg|png|webp|avif|gif|svg)$/);
return regExpUrlImage.test(url);
};
const Url = React.memo( const Url = React.memo(
({ url, index, theme }: { url: IUrl; index: number; theme: TSupportedThemes }) => { ({ url, index, theme }: { url: IUrl; index: number; theme: TSupportedThemes }) => {
if (!url || url?.ignoreParse) { if (!url || url?.ignoreParse) {
@ -117,7 +113,7 @@ const Url = React.memo(
if (url.image) { if (url.image) {
imageUrl = url.image; imageUrl = url.image;
} else { } else {
imageUrl = isImage(url.url) ? url.url : ''; imageUrl = isImage(url.url) && isValidURL(url.url) ? url.url : '';
} }
return ( return (

View File

@ -0,0 +1,2 @@
const regExpUrlImage = new RegExp(/\.(jpg|jpeg|png|webp|avif|gif|svg)$/);
export const isImage = (url: string) => regExpUrlImage.test(url);

View File

@ -14,3 +14,4 @@ export * from './server';
export * from './url'; export * from './url';
export * from './isValidEmail'; export * from './isValidEmail';
export * from './random'; export * from './random';
export * from './image';