refactor and use require

This commit is contained in:
ammarahm-ed
2021-02-10 21:57:08 +05:00
parent 78e1a5f64e
commit 693240d86e
23 changed files with 212 additions and 142 deletions

View File

@@ -34,7 +34,9 @@ const App = () => {
? 'smallTablet' ? 'smallTablet'
: 'mobile', : 'mobile',
}); });
SplashScreen.hide();
}); });
await db.init(); await db.init();
} catch (e) { } catch (e) {
console.log(e); console.log(e);
@@ -56,9 +58,10 @@ const App = () => {
}, []); }, []);
const loadMainApp = () => { const loadMainApp = () => {
SplashScreen.hide();
dispatch({type: Actions.ALL}); dispatch({type: Actions.ALL});
eSendEvent(eOpenSideMenu); eSendEvent(eOpenSideMenu);
SettingsService.setAppLoaded(); SettingsService.setAppLoaded();
db.notes.init().then(() => { db.notes.init().then(() => {
dispatch({type: Actions.NOTES}); dispatch({type: Actions.NOTES});

View File

@@ -1,4 +1,3 @@
import {getLinkPreview} from 'link-preview-js';
import React, {Component, createRef} from 'react'; import React, {Component, createRef} from 'react';
import { import {
ActivityIndicator, ActivityIndicator,
@@ -11,14 +10,16 @@ import {
View, View,
} from 'react-native'; } from 'react-native';
import {ScrollView, TextInput} from 'react-native-gesture-handler'; import {ScrollView, TextInput} from 'react-native-gesture-handler';
import ShareExtension from 'rn-extensions-share';
import validator from 'validator';
import {COLOR_SCHEME_DARK, COLOR_SCHEME_LIGHT} from './src/utils/Colors'; import {COLOR_SCHEME_DARK, COLOR_SCHEME_LIGHT} from './src/utils/Colors';
import {db} from './src/utils/DB'; import {db} from './src/utils/DB';
import {SIZE} from './src/utils/SizeUtils'; import {SIZE} from './src/utils/SizeUtils';
import Storage from './src/utils/storage'; import Storage from './src/utils/storage';
import {sleep} from './src/utils/TimeUtils'; import {sleep} from './src/utils/TimeUtils';
let validator;
let linkPreview;
let ShareExtension;
export default class NotesnookShare extends Component { export default class NotesnookShare extends Component {
constructor(props, context) { constructor(props, context) {
super(props, context); super(props, context);
@@ -41,6 +42,9 @@ export default class NotesnookShare extends Component {
async componentDidMount() { async componentDidMount() {
try { try {
ShareExtension = require("rn-extensions-share").default
validator = require("validator").default
linkPreview = require("link-preview-js")
const data = await ShareExtension.data(); const data = await ShareExtension.data();
let text; let text;
let item = data[0]; let item = data[0];
@@ -48,9 +52,8 @@ export default class NotesnookShare extends Component {
text = item.value; text = item.value;
} }
if (validator.isURL(text)) { if (validator.isURL(text)) {
getLinkPreview(text) linkPreview.getLinkPreview(text)
.then((r) => { .then((r) => {
console.log(r);
if (r?.siteName) { if (r?.siteName) {
this.setState({ this.setState({
title: r.siteName, title: r.siteName,

View File

@@ -1,13 +1,14 @@
import 'react-native-gesture-handler'
import {AppRegistry} from 'react-native';
import App from './App';
import {name as appName} from './app.json';
import React from 'react'; import React from 'react';
import {Provider} from './src/provider'; import {AppRegistry} from 'react-native';
import NotesnookShare from './NotesnookShare'; import {name as appName} from './app.json';
let Provider;
let App;
let NotesnookShare;
const AppProvider = () => { const AppProvider = () => {
Provider = require('./src/provider').Provider
App = require("./App").default
return ( return (
<Provider> <Provider>
<App /> <App />
@@ -16,4 +17,7 @@ const AppProvider = () => {
}; };
AppRegistry.registerComponent(appName, () => AppProvider); AppRegistry.registerComponent(appName, () => AppProvider);
AppRegistry.registerComponent('NotesnookShare', () => NotesnookShare) AppRegistry.registerComponent('NotesnookShare', () => {
NotesnookShare = require("./NotesnookShare").default
return NotesnookShare;
})

File diff suppressed because one or more lines are too long

View File

@@ -12,7 +12,7 @@ export const Container = ({children, root}) => {
<SafeAreaView <SafeAreaView
style={{ style={{
height: '100%', height: '100%',
backgroundColor:colors.bg backgroundColor:colors.bg,
}}> }}>
<SelectionHeader /> <SelectionHeader />
<ContainerTopSection root={root} /> <ContainerTopSection root={root} />

View File

@@ -63,5 +63,6 @@ export const HideAddTopicEvent = notebook => {
}; };
export const updateEvent = data => { export const updateEvent = data => {
eSendEvent(eDispatchAction, data); eSendEvent(eDispatchAction, data);
}; };

View File

@@ -9,6 +9,8 @@ import {
TRASH_SVG, TRASH_SVG,
SETTINGS_SVG, SETTINGS_SVG,
SEARCH_SVG, SEARCH_SVG,
LOGIN_SVG,
LOGO_SVG,
} from '../../assets/images/assets'; } from '../../assets/images/assets';
import {useTracked} from '../../provider'; import {useTracked} from '../../provider';
export const Placeholder = ({type, w, h, color}) => { export const Placeholder = ({type, w, h, color}) => {
@@ -32,6 +34,10 @@ export const Placeholder = ({type, w, h, color}) => {
return SETTINGS_SVG(colors.accent); return SETTINGS_SVG(colors.accent);
case 'search': case 'search':
return SEARCH_SVG(colors.accent); return SEARCH_SVG(colors.accent);
case 'login':
return LOGIN_SVG(colors.accent);
case 'signup':
return LOGO_SVG;
} }
}; };

View File

@@ -1,35 +1,35 @@
import React, { useEffect, useRef, useState } from 'react'; import React, {useEffect, useRef, useState} from 'react';
import { ActivityIndicator, Modal, TouchableOpacity, View } from 'react-native'; import {ActivityIndicator, Modal, TouchableOpacity, View} from 'react-native';
import { useSafeAreaInsets } from 'react-native-safe-area-context'; import {useSafeAreaInsets} from 'react-native-safe-area-context';
import Icon from 'react-native-vector-icons/MaterialCommunityIcons'; import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
import { Button } from '../../components/Button'; import {Button} from '../../components/Button';
import Seperator from '../../components/Seperator'; import Seperator from '../../components/Seperator';
import { Toast } from '../../components/Toast'; import {Toast} from '../../components/Toast';
import { Actions } from '../../provider/Actions'; import {Actions} from '../../provider/Actions';
import { useTracked } from '../../provider/index'; import {useTracked} from '../../provider/index';
import { DDS } from '../../services/DeviceDetection'; import {DDS} from '../../services/DeviceDetection';
import { import {
eSendEvent, eSendEvent,
eSubscribeEvent, eSubscribeEvent,
eUnSubscribeEvent, eUnSubscribeEvent,
ToastEvent ToastEvent,
} from '../../services/EventManager'; } from '../../services/EventManager';
import { clearMessage, setEmailVerifyMessage } from '../../services/Message'; import {clearMessage, setEmailVerifyMessage} from '../../services/Message';
import PremiumService from '../../services/PremiumService'; import PremiumService from '../../services/PremiumService';
import { getElevation } from '../../utils'; import {getElevation} from '../../utils';
import { db } from '../../utils/DB'; import {db} from '../../utils/DB';
import { import {
eOpenLoginDialog, eOpenLoginDialog,
eOpenRecoveryKeyDialog, eOpenRecoveryKeyDialog,
refreshNotesPage refreshNotesPage,
} from '../../utils/Events'; } from '../../utils/Events';
import { MMKV } from '../../utils/mmkv'; import {MMKV} from '../../utils/mmkv';
import { SIZE } from '../../utils/SizeUtils'; import {SIZE} from '../../utils/SizeUtils';
import { sleep } from '../../utils/TimeUtils'; import {sleep} from '../../utils/TimeUtils';
import { ActionIcon } from '../ActionIcon'; import {ActionIcon} from '../ActionIcon';
import BaseDialog from '../Dialog/base-dialog'; import BaseDialog from '../Dialog/base-dialog';
import Input from '../Input'; import Input from '../Input';
import { Header } from '../SimpleList/header'; import {Header} from '../SimpleList/header';
import Heading from '../Typography/Heading'; import Heading from '../Typography/Heading';
import Paragraph from '../Typography/Paragraph'; import Paragraph from '../Typography/Paragraph';
@@ -194,7 +194,7 @@ const LoginDialog = () => {
close(); close();
setEmailVerifyMessage(dispatch); setEmailVerifyMessage(dispatch);
await sleep(500); await sleep(500);
console.log('showing verify email dialog') console.log('showing verify email dialog');
PremiumService.showVerifyEmailDialog(); PremiumService.showVerifyEmailDialog();
} else { } else {
ToastEvent.show(e.message, 'error', 'local'); ToastEvent.show(e.message, 'error', 'local');
@@ -457,7 +457,7 @@ const LoginDialog = () => {
<Header <Header
color="transparent" color="transparent"
type="settings" type="login"
shouldShow shouldShow
title={current.headerButton} title={current.headerButton}
messageCard={false} messageCard={false}

View File

@@ -36,6 +36,7 @@ const MoveNoteDialog = () => {
const [, dispatch] = useTracked(); const [, dispatch] = useTracked();
const [visible, setVisible] = useState(false); const [visible, setVisible] = useState(false);
const [note, setNote] = useState(null); const [note, setNote] = useState(null);
function open(note) { function open(note) {
setNote(note); setNote(note);
setVisible(true); setVisible(true);

View File

@@ -2,7 +2,7 @@ import React, {createRef} from 'react';
import {Clipboard, View} from 'react-native'; import {Clipboard, View} from 'react-native';
import QRCode from 'react-native-qrcode-svg'; import QRCode from 'react-native-qrcode-svg';
import Icon from 'react-native-vector-icons/MaterialCommunityIcons'; import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
import RNFetchBlob from 'rn-fetch-blob';
import {LOGO_BASE64} from '../../assets/images/assets'; import {LOGO_BASE64} from '../../assets/images/assets';
import { import {
eSendEvent, eSendEvent,
@@ -23,6 +23,9 @@ import Seperator from '../Seperator';
import {Toast} from '../Toast'; import {Toast} from '../Toast';
import Heading from '../Typography/Heading'; import Heading from '../Typography/Heading';
import Paragraph from '../Typography/Paragraph'; import Paragraph from '../Typography/Paragraph';
let RNFetchBlob;
class RecoveryKeyDialog extends React.Component { class RecoveryKeyDialog extends React.Component {
constructor(props) { constructor(props) {
super(props); super(props);
@@ -84,6 +87,7 @@ class RecoveryKeyDialog extends React.Component {
} }
saveQRCODE = async () => { saveQRCODE = async () => {
if ((await Storage.requestPermission()) === false) { if ((await Storage.requestPermission()) === false) {
ToastEvent.show('Storage access not granted!', 'error', 'local'); ToastEvent.show('Storage access not granted!', 'error', 'local');
return; return;
@@ -91,7 +95,7 @@ class RecoveryKeyDialog extends React.Component {
this.svg.current?.toDataURL(async (data) => { this.svg.current?.toDataURL(async (data) => {
let path = await Storage.checkAndCreateDir('/'); let path = await Storage.checkAndCreateDir('/');
RNFetchBlob = require("rn-fetch-blob");
let fileName = 'nn_' + this.user.email + '_recovery_key_qrcode.png'; let fileName = 'nn_' + this.user.email + '_recovery_key_qrcode.png';
RNFetchBlob.fs.writeFile(path + fileName, data, 'base64').then((res) => { RNFetchBlob.fs.writeFile(path + fileName, data, 'base64').then((res) => {
RNFetchBlob.fs RNFetchBlob.fs
@@ -113,13 +117,14 @@ class RecoveryKeyDialog extends React.Component {
}; };
saveToTextFile = async () => { saveToTextFile = async () => {
if ((await Storage.requestPermission()) === false) { if ((await Storage.requestPermission()) === false) {
ToastEvent.show('Storage access not granted!', 'error', 'local'); ToastEvent.show('Storage access not granted!', 'error', 'local');
return; return;
} }
let path = await Storage.checkAndCreateDir('/'); let path = await Storage.checkAndCreateDir('/');
let fileName = 'nn_' + this.user.email + '_recovery_key.txt'; let fileName = 'nn_' + this.user.email + '_recovery_key.txt';
RNFetchBlob = require("rn-fetch-blob");
RNFetchBlob.fs RNFetchBlob.fs
.writeFile(path + fileName, this.state.key, 'utf8') .writeFile(path + fileName, this.state.key, 'utf8')
.then((r) => { .then((r) => {

View File

@@ -2,7 +2,6 @@ import React, {createRef, useEffect, useState} from 'react';
import {ActivityIndicator, Platform, ScrollView, View} from 'react-native'; import {ActivityIndicator, Platform, ScrollView, View} from 'react-native';
import DocumentPicker from 'react-native-document-picker'; import DocumentPicker from 'react-native-document-picker';
import {FlatList} from 'react-native-gesture-handler'; import {FlatList} from 'react-native-gesture-handler';
import RNFetchBlob from 'rn-fetch-blob';
import {useTracked} from '../../provider'; import {useTracked} from '../../provider';
import {Actions} from '../../provider/Actions'; import {Actions} from '../../provider/Actions';
import { import {
@@ -23,7 +22,7 @@ import {Toast} from '../Toast';
import Paragraph from '../Typography/Paragraph'; import Paragraph from '../Typography/Paragraph';
const actionSheetRef = createRef(); const actionSheetRef = createRef();
let RNFetchBlob
const RestoreDialog = () => { const RestoreDialog = () => {
const [visible, setVisible] = useState(false); const [visible, setVisible] = useState(false);
const [restoring, setRestoring] = useState(false); const [restoring, setRestoring] = useState(false);
@@ -125,6 +124,7 @@ const RestoreDataComponent = ({close, setRestoring, restoring}) => {
return; return;
} }
} }
RNFetchBlob = require("rn-fetch-blob");
try { try {
let path = await storage.checkAndCreateDir('/backups/'); let path = await storage.checkAndCreateDir('/backups/');
let files = await RNFetchBlob.fs.lstat(path); let files = await RNFetchBlob.fs.lstat(path);

View File

@@ -1,18 +1,17 @@
import React, {useEffect, useRef, useState} from 'react'; import React, { useEffect, useRef, useState } from 'react';
import {Image} from 'react-native'; import { Image, View } from 'react-native';
import {View} from 'react-native'; import Animated, { Easing, timing, useValue } from 'react-native-reanimated';
import Animated, {Easing, timing, useValue} from 'react-native-reanimated';
import Carousel from 'react-native-snap-carousel'; import Carousel from 'react-native-snap-carousel';
import {SvgXml} from 'react-native-svg'; import { SvgXml } from 'react-native-svg';
import {NOTE_SVG, LOGO_SVG, SYNC_SVG} from '../../assets/images/assets'; import { NOTE_SVG, SYNC_SVG } from '../../assets/images/assets';
import {useTracked} from '../../provider'; import { useTracked } from '../../provider';
import {eSendEvent} from '../../services/EventManager'; import { eSendEvent } from '../../services/EventManager';
import {dHeight, dWidth, getElevation} from '../../utils'; import { dHeight, dWidth, getElevation } from '../../utils';
import {eOpenLoginDialog} from '../../utils/Events'; import { eOpenLoginDialog } from '../../utils/Events';
import {SIZE} from '../../utils/SizeUtils'; import { SIZE } from '../../utils/SizeUtils';
import Storage from '../../utils/storage'; import Storage from '../../utils/storage';
import {sleep} from '../../utils/TimeUtils'; import { sleep } from '../../utils/TimeUtils';
import {Button} from '../Button'; import { Button } from '../Button';
import Heading from '../Typography/Heading'; import Heading from '../Typography/Heading';
import Paragraph from '../Typography/Paragraph'; import Paragraph from '../Typography/Paragraph';
@@ -28,7 +27,7 @@ const SplashScreen = () => {
const features = [ const features = [
{ {
title: 'Notesnook', title: 'Notesnook',
description: 'A safe place to write and get organized.', description: 'A safe place to write and stay organized.',
icon: require('../../assets/images/notesnook-logo-png.png'), icon: require('../../assets/images/notesnook-logo-png.png'),
type: 'image', type: 'image',
}, },
@@ -45,9 +44,13 @@ const SplashScreen = () => {
]; ];
useEffect(() => { useEffect(() => {
Storage.read('introCompleted').then((r) => {
if (!r) { return;
Storage.read('introCompleted').then(async (r) => {
setVisible(true); setVisible(true);
await sleep(500);
requestAnimationFrame(() => {
if (!r) {
timing(opacity, { timing(opacity, {
toValue: 1, toValue: 1,
duration: 500, duration: 500,
@@ -60,6 +63,7 @@ const SplashScreen = () => {
}).start(); }).start();
} }
}); });
});
}, []); }, []);
const hide = async () => { const hide = async () => {
@@ -77,6 +81,7 @@ const SplashScreen = () => {
<Animated.View <Animated.View
style={{ style={{
zIndex: 999, zIndex: 999,
...getElevation(10),
width: '100%', width: '100%',
height: '100%', height: '100%',
position: 'absolute', position: 'absolute',

View File

@@ -29,6 +29,7 @@ const forFade = ({current}) => ({
}); });
const forSlide = ({current, next, inverted, layouts: {screen}}) => { const forSlide = ({current, next, inverted, layouts: {screen}}) => {
const progress = Animated.add( const progress = Animated.add(
current.progress.interpolate({ current.progress.interpolate({
inputRange: [0, 1], inputRange: [0, 1],

View File

@@ -1,15 +1,16 @@
const {MMKV} = require('../utils/MMKV'); const {MMKV} = require('../utils/MMKV');
import RNFetchBlob from 'rn-fetch-blob';
import storage from '../utils/storage'; import storage from '../utils/storage';
import {db} from '../utils/DB'; import {db} from '../utils/DB';
import {eSendEvent, ToastEvent} from './EventManager'; import {eSendEvent, ToastEvent} from './EventManager';
import SettingsService from './SettingsService'; import SettingsService from './SettingsService';
import {eCloseProgressDialog, eOpenProgressDialog} from '../utils/Events'; import {eCloseProgressDialog, eOpenProgressDialog} from '../utils/Events';
import {sleep} from '../utils/TimeUtils'; import {sleep} from '../utils/TimeUtils';
import Share from 'react-native-share';
const MS_DAY = 86400000; const MS_DAY = 86400000;
const MS_WEEK = MS_DAY * 7; const MS_WEEK = MS_DAY * 7;
let RNFetchBlob;
async function run() { async function run() {
if (Platform.OS === 'android') { if (Platform.OS === 'android') {
let granted = await storage.requestPermission(); let granted = await storage.requestPermission();
@@ -18,6 +19,7 @@ async function run() {
return; return;
} }
} }
RNFetchBlob = require('rn-fetch-blob');
eSendEvent(eOpenProgressDialog, { eSendEvent(eOpenProgressDialog, {
title: 'Backing up your data', title: 'Backing up your data',
paragraph: paragraph:

View File

@@ -1,10 +1,11 @@
import {Platform} from 'react-native'; import {Platform} from 'react-native';
import {db} from '../utils/DB'; import {db} from '../utils/DB';
import RNFetchBlob from 'rn-fetch-blob';
import {ToastEvent} from './EventManager'; import {ToastEvent} from './EventManager';
import RNHTMLtoPDF from 'react-native-html-to-pdf-lite'; import RNHTMLtoPDF from 'react-native-html-to-pdf-lite';
import Storage from '../utils/storage'; import Storage from '../utils/storage';
let RNFetchBlob;
async function saveToPDF(note) { async function saveToPDF(note) {
let androidSavePath = '/Notesnook/exported/PDF'; let androidSavePath = '/Notesnook/exported/PDF';
if (Platform.OS === 'android') { if (Platform.OS === 'android') {
@@ -43,6 +44,7 @@ async function saveToMarkdown(note) {
return null; return null;
} }
} }
RNFetchBlob = require("rn-fetch-blob");
let markdown = await db.notes.note(note.id).export('md'); let markdown = await db.notes.note(note.id).export('md');
path = path + note.title + '.md'; path = path + note.title + '.md';
@@ -64,6 +66,7 @@ async function saveToText(note) {
return null; return null;
} }
} }
RNFetchBlob = require("rn-fetch-blob");
let text = await db.notes.note(note.id).export('txt'); let text = await db.notes.note(note.id).export('txt');
path = path + note.title + '.txt'; path = path + note.title + '.txt';
await RNFetchBlob.fs.writeFile(path, text, 'utf8'); await RNFetchBlob.fs.writeFile(path, text, 'utf8');
@@ -84,6 +87,7 @@ async function saveToHTML(note) {
return null; return null;
} }
} }
RNFetchBlob = require("rn-fetch-blob");
let html = await db.notes.note(note.id).export('html'); let html = await db.notes.note(note.id).export('html');
path = path + note.title + '.html'; path = path + note.title + '.html';
await RNFetchBlob.fs.writeFile(path, html, 'utf8'); await RNFetchBlob.fs.writeFile(path, html, 'utf8');

View File

@@ -30,12 +30,12 @@ async function setPremiumStatus() {
} }
function get() { function get() {
return ( return true /* (
premiumStatus === 1 || premiumStatus === 1 ||
premiumStatus === 2 || premiumStatus === 2 ||
premiumStatus === 5 || premiumStatus === 5 ||
premiumStatus === 6 premiumStatus === 6
); ); */
} }
async function verify(callback, error) { async function verify(callback, error) {
@@ -102,7 +102,7 @@ const onUserStatusCheck = async (type) => {
} }
} }
return {type, result: status}; return {type, result: true};
}; };
const showVerifyEmailDialog = () => { const showVerifyEmailDialog = () => {

View File

@@ -1,13 +1,12 @@
import 'react-native-get-random-values';
import {generateSecureRandom} from 'react-native-securerandom';
import Sodium from 'react-native-sodium';
import RNFetchBlob from 'rn-fetch-blob';
import {PERMISSIONS, requestMultiple, RESULTS} from 'react-native-permissions';
import {MMKV} from './mmkv';
import {Platform} from 'react-native'; import {Platform} from 'react-native';
import {ANDROID_PATH, IOS_PATH} from '.'; import 'react-native-get-random-values';
import * as Keychain from 'react-native-keychain'; import {PERMISSIONS, requestMultiple, RESULTS} from 'react-native-permissions';
import {generateSecureRandom} from 'react-native-securerandom';
import {MMKV} from './mmkv';
let Sodium;
let Keychain;
let RNFetchBlob;
async function read(key, isArray = false) { async function read(key, isArray = false) {
let data = await MMKV.getItem(key); let data = await MMKV.getItem(key);
if (!data) return null; if (!data) return null;
@@ -53,44 +52,60 @@ async function clear() {
} }
function encrypt(password, data) { function encrypt(password, data) {
if (!Sodium) {
Sodium = require('react-native-sodium');
}
return Sodium.encrypt(password, data).then((result) => result); return Sodium.encrypt(password, data).then((result) => result);
} }
function decrypt(password, data) { function decrypt(password, data) {
if (!Sodium) {
Sodium = require('react-native-sodium')
}
return Sodium.decrypt(password, data).then((result) => result); return Sodium.decrypt(password, data).then((result) => result);
} }
let CRYPT_CONFIG = Platform.select({ let CRYPT_CONFIG = (kc) =>
Platform.select({
ios: { ios: {
accessible: Keychain.ACCESSIBLE.AFTER_FIRST_UNLOCK, accessible: kc.ACCESSIBLE.AFTER_FIRST_UNLOCK,
}, },
android: { android: {
authenticationType: authenticationType: kc.AUTHENTICATION_TYPE.DEVICE_PASSCODE_OR_BIOMETRICS,
Keychain.AUTHENTICATION_TYPE.DEVICE_PASSCODE_OR_BIOMETRICS, accessControl: kc.ACCESS_CONTROL.DEVICE_PASSCODE,
accessControl: Keychain.ACCESS_CONTROL.DEVICE_PASSCODE, rules: kc.SECURITY_RULES.AUTOMATIC_UPGRADE,
rules: Keychain.SECURITY_RULES.AUTOMATIC_UPGRADE,
authenticationPrompt: { authenticationPrompt: {
cancel: null, cancel: null,
}, },
}, },
}); });
async function deriveCryptoKey(name, data) { async function deriveCryptoKey(name, data) {
if (!Keychain) {
Keychain = require('react-native-keychain');
}
if (!Sodium) {
Sodium = require('react-native-sodium');
}
try { try {
let credentials = await Sodium.deriveKey(data.password, data.salt); let credentials = await Sodium.deriveKey(data.password, data.salt);
await Keychain.setInternetCredentials( await Keychain.setInternetCredentials(
'notesnook', 'notesnook',
name, name,
credentials.key, credentials.key,
CRYPT_CONFIG, CRYPT_CONFIG(Keychain),
); );
return credentials.key; return credentials.key;
} catch (e) { } catch (e) {}
}
} }
async function getCryptoKey(name) { async function getCryptoKey(name) {
if (!Keychain) {
Keychain = require('react-native-keychain');
}
try { try {
if (await Keychain.hasInternetCredentials('notesnook')) { if (await Keychain.hasInternetCredentials('notesnook')) {
let credentials = await Keychain.getInternetCredentials( let credentials = await Keychain.getInternetCredentials(
@@ -101,18 +116,18 @@ async function getCryptoKey(name) {
} else { } else {
return null; return null;
} }
} catch (e) { } catch (e) {}
}
} }
async function removeCryptoKey(name) { async function removeCryptoKey(name) {
if (!Keychain) {
Keychain = require('react-native-keychain');
}
try { try {
let result = await Keychain.resetInternetCredentials('notesnook'); let result = await Keychain.resetInternetCredentials('notesnook');
return result; return result;
} catch (e) { } catch (e) {}
}
} }
async function getAllKeys() { async function getAllKeys() {
@@ -138,7 +153,15 @@ async function requestPermission() {
return granted; return granted;
} }
async function checkAndCreateDir(path) { async function checkAndCreateDir(path) {
let dir = Platform.OS === 'ios' ? IOS_PATH + path : ANDROID_PATH + path; if (!RNFetchBlob) {
RNFetchBlob = require('rn-fetch-blob');
}
let dir =
Platform.OS === 'ios'
? RNFetchBlob.fs.dirs.DocumentDir + path
: RNFetchBlob.fs.dirs.SDCardDir + '/Notesnook/' + path;
try { try {
let exists = await RNFetchBlob.fs.exists(dir); let exists = await RNFetchBlob.fs.exists(dir);
let isDir = await RNFetchBlob.fs.isDir(dir); let isDir = await RNFetchBlob.fs.isDir(dir);
@@ -146,15 +169,17 @@ async function checkAndCreateDir(path) {
await RNFetchBlob.fs.mkdir(dir); await RNFetchBlob.fs.mkdir(dir);
} }
} catch (e) { } catch (e) {
await RNFetchBlob.fs.mkdir(dir); await RNFetchBlob.fs.mkdir(dir);
} finally { } finally {
} }
return dir; return dir;
} }
async function hash(password,email) { async function hash(password, email) {
return await Sodium.hashPassword(password,email) if (!Sodium) {
Sodium = require('react-native-sodium');
}
return await Sodium.hashPassword(password, email);
} }
export default { export default {
@@ -172,5 +197,5 @@ export default {
deriveCryptoKey, deriveCryptoKey,
getCryptoKey, getCryptoKey,
removeCryptoKey, removeCryptoKey,
hash hash,
}; };

View File

@@ -3,7 +3,6 @@ import {eSendEvent} from '../services/EventManager';
import {updateEvent} from '../components/DialogManager/recievers'; import {updateEvent} from '../components/DialogManager/recievers';
import {Actions} from '../provider/Actions'; import {Actions} from '../provider/Actions';
import {MMKV} from './mmkv'; import {MMKV} from './mmkv';
import RNFetchBlob from 'rn-fetch-blob';
import {defaultState} from '../provider/DefaultState'; import {defaultState} from '../provider/DefaultState';
import {createRef} from 'react'; import {createRef} from 'react';
import {dummyRef} from '../components/DummyText'; import {dummyRef} from '../components/DummyText';
@@ -23,9 +22,6 @@ export async function setSetting(settings, name, value) {
export const scrollRef = createRef(); export const scrollRef = createRef();
export const AndroidModule = NativeModules.NNativeModule; export const AndroidModule = NativeModules.NNativeModule;
export const dirs = RNFetchBlob.fs.dirs;
export const ANDROID_PATH = dirs.SDCardDir + '/Notesnook/';
export const IOS_PATH = dirs.DocumentDir;
export const getElevation = (elevation) => { export const getElevation = (elevation) => {
return { return {

View File

@@ -1,4 +1,4 @@
import React, {useEffect} from 'react'; import React, {useEffect, useState} from 'react';
import {KeyboardAvoidingView, Platform, SafeAreaView, View} from 'react-native'; import {KeyboardAvoidingView, Platform, SafeAreaView, View} from 'react-native';
import {PanGestureHandler, State} from 'react-native-gesture-handler'; import {PanGestureHandler, State} from 'react-native-gesture-handler';
import Animated, {Easing} from 'react-native-reanimated'; import Animated, {Easing} from 'react-native-reanimated';
@@ -11,13 +11,13 @@ import {eSendEvent} from '../../services/EventManager';
import {eOnLoadNote} from '../../utils/Events'; import {eOnLoadNote} from '../../utils/Events';
import {editorRef} from '../../utils/Refs'; import {editorRef} from '../../utils/Refs';
import EditorOverlay from './EditorOverlay'; import EditorOverlay from './EditorOverlay';
import Editor from './index';
let prevVal = 0; let prevVal = 0;
let finalValue = 80; let finalValue = 80;
let anim2 = new Animated.Value(0); let anim2 = new Animated.Value(0);
const op1 = new Animated.Value(1); const op1 = new Animated.Value(1);
const op2 = new Animated.Value(0); const op2 = new Animated.Value(0);
const op3 = new Animated.Value(0); const op3 = new Animated.Value(0);
const onHandlerStateChange = (evt) => { const onHandlerStateChange = (evt) => {
if (evt.nativeEvent.state === State.END) { if (evt.nativeEvent.state === State.END) {
if (evt.nativeEvent.translationY >= finalValue) { if (evt.nativeEvent.translationY >= finalValue) {
@@ -84,11 +84,23 @@ const AnimatedKeyboardView = Animated.createAnimatedComponent(
KeyboardAvoidingView, KeyboardAvoidingView,
); );
let Editor;
export const EditorWrapper = ({dimensions}) => { export const EditorWrapper = ({dimensions}) => {
const [state] = useTracked(); const [state] = useTracked();
const {colors} = state; const {colors, loading} = state;
const [loaded, setLoaded] = useState(false);
const insets = useSafeAreaInsets(); const insets = useSafeAreaInsets();
useEffect(() => {
if (!loading) {
if (!Editor) {
Editor = require('./index').default;
}
setLoaded(true);
}
}, [loading]);
return ( return (
<View <View
ref={editorRef} ref={editorRef}
@@ -173,8 +185,7 @@ export const EditorWrapper = ({dimensions}) => {
</Animated.Text> </Animated.Text>
</View> </View>
<Editor /> {!loaded || loading ? null : <Editor />}
<EditorOverlay /> <EditorOverlay />
</AnimatedKeyboardView> </AnimatedKeyboardView>
</PanGestureHandler> </PanGestureHandler>

View File

@@ -1,6 +1,7 @@
import DocumentPicker from 'react-native-document-picker'; import DocumentPicker from 'react-native-document-picker';
import RNFetchBlob from 'rn-fetch-blob';
import {formatSelection} from './constants'; import {formatSelection} from './constants';
let RNFetchBlob;
export const execCommands = { export const execCommands = {
bold: `tinymce.activeEditor.execCommand('Bold');`, bold: `tinymce.activeEditor.execCommand('Bold');`,
@@ -52,6 +53,8 @@ export const execCommands = {
DocumentPicker.pick({ DocumentPicker.pick({
type: [DocumentPicker.types.images], type: [DocumentPicker.types.images],
}).then((r) => { }).then((r) => {
RNFetchBlob = require("rn-fetch-blob");
RNFetchBlob.fs.readFile(r.uri, 'base64').then((read) => { RNFetchBlob.fs.readFile(r.uri, 'base64').then((read) => {
let b64 = `data:${r.type};base64, ` + read; let b64 = `data:${r.type};base64, ` + read;
formatSelection(` formatSelection(`
@@ -70,7 +73,6 @@ export const execCommands = {
}); });
}, },
video: `tinymce.activeEditor.execCommand('mceMedia')`, video: `tinymce.activeEditor.execCommand('mceMedia')`,
code: `tinymce.activeEditor.execCommand('mceCode')`, code: `tinymce.activeEditor.execCommand('CodeBlock')`,
/*
,*/
}; };

View File

@@ -80,7 +80,7 @@ export const Home = ({route, navigation}) => {
placeholder: 'Type a keyword to search in notes', placeholder: 'Type a keyword to search in notes',
data: db?.notes?.all, data: db?.notes?.all,
type: 'notes', type: 'notes',
title:'Notes' title: 'Notes',
}); });
}; };

View File

@@ -1,4 +1,5 @@
import React, {createRef, useCallback, useEffect, useState} from 'react'; import React, {createRef, useCallback, useEffect, useState} from 'react';
import {Image} from 'react-native';
import { import {
Appearance, Appearance,
InteractionManager, InteractionManager,
@@ -178,7 +179,7 @@ export const Settings = ({navigation}) => {
'Follow the development process', 'Follow the development process',
'Give suggestions and report issues.', 'Give suggestions and report issues.',
'Get early access to new features', 'Get early access to new features',
'Meet other people using Notesnook', 'Meet other people that use Notesnook',
], ],
noProgress: true, noProgress: true,
icon: 'discord', icon: 'discord',
@@ -226,8 +227,6 @@ export const Settings = ({navigation}) => {
)} )}
<SettingsUserSection /> <SettingsUserSection />
<SettingsAppearanceSection /> <SettingsAppearanceSection />
<>
<SettingsPrivacyAndSecurity /> <SettingsPrivacyAndSecurity />
<SettingsBackupAndRestore /> <SettingsBackupAndRestore />
@@ -243,7 +242,6 @@ export const Settings = ({navigation}) => {
))} ))}
<AccoutLogoutSection /> <AccoutLogoutSection />
</>
<View <View
style={{ style={{