Skip to content

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

optimize editor transitions

ammarahm-ed2f763302152c
diff --git a/apps/mobile/src/views/Editor/EditorOverlay.js b/apps/mobile/src/views/Editor/EditorOverlay.js
index abe0e5909..8488f24ea 100644
--- a/apps/mobile/src/views/Editor/EditorOverlay.js
+++ b/apps/mobile/src/views/Editor/EditorOverlay.js
@@ -34,20 +34,12 @@ const EditorOverlay = () => {
}, 4000);
} else {
setProgress(4);
- await sleep(1);
setError(false);
- timing(opacity, {
- toValue: 0,
- duration: 150,
- easing: Easing.out(Easing.ease),
- }).start(async () => {
- await sleep(200);
- setProgress(1);
- opacity.setValue(1);
- setLoading(null);
- clearTimeout(timer);
- clearTimeout(timerError);
- });
+ setProgress(1);
+ opacity.setValue(1);
+ setLoading(null);
+ clearTimeout(timer);
+ clearTimeout(timerError);
}
};
diff --git a/apps/mobile/src/views/Editor/Functions.js b/apps/mobile/src/views/Editor/Functions.js
index e72d95431..d7d65f1d9 100644
--- a/apps/mobile/src/views/Editor/Functions.js
+++ b/apps/mobile/src/views/Editor/Functions.js
@@ -5,7 +5,7 @@ import {Actions} from '../../provider/Actions';
import {DDS} from '../../services/DeviceDetection';
import {eSendEvent, sendNoteEditedEvent} from '../../services/EventManager';
import Navigation from '../../services/Navigation';
-import {editing} from '../../utils';
+import {editing, InteractionManager} from '../../utils';
import {COLORS_NOTE, COLOR_SCHEME} from '../../utils/Colors';
import {hexToRGBA} from '../../utils/ColorUtils';
import {db} from '../../utils/DB';
@@ -175,14 +175,16 @@ let currentEditingTimer = null;
let webviewTimer = null;
export const loadNote = async item => {
+ console.log(item);
editing.currentlyEditing = true;
tiny.call(EditorWebView, tiny.blur);
if (item && item.type === 'new') {
- await clearEditor();
+ if (getNote()) {
+ await clearEditor();
+ }
clearNote();
noteEdited = false;
id = null;
- await sleep(20);
if (Platform.OS === 'android') {
textInput.current?.focus();
EditorWebView.current?.requestFocus();
@@ -194,28 +196,30 @@ export const loadNote = async item => {
EditorWebView.current?.reload();
}
tiny.call(EditorWebView, tiny.notLoading);
+ checkStatus();
} else {
if (id === item.id && !item.forced) {
return;
}
- eSendEvent('loadingNote', item);
- eSendEvent('webviewreset');
- webviewInit = false;
- editing.isFocused = false;
- clearTimer();
await setNote(item);
- sendNoteEditedEvent({
- id: id,
- });
-
- if (webviewInit) {
- await loadNoteInEditor();
- } else {
- EditorWebView.current?.reload();
- }
- updateEvent({type: Actions.CURRENT_EDITING_NOTE, id: item.id});
+ eSendEvent('loadingNote', item);
+ InteractionManager.runAfterInteractions(async () => {
+ eSendEvent('webviewreset');
+ webviewInit = false;
+ editing.isFocused = false;
+ clearTimer();
+ sendNoteEditedEvent({
+ id: id,
+ });
+ if (webviewInit) {
+ await loadNoteInEditor();
+ } else {
+ EditorWebView.current?.reload();
+ }
+ updateEvent({type: Actions.CURRENT_EDITING_NOTE, id: item.id});
+ checkStatus();
+ }, 1);
}
- checkStatus();
};
const checkStatus = (reset = false) => {
@@ -339,22 +343,18 @@ export async function clearEditor() {
(content?.data && content.data?.trim().length > 0) ||
(title && title.trim().length > 0)
) {
- await saveNote();
+ await saveNote(true);
}
clearNote();
editing.focusType = null;
- updateEvent({type: Actions.CURRENT_EDITING_NOTE, id: null});
- sendNoteEditedEvent({
- id: id,
- forced: true,
- });
eSendEvent('historyEvent', {
undo: 0,
redo: 0,
});
saveCounter = 0;
- tiny.call(EditorWebView, tiny.updateDateEdited(''), true);
- tiny.call(EditorWebView, tiny.updateSavingState(''), true);
+ setTimeout(() => {
+ updateEvent({type: Actions.CURRENT_EDITING_NOTE, id: null});
+ }, 1);
}
async function setNoteInEditorAfterSaving(oldId, currentId) {
@@ -420,7 +420,7 @@ async function addToCollection(id) {
}
}
-export async function saveNote() {
+export async function saveNote(preventUpdate) {
try {
if (id && !db.notes.note(id)) {
clearNote();
@@ -447,10 +447,10 @@ export async function saveNote() {
Navigation.routeNames.NotesPage,
Navigation.routeNames.Notebook,
]);
- updateEvent({type: Actions.CURRENT_EDITING_NOTE, id: noteId});
}
if (!id) {
+ updateEvent({type: Actions.CURRENT_EDITING_NOTE, id: noteId});
await addToCollection(noteId);
}
await setNoteInEditorAfterSaving(id, noteId);
@@ -459,12 +459,14 @@ export async function saveNote() {
noteData.contentId = note.contentId;
await db.vault.save(noteData);
}
- sendNoteEditedEvent({
- id: id,
- });
- let n = db.notes.note(id)?.data?.dateEdited;
- tiny.call(EditorWebView, tiny.updateDateEdited(timeConverter(n)));
- tiny.call(EditorWebView, tiny.updateSavingState('Saved'));
+ if (!preventUpdate) {
+ sendNoteEditedEvent({
+ id: id,
+ });
+ let n = db.notes.note(id)?.data?.dateEdited;
+ tiny.call(EditorWebView, tiny.updateDateEdited(timeConverter(n)));
+ tiny.call(EditorWebView, tiny.updateSavingState('Saved'));
+ }
} catch (e) {}
}
diff --git a/apps/mobile/src/views/Editor/tiny/tiny.js b/apps/mobile/src/views/Editor/tiny/tiny.js
index 472a95e49..44cdf2c15 100644
--- a/apps/mobile/src/views/Editor/tiny/tiny.js
+++ b/apps/mobile/src/views/Editor/tiny/tiny.js
@@ -6,8 +6,13 @@ const reset = `
isLoading = true;
document.getElementById("titleInput").value = '';
autosize();
+window.prevContent = "";
tinymce.activeEditor.setContent('');
tinymce.activeEditor.undoManager.clear();
+info = document.querySelector(infoBar);
+info.querySelector('#infosaved').innerText = "";
+info.querySelector('#infodate').innerText = "";
+info.querySelector('#infowords').innerText = ""
document.activeElement.blur();
window.blur();
`;