Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

fix link preview & loading

ammarahm-ed593d2c970ec5
diff --git a/apps/mobile/share/index.js b/apps/mobile/share/index.js
index f37456aca..b1c15dd2c 100644
--- a/apps/mobile/share/index.js
+++ b/apps/mobile/share/index.js
@@ -21,7 +21,6 @@ import {useSafeAreaInsets} from 'react-native-safe-area-context';
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
import WebView from 'react-native-webview';
import ShareExtension from 'rn-extensions-share';
-import validator from 'validator';
import {
eSendEvent,
eSubscribeEvent,
@@ -33,6 +32,7 @@ import Storage from '../src/utils/storage';
import {sleep} from '../src/utils/TimeUtils';
import {Search} from './search';
import {useShareStore} from './store';
+import isURL from 'validator/lib/isURL';
const AnimatedKAV = Animated.createAnimatedComponent(KeyboardAvoidingView);
const AnimatedSAV = Animated.createAnimatedComponent(SafeAreaView);
@@ -220,7 +220,7 @@ const NotesnookShare = ({quicknote = false}) => {
for (item of data) {
if (item.type === 'text') {
setRawData(item);
- if (validator.isURL(item.value)) {
+ if (isURL(item.value)) {
note = await showLinkPreview(note, item.value);
} else {
note.content.data = makeHtmlFromPlainText(item.value);
@@ -371,7 +371,7 @@ const NotesnookShare = ({quicknote = false}) => {
return {...note};
});
} else {
- let html = validator.isURL(rawData.value)
+ let html = isURL(rawData.value)
? makeHtmlFromUrl(rawData.value)
: makeHtmlFromPlainText(rawData.value);
setNote(note => {
@@ -679,7 +679,7 @@ const NotesnookShare = ({quicknote = false}) => {
paddingRight: 80,
alignItems: 'center'
}}>
- {rawData.value && validator.isURL(rawData.value) ? (
+ {rawData.value && isURL(rawData.value) ? (
<Button
color={mode == 2 ? colors.shade : colors.nav}
icon={modes[2].icon}
diff --git a/apps/mobile/src/services/Validation.js b/apps/mobile/src/services/Validation.js
index a0b9dc8cb..88a757a9a 100644
--- a/apps/mobile/src/services/Validation.js
+++ b/apps/mobile/src/services/Validation.js
@@ -1,8 +1,8 @@
-import validator from 'validator';
+import isEmail from 'validator/lib/isEmail';
export function validateEmail(email) {
if (email && email.length > 0) {
- return validator.isEmail(email)
+ return isEmail(email)
} else {
return false;
}
diff --git a/apps/mobile/src/views/Editor/tiny/toolbar/linkinput.js b/apps/mobile/src/views/Editor/tiny/toolbar/linkinput.js
index a5a350a13..1623c3d85 100644
--- a/apps/mobile/src/views/Editor/tiny/toolbar/linkinput.js
+++ b/apps/mobile/src/views/Editor/tiny/toolbar/linkinput.js
@@ -15,7 +15,9 @@ import {
properties
} from './constants';
import LinkPreview from './linkpreview';
-import validator from 'validator';
+import isURL from 'validator/lib/isURL';
+import isEmail from 'validator/lib/isEmail';
+import isMobilePhone from "validator/lib/isMobilePhone";
import Input from '../../../../components/Input';
let inputValue = null;
@@ -76,8 +78,8 @@ const ToolbarLinkInput = ({format, value, setVisible}) => {
formatSelection(execCommands.unlink);
setVisible(false);
} else {
- if (!inputValue.includes('://')) inputValue = 'https://' + inputValue;
- if (!validator.isURL(inputValue)) {
+
+ if (!isURL(inputValue) || !isEmail(inputValue) || !isMobilePhone(inputValue)) {
ToastEvent.show({
heading: 'Invalid url',
message: 'Please enter a valid url',
diff --git a/apps/mobile/src/views/Editor/tiny/toolbar/linkpreview.js b/apps/mobile/src/views/Editor/tiny/toolbar/linkpreview.js
index c3d12a60b..ea206fa88 100644
--- a/apps/mobile/src/views/Editor/tiny/toolbar/linkpreview.js
+++ b/apps/mobile/src/views/Editor/tiny/toolbar/linkpreview.js
@@ -1,6 +1,6 @@
import {getLinkPreview} from 'link-preview-js';
import React, {useEffect, useState} from 'react';
-import {Image, ScrollView, TouchableOpacity, View} from 'react-native';
+import {Image, Linking, ScrollView, TouchableOpacity, View} from 'react-native';
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
import {ActionIcon} from '../../../../components/ActionIcon';
import Heading from '../../../../components/Typography/Heading';
@@ -9,10 +9,11 @@ import {useTracked} from '../../../../provider';
import {openLinkInBrowser} from '../../../../utils/functions';
import {SIZE} from '../../../../utils/SizeUtils';
import {INPUT_MODE, properties, reFocusEditor} from './constants';
-import validator from 'validator';
+import isEmail from 'validator/lib/isEmail';
+import isURL from 'validator/lib/isURL';
+import isMobilePhone from "validator/lib/isMobilePhone";
import { ToastEvent } from '../../../../services/EventManager';
-
let prevLink = {};
const LinkPreview = ({setMode, value, onSubmit}) => {
const [state] = useTracked();
@@ -91,8 +92,23 @@ const LinkPreview = ({setMode, value, onSubmit}) => {
};
const openLink = () => {
-
- if (validator.isURL(value)) {
+
+ if (value.startsWith("mailto:") || value.startsWith("tel:") || value.startsWith("sms:")) {
+ Linking.openURL(value).catch(console.log);
+ return;
+ }
+
+ if (isEmail(value)) {
+ Linking.openURL(`mailto:${value}`).catch(console.log);
+ return;
+ }
+
+ if (isMobilePhone(value)) {
+ Linking.openURL(`tel:${value}`).catch(console.log);
+ return;
+ }
+
+ if (isURL(value)) {
openLinkInBrowser(value, colors)
.catch(e => {})
.then(async r => {