Skip to content

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

fix link input and preview

ammarahm-ed2509a9517d0b
diff --git a/apps/mobile/src/views/Editor/tiny/toolbar/linkinput.js b/apps/mobile/src/views/Editor/tiny/toolbar/linkinput.js
index 00556e963..807a7145c 100644
--- a/apps/mobile/src/views/Editor/tiny/toolbar/linkinput.js
+++ b/apps/mobile/src/views/Editor/tiny/toolbar/linkinput.js
@@ -1,10 +1,12 @@
import React, {useEffect, useRef, useState} from 'react';
-import {Linking, View} from 'react-native';
-import {eSendEvent} from '../../../../services/EventManager';
+import {TextInput, View} from 'react-native';
import {Button} from '../../../../components/Button';
-import Input from '../../../../components/Input';
import {useTracked} from '../../../../provider';
+import {eSendEvent} from '../../../../services/EventManager';
import {editing} from '../../../../utils';
+import {normalize, SIZE} from '../../../../utils/SizeUtils';
+import {EditorWebView} from '../../Functions';
+import tiny from '../tiny';
import {execCommands} from './commands';
import {
focusEditor,
@@ -13,10 +15,6 @@ import {
properties,
} from './constants';
import LinkPreview from './linkpreview';
-import tiny from '../tiny';
-import {EditorWebView} from '../../Functions';
-import {openLinkInBrowser} from '../../../../utils/functions';
-import {normalize, SIZE} from '../../../../utils/SizeUtils';
let inputValue = null;
@@ -34,6 +32,7 @@ const ToolbarLinkInput = ({format, value, setVisible}) => {
inputRef.current?.focus();
tiny.call(EditorWebView, tiny.restoreRange);
}
+ inputValue = value;
properties.inputMode = value ? INPUT_MODE.NO_EDIT : INPUT_MODE.EDITING;
editing.tooltip = format;
properties.userBlur = false;
@@ -49,6 +48,18 @@ const ToolbarLinkInput = ({format, value, setVisible}) => {
};
}, [format]);
+ useEffect(() => {
+ if (value && mode === INPUT_MODE.EDITING) {
+ if (properties.pauseSelectionChange) {
+ setTimeout(() => {
+ properties.pauseSelectionChange = false;
+ }, 100);
+ }
+ inputRef.current?.focus();
+ return;
+ }
+ }, [mode]);
+
const onChangeText = (value) => {
inputValue = value;
};
@@ -60,25 +71,16 @@ const ToolbarLinkInput = ({format, value, setVisible}) => {
properties.userBlur = true;
if (inputValue === '' || !inputValue) {
formatSelection(execCommands.unlink);
+ setVisible(false);
} else {
formatSelection(execCommands[format](inputValue));
}
- tiny.call(EditorWebView, tiny.restoreRange + tiny.clearRange);
-
- setVisible(false);
editing.tooltip = null;
+ setMode(INPUT_MODE.NO_EDIT);
focusEditor(format);
properties.userBlur = false;
};
- const onPress = async () => {
- openLinkInBrowser(value, colors)
- .catch((e) => ToastEvent.show(e.message, 'error'))
- .then((r) => {
- console.log('closed');
- });
- };
-
const onBlur = async () => {
tiny.call(EditorWebView, tiny.clearRange);
formatSelection(`current_selection_range = null`);
@@ -101,26 +103,32 @@ const ToolbarLinkInput = ({format, value, setVisible}) => {
<LinkPreview value={value} setMode={setMode} onSubmit={onSubmit} />
) : (
<>
- <Input
- fwdRef={inputRef}
- onBlurInput={onBlur}
- onPress={onPress}
- height={normalize(45) }
+ <TextInput
+ ref={inputRef}
+ onBlur={onBlur}
+ style={{
+ height: normalize(50),
+ color: colors.pri,
+ zIndex: 10,
+ flexGrow: 1,
+ }}
+ autoCapitalize="none"
+ autoCorrect={false}
onSubmit={onSubmit}
onChangeText={onChangeText}
defaultValue={value}
blurOnSubmit={false}
- loading={mode === INPUT_MODE.NO_EDIT}
placeholder="Enter link"
+ placeholderTextColor={colors.nav}
/>
{mode === INPUT_MODE.EDITING && (
<Button
title="Save"
onPress={onSubmit}
- height={normalize(40) }
+ height={normalize(40)}
fontSize={SIZE.md}
- style={{marginLeft: 10}}
+ style={{marginLeft: 10, paddingHorizontal: 12}}
/>
)}
</>
diff --git a/apps/mobile/src/views/Editor/tiny/toolbar/linkpreview.js b/apps/mobile/src/views/Editor/tiny/toolbar/linkpreview.js
index f832be21e..5d9461080 100644
--- a/apps/mobile/src/views/Editor/tiny/toolbar/linkpreview.js
+++ b/apps/mobile/src/views/Editor/tiny/toolbar/linkpreview.js
@@ -1,19 +1,18 @@
-import {getLinkPreview} from 'link-preview-js';
-import React, {useEffect, useState} from 'react';
-import {Image, View} from 'react-native';
-import {TouchableOpacity} from 'react-native-gesture-handler';
+import { getLinkPreview } from 'link-preview-js';
+import React, { useEffect, useState } from 'react';
+import { Image, ScrollView, View } from 'react-native';
+import { TouchableOpacity } from 'react-native-gesture-handler';
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
-import {Button} from '../../../../components/Button';
+import { ActionIcon } from '../../../../components/ActionIcon';
import Heading from '../../../../components/Typography/Heading';
import Paragraph from '../../../../components/Typography/Paragraph';
-import {useTracked} from '../../../../provider';
-import {ToastEvent} from '../../../../services/EventManager';
-import {openLinkInBrowser} from '../../../../utils/functions';
-import {SIZE} from '../../../../utils/SizeUtils';
-import {INPUT_MODE, properties} from './constants';
+import { useTracked } from '../../../../provider';
+import { openLinkInBrowser } from '../../../../utils/functions';
+import { SIZE } from '../../../../utils/SizeUtils';
+import { INPUT_MODE, properties } from './constants';
let prevLink = {};
-let prevHeight = 65;
+let prevHeight = 50;
const LinkPreview = ({setMode, value, onSubmit}) => {
const [state] = useTracked();
const {colors} = state;
@@ -50,14 +49,16 @@ const LinkPreview = ({setMode, value, onSubmit}) => {
marginVertical: 5,
borderWidth: 1,
borderColor: colors.nav,
+ backgroundColor: colors.nav,
}}
- resizeMode="cover"
+ resizeMode="center"
source={{uri: imageLink}}
/>
) : faviconLink ? (
<View
style={{
borderColor: colors.nav,
+ backgroundColor: colors.nav,
borderWidth: 1,
marginVertical: 5,
borderRadius: 5,
@@ -82,14 +83,14 @@ const LinkPreview = ({setMode, value, onSubmit}) => {
backgroundColor: colors.shade,
borderRadius: 5,
}}>
- <Icon size={40} color={colors.accent} name="web" />
+ <Icon size={height - 4} color={colors.accent} name="web" />
</View>
);
};
const openLink = () => {
openLinkInBrowser(value, colors)
- .catch((e) => ToastEvent.show(e.message, 'error'))
+ .catch((e) => {})
.then((r) => {
console.log('closed');
});
@@ -106,56 +107,26 @@ const LinkPreview = ({setMode, value, onSubmit}) => {
flex: 1,
}}>
<TouchableOpacity onPress={openLink} activeOpacity={1}>
- <Heading
- numberOfLines={1}
- style={{flexWrap: 'wrap', maxWidth: '90%', paddingLeft: 5}}
- size={SIZE.sm}>
- {name ? name + ': ' + title : title ? title : 'Web Link'}
- </Heading>
-
- <Paragraph
- style={{flexWrap: 'wrap', maxWidth: '90%', paddingLeft: 5}}
- numberOfLines={2}
- color={colors.icon}
- size={SIZE.xs}>
- {description ? description : link?.value ? link.value : value}
- </Paragraph>
-
- <View
+ <ScrollView
style={{
- flexDirection: 'row',
- alignItems: 'center',
- justifyContent: 'space-between',
- width: '100%',
- }}>
- <View
- style={{
- flexDirection: 'row',
- alignItems: 'center',
- }}>
- <Button
- onPress={() => {
- setMode(INPUT_MODE.EDITING);
- properties.inputMode = INPUT_MODE.EDITING;
- }}
- style={{
- paddingHorizontal: 6,
- }}
- height={25}
- fontSize={SIZE.sm}
- title="Edit"
- />
- <Button
- type="errorShade"
- onPress={() => {
- onSubmit('clear');
- }}
- height={25}
- fontSize={SIZE.sm}
- title="Remove"
- />
- </View>
- </View>
+ marginRight: 10,
+ }}
+ horizontal
+ showsHorizontalScrollIndicator={false}>
+ <Heading numberOfLines={1} style={{paddingLeft: 5}} size={SIZE.sm}>
+ {name ? name + ': ' + title : title ? title : 'Web Link'}
+ </Heading>
+ </ScrollView>
+
+ <ScrollView horizontal showsHorizontalScrollIndicator={false}>
+ <Paragraph
+ style={{flexWrap: 'wrap', paddingLeft: 5}}
+ numberOfLines={1}
+ color={colors.icon}
+ size={SIZE.xs}>
+ {description ? description : link?.value ? link.value : value}
+ </Paragraph>
+ </ScrollView>
</TouchableOpacity>
</View>
);
@@ -166,12 +137,40 @@ const LinkPreview = ({setMode, value, onSubmit}) => {
{renderImage(link.image, link.favicon)}
{renderText(link.name, link.title, link.description)}
- <Button
- type="shade"
- title="Visit"
- icon="open-in-new"
- onPress={openLink}
- />
+ <View
+ style={{
+ flexDirection: 'row',
+ alignItems: 'center',
+ }}>
+ <ActionIcon
+ onPress={() => {
+ onSubmit('clear');
+ }}
+ customStyle={{
+ width: 40,
+ marginHorizontal: 10,
+ height: 40,
+ }}
+ name="delete"
+ size={SIZE.xl}
+ color={colors.pri}
+ />
+ <ActionIcon
+ onPress={async () => {
+ properties.pauseSelectionChange = true;
+ setMode(INPUT_MODE.EDITING);
+ properties.inputMode = INPUT_MODE.EDITING;
+ }}
+ customStyle={{
+ width: 40,
+ marginHorizontal: 10,
+ height: 40,
+ }}
+ name="pencil"
+ size={SIZE.xl}
+ color={colors.pri}
+ />
+ </View>
</>
);
};