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
handle deleting note properly when editor is open
ammarahm-ed743b80642183
diff --git a/apps/mobile/src/utils/useAppEvents.js b/apps/mobile/src/utils/useAppEvents.jsindex a17589edc..35df3fc6f 100644--- a/apps/mobile/src/utils/useAppEvents.js+++ b/apps/mobile/src/utils/useAppEvents.js@@ -112,7 +112,6 @@ export const useAppEvents = () => {EV.subscribe(EVENTS.userSessionExpired, onSessionExpired);EV.subscribe(EVENTS.userCheckStatus, PremiumService.onUserStatusCheck);EV.subscribe(EVENTS.userSubscriptionUpdated, onAccountStatusChange);- EV.subscribe(EVENTS.noteRemoved, onNoteRemoved);EV.subscribe(EVENTS.mediaAttachmentDownloaded, onMediaDownloaded);EV.subscribe(EVENTS.attachmentsLoading, onLoadingAttachment);@@ -133,7 +132,6 @@ export const useAppEvents = () => {EV.unsubscribe(EVENTS.databaseSyncRequested, partialSync);EV.unsubscribe(EVENTS.userLoggedOut, onLogout);EV.unsubscribe(EVENTS.userEmailConfirmed, onEmailVerified);- EV.unsubscribe(EVENTS.noteRemoved, onNoteRemoved);EV.unsubscribe(EVENTS.mediaAttachmentDownloaded, onMediaDownloaded);EV.subscribe(EVENTS.attachmentsLoading, onLoadingAttachment);EV.unsubscribe(EVENTS.userCheckStatus, PremiumService.onUserStatusCheck);@@ -159,7 +157,8 @@ export const useAppEvents = () => {Navigation.routeNames.Trash,Navigation.routeNames.Notebook]);- eSendEvent(eClearEditor);+ eSendEvent(eClearEditor, id);+} catch (e) {}};@@ -205,6 +204,7 @@ export const useAppEvents = () => {try {if (url.startsWith('https://app.notesnook.com/account/verified')) {await onEmailVerified();+} else {return;}diff --git a/apps/mobile/src/views/Editor/EditorHeader.js b/apps/mobile/src/views/Editor/EditorHeader.jsindex da773b9fe..b98b3bb79 100644--- a/apps/mobile/src/views/Editor/EditorHeader.js+++ b/apps/mobile/src/views/Editor/EditorHeader.js@@ -1,3 +1,4 @@+import {EV, EVENTS} from 'notes-core/common';import React, {useEffect, useRef} from 'react';import {BackHandler,@@ -169,12 +170,29 @@ const EditorHeader = () => {useEffect(() => {eSubscribeEvent(eOnLoadNote, load);eSubscribeEvent(eClearEditor, onCallClear);+ EV.subscribe(EVENTS.noteRemoved, onNoteRemoved);return () => {+ EV.unsubscribe(EVENTS.noteRemoved, onNoteRemoved);eUnSubscribeEvent(eClearEditor, onCallClear);eUnSubscribeEvent(eOnLoadNote, load);};}, []);+ const onNoteRemoved = async id => {+ try {+ console.log("NOTE REMOVED",id);+ await db.notes.remove(id);+ if (id !== getNote().id) return;+ Navigation.setRoutesToUpdate([+ Navigation.routeNames.Favorites,+ Navigation.routeNames.Notes,+ Navigation.routeNames.NotesPage,+ Navigation.routeNames.Trash,+ Navigation.routeNames.Notebook+ ]);+ } catch (e) {}+ };+useEffect(() => {if (fullscreen && DDS.isTab) {handleBack.current = BackHandler.addEventListener(@@ -295,7 +313,6 @@ const EditorHeader = () => {color={colors.yellow}customStyle={{marginLeft: 10,- borderRadius: 5}}top={50}onPress={() => {@@ -313,7 +330,6 @@ const EditorHeader = () => {color={colors.pri}customStyle={{marginLeft: 10,- borderRadius: 5}}top={50}onPress={publishNote}@@ -326,7 +342,6 @@ const EditorHeader = () => {color={colors.pri}customStyle={{marginLeft: 10,- borderRadius: 5}}top={50}onPress={picker.pick}diff --git a/apps/mobile/src/views/Editor/Functions.js b/apps/mobile/src/views/Editor/Functions.jsindex 6ba957961..e9650ee6b 100644--- a/apps/mobile/src/views/Editor/Functions.js+++ b/apps/mobile/src/views/Editor/Functions.js@@ -261,12 +261,12 @@ export const loadNote = async item => {clearNote();noteEdited = false;if (Platform.OS === 'android') {- await sleep(100);+ await sleep(300);textInput.current?.focus();EditorWebView.current?.requestFocus();tiny.call(EditorWebView, tiny.focusEditor);} else {- await sleep(50);+ await sleep(150);tiny.call(EditorWebView, tiny.focusEditor);}if (EDITOR_SETTINGS) {@@ -351,6 +351,7 @@ export const _onMessage = async evt => {eSendEvent('historyEvent', message.value);break;case 'tiny':+ console.log(message.value);if (message.value === '<br>') return;if (message.value !== content.data) {if (prevNoteContent && message.value === prevNoteContent) {@@ -392,7 +393,7 @@ export const _onMessage = async evt => {tiny.call(EditorWebView, tiny.notLoading);setTimeout(() => {eSendEvent('loadingNote');- },150);+ }, 150);break;case 'premium':let user = await db.user.getUser();@@ -581,6 +582,7 @@ export async function saveNote(preventUpdate) {try {if (id && !db.notes.note(id)) {clearNote();+ useEditorStore.getState().setCurrentlyEditingNote(null);return;}let locked = false;@@ -631,8 +633,11 @@ export async function saveNote(preventUpdate) {]);let n = db.notes.note(id)?.data?.dateEdited;lastEditTime = n + 10;- tiny.call(EditorWebView, tiny.updateDateEdited(timeConverter(n)));- tiny.call(EditorWebView, tiny.updateSavingState('Saved'));+ tiny.call(+ EditorWebView,+ tiny.updateDateEdited(n ? timeConverter(n) : '')+ );+ tiny.call(EditorWebView, tiny.updateSavingState(!n ? '' : 'Saved'));}} catch (e) {console.log('note save error', e, e.stack);