A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
add netInfo
ammarahm-ed2ec1a9c1a1dd
diff --git a/apps/mobile/App.js b/apps/mobile/App.jsindex 2174825ac..c53a079d6 100644--- a/apps/mobile/App.js+++ b/apps/mobile/App.js@@ -1,18 +1,20 @@-import React, { useEffect, useState } from 'react';+import React, {useEffect, useState} from 'react';import MMKV from 'react-native-mmkv-storage';import Orientation from 'react-native-orientation';-import { SafeAreaProvider } from 'react-native-safe-area-context';-import { getColorScheme, scale, updateSize } from './src/common/common';-import { useTracked } from './src/provider';-import { ACTIONS } from './src/provider/actions';-import { defaultState } from './src/provider/defaultState';-import { eSubscribeEvent, eUnSubscribeEvent } from './src/services/eventManager';-import { eDispatchAction, eStartSyncer } from './src/services/events';-import { db, DDS } from './src/utils/utils';+import {SafeAreaProvider} from 'react-native-safe-area-context';+import {getColorScheme, scale, updateSize} from './src/common/common';+import {useTracked} from './src/provider';+import {ACTIONS} from './src/provider/actions';+import {defaultState} from './src/provider/defaultState';+import {eSubscribeEvent, eUnSubscribeEvent} from './src/services/eventManager';+import {eDispatchAction, eStartSyncer} from './src/services/events';+import {db, DDS, ToastEvent} from './src/utils/utils';+import {useNetInfo} from '@react-native-community/netinfo';const App = () => {const [state, dispatch] = useTracked();const [init, setInit] = useState(false);+ const netInfo = useNetInfo();const I = DDS.isTab ? require('./index.tablet') : require('./index.mobile');const _onOrientationChange = o => {// Currently orientation is locked on tablet.@@ -22,6 +24,27 @@ const App = () => {forceUpdate();}, 1000); */};++ useEffect(() => {+ if (!netInfo.isConnected || !netInfo.isInternetReachable) {+ db.user.get().then(user => {+ if (user) {+ ToastEvent.show('No internet connection','error');+ } else {++ }+ });+ } else {+ db.user.get().then(user => {+ if (user) {+ ToastEvent.show('Internet connection restored');+ } else {++ }+ });+ }+ }, [netInfo]);+useEffect(() => {Orientation.addOrientationListener(_onOrientationChange);eSubscribeEvent(eDispatchAction, type => {@@ -51,14 +74,11 @@ const App = () => {let u = await db.user.get();try {await db.sync();- } catch(e) {-- }+ } catch (e) {}u = await db.user.get();dispatch({type: ACTIONS.USER, user: u});dispatch({type: ACTIONS.ALL});dispatch({type: ACTIONS.SYNCING, syncing: false});-};useEffect(() => {@@ -74,8 +94,9 @@ const App = () => {Initialize().then(() => {db.init().then(async () => {let user = await db.user.get();- startSyncer();dispatch({type: ACTIONS.USER, user: user});+ console.log(user);+ startSyncer();dispatch({type: ACTIONS.ALL});setInit(true);});@@ -121,7 +142,6 @@ const App = () => {<I.Initialize /></></SafeAreaProvider>-</>);};diff --git a/apps/mobile/ios/Podfile.lock b/apps/mobile/ios/Podfile.lockindex 11ba7d915..b7ede47f4 100644--- a/apps/mobile/ios/Podfile.lock+++ b/apps/mobile/ios/Podfile.lock@@ -240,6 +240,8 @@ PODS:- react-native-mmkv-storage (0.2.2):- MMKV (= 1.0.24)- React+ - react-native-netinfo (5.9.2):+ - React- react-native-orientation (3.1.3):- React- react-native-safe-area-context (0.7.3):@@ -366,6 +368,7 @@ DEPENDENCIES:- React-jsinspector (from `../node_modules/react-native/ReactCommon/jsinspector`)- react-native-get-random-values (from `../node_modules/react-native-get-random-values`)- react-native-mmkv-storage (from `../node_modules/react-native-mmkv-storage`)+ - "react-native-netinfo (from `../node_modules/@react-native-community/netinfo`)"- react-native-orientation (from `../node_modules/react-native-orientation`)- react-native-safe-area-context (from `../node_modules/react-native-safe-area-context`)- react-native-sodium (from `../node_modules/react-native-sodium`)@@ -441,6 +444,8 @@ EXTERNAL SOURCES::path: "../node_modules/react-native-get-random-values"react-native-mmkv-storage::path: "../node_modules/react-native-mmkv-storage"+ react-native-netinfo:+ :path: "../node_modules/@react-native-community/netinfo"react-native-orientation::path: "../node_modules/react-native-orientation"react-native-safe-area-context:@@ -518,6 +523,7 @@ SPEC CHECKSUMS:React-jsinspector: 512e560d0e985d0e8c479a54a4e5c147a9c83493react-native-get-random-values: 2b7500cdb68066aba87cdccd97067c29e16ffe95react-native-mmkv-storage: 4f85ac485ff25ad5b9f7b3c6cd4c8bb067b1028c+ react-native-netinfo: cb74e17062b2af5a16a4b137f32495f241df1a8ereact-native-orientation: f1caf84d65f1a4fd4511a18f2b924e634ad7a628react-native-safe-area-context: e200d4433aba6b7e60b52da5f37af11f7a0b0392react-native-sodium: c7587732667e1cdb7d0d77c2aa2e98420aad2036diff --git a/apps/mobile/src/services/validation.js b/apps/mobile/src/services/validation.jsindex 7b2986671..d5efd0a2f 100644--- a/apps/mobile/src/services/validation.js+++ b/apps/mobile/src/services/validation.js@@ -1,3 +1,5 @@+import {db} from '../utils/utils';+let regex = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;export function validateEmail(email) {@@ -27,3 +29,8 @@ export function validateUsername(username) {return false;}}++export async function checkPremiumUser() {+ let user = await db.user.get();+ return false;+}diff --git a/apps/mobile/src/utils/storage.js b/apps/mobile/src/utils/storage.jsindex fd158f2fc..cf5fc096c 100644--- a/apps/mobile/src/utils/storage.js+++ b/apps/mobile/src/utils/storage.js@@ -11,6 +11,12 @@ async function read(key, isArray = false) {}} else if (key === 'hasConflicts') {return await MMKV.getBoolAsync(key);+ } else if (key === "t") {+ try {+ return await MMKV.getStringAsync(key);+ } catch(e) {+ return null+ }} else {try {data = await MMKV.getMapAsync(key);@@ -27,7 +33,10 @@ async function write(key, data) {return await MMKV.setArrayAsync(key, data.slice());} else if (typeof data === 'boolean') {return await MMKV.setBoolAsync(key, data);+ } else if (typeof data === "number") {+ return await MMKV.setIntAsync(key, data);} else {+ console.log(key,data,"VALUE");return await MMKV.setMapAsync(key, data);}}diff --git a/apps/mobile/src/views/Login/index.js b/apps/mobile/src/views/Login/index.jsindex b1df0827f..1f72e2b88 100644--- a/apps/mobile/src/views/Login/index.js+++ b/apps/mobile/src/views/Login/index.js@@ -72,51 +72,55 @@ export const Login = ({route, navigation}) => {}, [isFocused]);const _logIn = async () => {- if (!password || password.length < 8) {- ToastEvent.show('Invalid username or password', 'error');- return;- }- if (!username) {- ToastEvent.show('Invalid username or password', 'error');+ if (+ !password ||+ password.length < 8 ||+ !username ||+ invalidPassword ||+ invalidUsername+ ) {+ ToastEvent.show('username or password invalid', 'error');return;}+setLoggingIn(true);_username.current.blur();_pass.current.blur();-setStatus('Logging in...');- if (!invalidPassword && !invalidUsername) {- try {- await db.user.login(username, password);+ try {+ let res = await db.user.login(username, password);+ if (res) {setStatus('Fetching data...');- } catch (e) {- setTimeout(() => {- ToastEvent.show(e.message, 'error');- setLoggingIn(false);- }, 500);-- return;}-- let user;- try {- user = await db.user.get();- dispatch({type: ACTIONS.USER, user: user});- dispatch({type:ACTIONS.SYNCING,syncing:true});- setStatus('Syncing your notes...');- await db.sync();- eSendEvent(eStartSyncer);- navigation.goBack();- dispatch({type: ACTIONS.ALL});- eSendEvent(refreshNotesPage);- dispatch({type:ACTIONS.SYNCING,syncing:false});- ToastEvent.show(`Logged in as ${username}`, 'success');- } catch (e) {+ } catch (e) {+ setTimeout(() => {ToastEvent.show(e.message, 'error');- }- } else {- ToastEvent.show('Login failed, username or passoword invalid', 'error');+ setLoggingIn(false);+ }, 500);++ return;+ }++ let user;++ try {+ user = await db.user.get();+ if (!user) throw new Error('Username or password incorrect');+ dispatch({type: ACTIONS.USER, user: user});+ dispatch({type: ACTIONS.SYNCING, syncing: true});+ setStatus('Syncing your notes...');+ await db.sync();+ eSendEvent(eStartSyncer);+ navigation.goBack();+ dispatch({type: ACTIONS.ALL});+ eSendEvent(refreshNotesPage);+ dispatch({type: ACTIONS.SYNCING, syncing: false});+ ToastEvent.show(`Logged in as ${username}`, 'success');+ } catch (e) {+ dispatch({type: ACTIONS.SYNCING, syncing: false});+ setLoggingIn(false);+ ToastEvent.show(e.message, 'error');}};@@ -131,14 +135,14 @@ export const Login = ({route, navigation}) => {route: route,color: null,navigation: navigation,- ind:!route.params.root+ ind: !route.params.root,},});dispatch({type: ACTIONS.CONTAINER_BOTTOM_BUTTON,state: {visible: false,- ind:!route.params.root+ ind: !route.params.root,},});dispatch({@@ -156,7 +160,7 @@ export const Login = ({route, navigation}) => {type: ACTIONS.HEADER_TEXT_STATE,state: {heading: 'Login',- ind:!route.params.root+ ind: !route.params.root,},});@@ -169,7 +173,7 @@ export const Login = ({route, navigation}) => {type: ACTIONS.SEARCH_STATE,state: {noSearch: true,- ind:!route.params.root+ ind: !route.params.root,},});if (!route.params.root) {@@ -214,11 +218,11 @@ export const Login = ({route, navigation}) => {{loggingIn ? null : (<>- <View- style={{- marginTop: Platform.OS == 'ios' ? 125 - 60 : 125 - 60,- }}- />+ <View+ style={{+ marginTop: Platform.OS == 'ios' ? 125 - 60 : 125 - 60,+ }}+ /><Viewstyle={{diff --git a/apps/mobile/src/views/Signup/index.js b/apps/mobile/src/views/Signup/index.jsindex 920151ddf..1fa474a6b 100644--- a/apps/mobile/src/views/Signup/index.js+++ b/apps/mobile/src/views/Signup/index.js@@ -14,6 +14,7 @@ import {useIsFocused} from '@react-navigation/native';import {opacity, pv, SIZE, WEIGHT, ph} from '../../common/common';import {Header} from '../../components/header';import {useTracked} from '../../provider';+import {eSubscribeEvent,eUnSubscribeEvent,@@ -74,20 +75,33 @@ export const Signup = ({route, navigation}) => {};}, [isFocused]);- const _signUp = async () => {+ const validateInfo = () => {if (!password || !email || !username || !passwordReEnter) {ToastEvent.show('All fields are required', 'error');- return;+ return false;}+if (!confirmPassword) {ToastEvent.show('Passwords do not match', 'error');- return;+ return false;}- setSigningIn(true);- setStatus('Creating your account...');+if (!invalidEmail && !invalidPassword && !invalidUsername) {+ ToastEvent.show('Signup information is invalid', 'error');+ return false;+ }++ }++ const _signUp = async () => {+ if (!validateInfo) return;++ setSigningIn(true);+ setStatus('Creating your account...');try {await db.user.signup(username, email, password);++} catch (e) {setSigningIn(false);setFailed(true);@@ -97,6 +111,8 @@ export const Signup = ({route, navigation}) => {let user;try {++user = await db.user.user.get();setStatus('Logging you in...');let k = await db.user.key();@@ -112,9 +128,7 @@ export const Signup = ({route, navigation}) => {setFailed(true);ToastEvent.show('Login Failed, try again', 'error');}- } else {- ToastEvent.show('Signup failed', 'error');- }+};useEffect(() => {