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
run functions after interaction completed
ammarahm-edbf78ae4973af
diff --git a/apps/mobile/src/views/Editor/EditorHeader.js b/apps/mobile/src/views/Editor/EditorHeader.jsindex da1af6e50..eaaa62a6f 100644--- a/apps/mobile/src/views/Editor/EditorHeader.js+++ b/apps/mobile/src/views/Editor/EditorHeader.js@@ -1,48 +1,53 @@-import React, {useEffect} from 'react';-import {BackHandler, Keyboard, Platform, View} from 'react-native';+import React, { useEffect } from 'react';+import {+ BackHandler,+ InteractionManager,+ Keyboard,+ Platform,+ View+} from 'react-native';import RNExitApp from 'react-native-exit-app';-import {useSafeAreaInsets} from 'react-native-safe-area-context';-import {notesnook} from '../../../e2e/test.ids';-import {ActionIcon} from '../../components/ActionIcon';+import { useSafeAreaInsets } from 'react-native-safe-area-context';+import { notesnook } from '../../../e2e/test.ids';+import { ActionIcon } from '../../components/ActionIcon';import {ActionSheetEvent,- simpleDialogEvent,+ simpleDialogEvent} from '../../components/DialogManager/recievers';-import {TEMPLATE_EXIT_FULLSCREEN} from '../../components/DialogManager/Templates';-import {useTracked} from '../../provider';-import {DDS} from '../../services/DeviceDetection';+import { TEMPLATE_EXIT_FULLSCREEN } from '../../components/DialogManager/Templates';+import { useTracked } from '../../provider';+import { DDS } from '../../services/DeviceDetection';import {eSendEvent,eSubscribeEvent,eUnSubscribeEvent,- ToastEvent,+ ToastEvent} from '../../services/EventManager';import Navigation from '../../services/Navigation';-import {editing} from '../../utils';-import {exitEditorAnimation} from '../../utils/Animations';+import { editing } from '../../utils';import { db } from '../../utils/DB';import {eClearEditor,eCloseFullscreenEditor,eOnLoadNote,- eOpenFullscreenEditor,+ eOpenFullscreenEditor} from '../../utils/Events';-import {sideMenuRef, tabBarRef} from '../../utils/Refs';-import {EditorTitle} from './EditorTitle';+import { sideMenuRef, tabBarRef } from '../../utils/Refs';+import { EditorTitle } from './EditorTitle';import {checkNote,clearEditor,clearTimer,EditorWebView,- getIntent,+getNote,- isFromIntent,+isNotedEdited,loadNote,post,saveNote,setColors,- setIntent,+ setIntent} from './Functions';import HistoryComponent from './HistoryComponent';@@ -92,20 +97,22 @@ const EditorHeader = () => {const load = async (item) => {await loadNote(item);- Keyboard.addListener('keyboardDidShow', () => {- post('keyboard');+ InteractionManager.runAfterInteractions(() => {+ Keyboard.addListener('keyboardDidShow', () => {+ post('keyboard');+ });+ if (!DDS.isTab) {+ handleBack = BackHandler.addEventListener(+ 'hardwareBackPress',+ _onHardwareBackPress,+ );+ }});- if (!DDS.isTab) {- handleBack = BackHandler.addEventListener(- 'hardwareBackPress',- _onHardwareBackPress,- );- }};const onCallClear = async () => {if (editing.currentlyEditing) {- await _onBackPress()+ await _onBackPress();}};@@ -240,7 +247,7 @@ const EditorHeader = () => {marginLeft: 10,}}onPress={() => {- let note = getNote() && db.notes.note(getNote().id).data+ let note = getNote() && db.notes.note(getNote().id).data;ActionSheetEvent(note,true,diff --git a/apps/mobile/src/views/Favorites/index.js b/apps/mobile/src/views/Favorites/index.jsindex c4f31e190..9e661fc1b 100644--- a/apps/mobile/src/views/Favorites/index.js+++ b/apps/mobile/src/views/Favorites/index.js@@ -1,4 +1,5 @@import React, {useCallback, useEffect} from 'react';+import {InteractionManager} from 'react-native';import {Placeholder} from '../../components/ListPlaceholders';import SimpleList from '../../components/SimpleList';import {useTracked} from '../../provider';@@ -11,21 +12,28 @@ import {eScrollEvent} from '../../utils/Events';export const Favorites = ({route, navigation}) => {const [state, dispatch] = useTracked();const favorites = state.favorites;+ const [localLoad, setLocalLoad] = React.useState(true);const {loading} = state;let pageIsLoaded = false;const onFocus = useCallback(() => {- eSendEvent(eScrollEvent, {name: 'Favorites', type: 'in'});- updateSearch();- if (DDS.isLargeTablet()) {- dispatch({- type: Actions.CONTAINER_BOTTOM_BUTTON,- state: {- onPress: null,- },- });- }+ InteractionManager.runAfterInteractions(() => {+ if (localLoad) {+ setLocalLoad(false);+ }+ eSendEvent(eScrollEvent, {name: 'Favorites', type: 'in'});+ updateSearch();+ if (DDS.isLargeTablet()) {+ dispatch({+ type: Actions.CONTAINER_BOTTOM_BUTTON,+ state: {+ onPress: null,+ },+ });+ }+ });+if (!pageIsLoaded) {pageIsLoaded = true;return;@@ -72,14 +80,15 @@ export const Favorites = ({route, navigation}) => {refreshCallback={() => {dispatch({type: Actions.FAVORITES});}}- loading={loading}+ loading={loading || localLoad}placeholderData={{heading: 'Your Favorites',paragraph: 'You have not added any notes to favorites yet.',button: null,+ loading: 'Loading your favorites',}}headerProps={{- heading: "Favorites",+ heading: 'Favorites',}}focused={() => navigation.isFocused()}placeholder={<Placeholder type="favorites" />}diff --git a/apps/mobile/src/views/Folders/index.js b/apps/mobile/src/views/Folders/index.jsindex 0e748f7b9..456a078bf 100644--- a/apps/mobile/src/views/Folders/index.js+++ b/apps/mobile/src/views/Folders/index.js@@ -1,4 +1,4 @@-import React, {useCallback, useEffect} from 'react';+import React, {useCallback, useEffect, useState} from 'react';import {AddNotebookEvent} from '../../components/DialogManager/recievers';import {Placeholder} from '../../components/ListPlaceholders';import SimpleList from '../../components/SimpleList';@@ -11,23 +11,31 @@ import SearchService from '../../services/SearchService';import {eScrollEvent} from '../../utils/Events';import Navigation from '../../services/Navigation';import {DDS} from '../../services/DeviceDetection';+import {InteractionManager} from 'react-native';export const Folders = ({route, navigation}) => {const [state, dispatch] = useTracked();const notebooks = state.notebooks;+ const [loading, setLoading] = useState(true);let pageIsLoaded = false;const onFocus = useCallback(() => {- eSendEvent(eScrollEvent, {name: 'Notebooks', type: 'in'});- updateSearch();- if (DDS.isLargeTablet()) {- dispatch({- type: Actions.CONTAINER_BOTTOM_BUTTON,- state: {- onPress: _onPressBottomButton,- },- });- }+ InteractionManager.runAfterInteractions(() => {+ if (loading) {+ setLoading(false);+ }+ eSendEvent(eScrollEvent, {name: 'Notebooks', type: 'in'});+ updateSearch();+ if (DDS.isLargeTablet()) {+ dispatch({+ type: Actions.CONTAINER_BOTTOM_BUTTON,+ state: {+ onPress: _onPressBottomButton,+ },+ });+ }+ });+if (!pageIsLoaded) {pageIsLoaded = true;return;@@ -54,7 +62,6 @@ export const Folders = ({route, navigation}) => {}, []);useEffect(() => {- console.log('rerendering notebooks yeah')if (navigation.isFocused()) {updateSearch();}@@ -77,14 +84,16 @@ export const Folders = ({route, navigation}) => {type="notebooks"focused={() => navigation.isFocused()}RenderItem={NotebookItemWrapper}+ loading={loading}placeholderData={{heading: 'Your Notebooks',paragraph: 'You have not added any notebooks yet.',button: 'Add a Notebook',action: _onPressBottomButton,+ loading: 'Loading your notebooks',}}headerProps={{- heading: "Notebooks",+ heading: 'Notebooks',}}placeholder={<Placeholder type="notebooks" />}/>diff --git a/apps/mobile/src/views/Home/index.js b/apps/mobile/src/views/Home/index.jsindex da0c349b2..a3148ba76 100755--- a/apps/mobile/src/views/Home/index.js+++ b/apps/mobile/src/views/Home/index.js@@ -1,4 +1,5 @@-import React, {useCallback, useEffect} from 'react';+import React, {useCallback, useEffect, useState} from 'react';+import {InteractionManager} from 'react-native';import {ContainerBottomButton} from '../../components/Container/ContainerBottomButton';import SimpleList from '../../components/SimpleList';import {useTracked} from '../../provider';@@ -15,21 +16,28 @@ import {tabBarRef} from '../../utils/Refs';export const Home = ({route, navigation}) => {const [state, dispatch] = useTracked();const {loading} = state;+ const [localLoad, setLocalLoad] = useState(true);const notes = state.notes;let pageIsLoaded = false;const onFocus = useCallback(() => {- updateSearch();- eSendEvent(eScrollEvent, {name: 'Notes', type: 'in'});+ InteractionManager.runAfterInteractions(() => {+ if (localLoad) {+ setLocalLoad(false);+ }- if (DDS.isLargeTablet()) {- dispatch({- type: Actions.CONTAINER_BOTTOM_BUTTON,- state: {- onPress: _onPressBottomButton,- },- });- }+ updateSearch();+ eSendEvent(eScrollEvent, {name: 'Notes', type: 'in'});++ if (DDS.isLargeTablet()) {+ dispatch({+ type: Actions.CONTAINER_BOTTOM_BUTTON,+ state: {+ onPress: _onPressBottomButton,+ },+ });+ }+ });if (!pageIsLoaded) {pageIsLoaded = true;@@ -91,7 +99,7 @@ export const Home = ({route, navigation}) => {type="notes"isHome={true}pinned={true}- loading={loading}+ loading={loading || localLoad}sortMenuButton={true}headerProps={{heading: 'Notes',@@ -103,7 +111,7 @@ export const Home = ({route, navigation}) => {paragraph: 'You have not added any notes yet.',button: 'Add your First Note',action: _onPressBottomButton,- loading: 'We are loading your notes.',+ loading: 'Loading your notes.',}}/>diff --git a/apps/mobile/src/views/Notebook/index.js b/apps/mobile/src/views/Notebook/index.jsindex 6d69cdfa5..814cad20b 100644--- a/apps/mobile/src/views/Notebook/index.js+++ b/apps/mobile/src/views/Notebook/index.js@@ -1,8 +1,7 @@import React, {useEffect, useState} from 'react';+import {InteractionManager} from 'react-native';import {ContainerBottomButton} from '../../components/Container/ContainerBottomButton';-import {AddTopicEvent} from '../../components/DialogManager/recievers';import SimpleList from '../../components/SimpleList';-import {useTracked} from '../../provider';import {eSendEvent,eSubscribeEvent,@@ -18,13 +17,15 @@ import {} from '../../utils/Events';export const Notebook = ({route, navigation}) => {- const [, dispatch] = useTracked();const [topics, setTopics] = useState(route.params.notebook.topics);+ const [loading, setLoading] = useState(true);let params = route.params;let pageIsLoaded = false;const onLoad = () => {- setTopics(db.notebooks.notebook(route.params.notebook.id).data.topics);+ InteractionManager.runAfterInteractions(() => {+ setTopics(db.notebooks.notebook(route.params.notebook.id).data.topics);+ });};useEffect(() => {@@ -39,19 +40,26 @@ export const Notebook = ({route, navigation}) => {}, []);const onFocus = async () => {- eSendEvent(eScrollEvent, {name: params.title, type: 'in'});- if (route.params.menu) {- navigation.setOptions({- animationEnabled: false,- gestureEnabled: false,- });- } else {- navigation.setOptions({- animationEnabled: true,- gestureEnabled: Platform.OS === 'ios',- });- }- updateSearch();+ InteractionManager.runAfterInteractions(() => {+ if (loading) {+ setLoading(false);+ }+ eSendEvent(eScrollEvent, {name: params.title, type: 'in'});+ if (route.params.menu) {+ navigation.setOptions({+ animationEnabled: false,+ gestureEnabled: false,+ });+ } else {+ navigation.setOptions({+ animationEnabled: true,+ gestureEnabled: Platform.OS === 'ios',+ });+ }+ updateSearch();++ });+if (!pageIsLoaded) {console.log('returning since page is not loaded');pageIsLoaded = true;@@ -102,12 +110,14 @@ export const Notebook = ({route, navigation}) => {headerProps={{heading: params.title,}}+ loading={loading}focused={() => navigation.isFocused()}placeholderData={{heading: route.params.notebook.title,paragraph: 'You have not added any topics yet.',button: 'Add a Topic',action: _onPressBottomButton,+ loading: 'Loading notebook topics',}}/>diff --git a/apps/mobile/src/views/Notes/index.js b/apps/mobile/src/views/Notes/index.jsindex 095261e39..82af10c32 100644--- a/apps/mobile/src/views/Notes/index.js+++ b/apps/mobile/src/views/Notes/index.js@@ -1,5 +1,5 @@import React, {useCallback, useEffect, useState} from 'react';-import {Platform} from 'react-native';+import {InteractionManager, Platform} from 'react-native';import {ContainerBottomButton} from '../../components/Container/ContainerBottomButton';import SimpleList from '../../components/SimpleList';import {NoteItemWrapper} from '../../components/SimpleList/NoteItemWrapper';@@ -22,6 +22,8 @@ import {tabBarRef} from '../../utils/Refs';export const Notes = ({route, navigation}) => {const [state, dispatch] = useTracked();const {loading} = state;+ const [localLoad, setLocalLoad] = useState(true);+const [notes, setNotes] = useState([]);let params = route.params ? route.params : null;let pageIsLoaded = false;@@ -58,70 +60,75 @@ export const Notes = ({route, navigation}) => {};const init = (data) => {- params = route.params;- if (data) {- params = data;- }- if (route.params.menu) {- navigation.setOptions({- animationEnabled: false,- gestureEnabled: false,- });- } else {- navigation.setOptions({- animationEnabled: true,- gestureEnabled: Platform.OS === 'ios',+ InteractionManager.runAfterInteractions(() => {+ if (localLoad) {+ setLocalLoad(false);+ }+ params = route.params;+ if (data) {+ params = data;+ }+ if (route.params.menu) {+ navigation.setOptions({+ animationEnabled: false,+ gestureEnabled: false,+ });+ } else {+ navigation.setOptions({+ animationEnabled: true,+ gestureEnabled: Platform.OS === 'ios',+ });+ }+ let allNotes = [];+ if (params.type === 'tag') {+ allNotes = db.notes.tagged(params.tag.id);+ } else if (params.type === 'color') {+ allNotes = db.notes.colored(params.color.id);+ console.log('allNotes', allNotes);+ } else {+ allNotes = db.notebooks+ .notebook(params.notebookId)+ .topics.topic(params.title).all;+ }++ if (+ (params.type === 'tag' || params.type === 'color') &&+ (!allNotes || allNotes.length === 0)+ ) {+ Navigation.goBack();+ }++ setNotes([...allNotes]);+ setActionAfterFirstSave();+ updateSearch();+ dispatch({+ type: Actions.CONTAINER_BOTTOM_BUTTON,+ state: {+ onPress: _onPressBottomButton,+ color: params.type == 'color' ? COLORS_NOTE[params.title] : null,+ },});- }- let allNotes = [];- if (params.type === 'tag') {- allNotes = db.notes.tagged(params.tag.id);- } else if (params.type === 'color') {- allNotes = db.notes.colored(params.color.id);- console.log('allNotes', allNotes);- } else {- allNotes = db.notebooks- .notebook(params.notebookId)- .topics.topic(params.title).all;- }- if (- (params.type === 'tag' || params.type === 'color') &&- (!allNotes || allNotes.length === 0)- ) {- Navigation.goBack();- }+ if (!pageIsLoaded) {+ pageIsLoaded = true;+ return;+ }- setNotes([...allNotes]);- setActionAfterFirstSave();- updateSearch();- dispatch({- type: Actions.CONTAINER_BOTTOM_BUTTON,- state: {- onPress: _onPressBottomButton,- color: params.type == 'color' ? COLORS_NOTE[params.title] : null,- },- });-- if (!pageIsLoaded) {- pageIsLoaded = true;- return;- }-- Navigation.setHeaderState('Notes', params, {- heading:- params.type === 'tag'- ? '#' + params.title- : params.title.slice(0, 1).toUpperCase() + params.title.slice(1),- id:- params.type === 'tag'- ? params.tag.id- : params.type === 'topic'- ? params.id- : params.type === 'color'- ? params.color.id- : null,- type: params.type,+ Navigation.setHeaderState('Notes', params, {+ heading:+ params.type === 'tag'+ ? '#' + params.title+ : params.title.slice(0, 1).toUpperCase() + params.title.slice(1),+ id:+ params.type === 'tag'+ ? params.tag.id+ : params.type === 'topic'+ ? params.id+ : params.type === 'color'+ ? params.color.id+ : null,+ type: params.type,+ });});};@@ -205,7 +212,7 @@ export const Notes = ({route, navigation}) => {: params.title.slice(0, 1).toUpperCase() + params.title.slice(1),color: params.type === 'color' ? params.title.toLowerCase() : null,}}- loading={loading}+ loading={loading || localLoad}focused={() => navigation.isFocused()}RenderItem={NoteItemWrapper}placeholderText={`Add some notes to this" ${@@ -216,6 +223,7 @@ export const Notes = ({route, navigation}) => {paragraph: 'You have not added any notes yet.',button: 'Add your First Note',action: _onPressBottomButton,+ loading:'Loading your notes.'}}/><ContainerBottomButtondiff --git a/apps/mobile/src/views/Settings/index.js b/apps/mobile/src/views/Settings/index.jsindex 06a74507d..9742cc902 100644--- a/apps/mobile/src/views/Settings/index.js+++ b/apps/mobile/src/views/Settings/index.js@@ -1,6 +1,7 @@import React, {createRef, useCallback, useEffect, useState} from 'react';import {Appearance,+ InteractionManager,Linking,Platform,ScrollView,@@ -771,30 +772,32 @@ const SettingsPrivacyAndSecurity = () => {});const checkVaultStatus = useCallback(() => {- db.vault.add('check_no_vault').catch(async (e) => {- let biometry = await Keychain.getSupportedBiometryType();- let fingerprint = await Keychain.hasInternetCredentials('nn_vault');+ InteractionManager.runAfterInteractions(() => {+ db.vault.add('check_no_vault').catch(async (e) => {+ let biometry = await Keychain.getSupportedBiometryType();+ let fingerprint = await Keychain.hasInternetCredentials('nn_vault');- let available = false;- if (- biometry === Keychain.BIOMETRY_TYPE.FINGERPRINT ||- biometry === Keychain.BIOMETRY_TYPE.TOUCH_ID- ) {- available = true;- }- if (e.message === db.vault.ERRORS.noVault) {- setVaultStatus({- exists: false,- biometryEnrolled: fingerprint,- isBiometryAvailable: available,- });- } else {- setVaultStatus({- exists: true,- biometryEnrolled: fingerprint,- isBiometryAvailable: available,- });- }+ let available = false;+ if (+ biometry === Keychain.BIOMETRY_TYPE.FINGERPRINT ||+ biometry === Keychain.BIOMETRY_TYPE.TOUCH_ID+ ) {+ available = true;+ }+ if (e.message === db.vault.ERRORS.noVault) {+ setVaultStatus({+ exists: false,+ biometryEnrolled: fingerprint,+ isBiometryAvailable: available,+ });+ } else {+ setVaultStatus({+ exists: true,+ biometryEnrolled: fingerprint,+ isBiometryAvailable: available,+ });+ }+ });});});diff --git a/apps/mobile/src/views/Tags/index.js b/apps/mobile/src/views/Tags/index.jsindex 502f3c280..9a7ce9c83 100644--- a/apps/mobile/src/views/Tags/index.js+++ b/apps/mobile/src/views/Tags/index.js@@ -1,4 +1,5 @@-import React, {useCallback, useEffect} from 'react';+import React, {useCallback, useEffect, useState} from 'react';+import {InteractionManager} from 'react-native';import {Placeholder} from '../../components/ListPlaceholders';import SimpleList from '../../components/SimpleList';import {useTracked} from '../../provider';@@ -12,19 +13,26 @@ import {eScrollEvent} from '../../utils/Events';export const Tags = ({route, navigation}) => {const [state, dispatch] = useTracked();const tags = state.tags;+ const [loading, setLoading] = useState(true);let pageIsLoaded = false;const onFocus = useCallback(() => {- eSendEvent(eScrollEvent, {name: 'Tags', type: 'in'});- if (DDS.isLargeTablet()) {- dispatch({- type: Actions.CONTAINER_BOTTOM_BUTTON,- state: {- onPress: null,- },- });- }- updateSearch();+ InteractionManager.runAfterInteractions(() => {+ if (loading) {+ setLoading(false);+ }+ eSendEvent(eScrollEvent, {name: 'Tags', type: 'in'});+ if (DDS.isLargeTablet()) {+ dispatch({+ type: Actions.CONTAINER_BOTTOM_BUTTON,+ state: {+ onPress: null,+ },+ });+ }+ updateSearch();+ });+if (!pageIsLoaded) {pageIsLoaded = true;return;@@ -69,13 +77,15 @@ export const Tags = ({route, navigation}) => {data={tags}type="tags"headerProps={{- heading: "Tags",+ heading: 'Tags',}}+ loading={loading}focused={() => navigation.isFocused()}placeholderData={{heading: 'Your Tags',paragraph: 'You have not created any tags for your notes yet.',button: null,+ loading: 'Loading your tags.',}}placeholder={<Placeholder type="tags" />}placeholderText="Tags added to notes appear here"diff --git a/apps/mobile/src/views/Trash/index.js b/apps/mobile/src/views/Trash/index.jsindex a42216f26..54b8136f5 100644--- a/apps/mobile/src/views/Trash/index.js+++ b/apps/mobile/src/views/Trash/index.js@@ -1,4 +1,4 @@-import React, {useCallback, useEffect} from 'react';+import React, {useCallback, useEffect, useState} from 'react';import {ContainerBottomButton} from '../../components/Container/ContainerBottomButton';import {simpleDialogEvent} from '../../components/DialogManager/recievers';import {TEMPLATE_EMPTY_TRASH} from '../../components/DialogManager/Templates';@@ -15,19 +15,26 @@ import {eScrollEvent} from '../../utils/Events';export const Trash = ({route, navigation}) => {const [state, dispatch] = useTracked();const trash = state.trash;+ const [loading, setLoading] = useState(true);let pageIsLoaded = false;const onFocus = useCallback(() => {- eSendEvent(eScrollEvent, {name: 'Trash', type: 'in'});- if (DDS.isLargeTablet()) {- dispatch({- type: Actions.CONTAINER_BOTTOM_BUTTON,- state: {- onPress: null,- },- });- }- updateSearch();+ InteractionManager.runAfterInteractions(() => {+ if (loading) {+ setLoading(false);+ }+ eSendEvent(eScrollEvent, {name: 'Trash', type: 'in'});+ if (DDS.isLargeTablet()) {+ dispatch({+ type: Actions.CONTAINER_BOTTOM_BUTTON,+ state: {+ onPress: null,+ },+ });+ }+ updateSearch();+ });+if (!pageIsLoaded) {pageIsLoaded = true;return;@@ -48,7 +55,6 @@ export const Trash = ({route, navigation}) => {navigation.addListener('focus', onFocus);return () => {pageIsLoaded = false;-eSendEvent(eScrollEvent, {name: 'Trash', type: 'back'});navigation.removeListener('focus', onFocus);};@@ -76,11 +82,13 @@ export const Trash = ({route, navigation}) => {data={trash}type="trash"focused={() => navigation.isFocused()}+ loading={loading}placeholderData={{heading: 'Trash',paragraph:'Items in the trash will be permanently deleted after 7 days.',button: null,+ loading: 'Loading trash items',}}headerProps={{heading: 'Trash',