Skip to content

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

refactor

ammarahm-edce07ccb5cdc2
diff --git a/apps/mobile/src/components/ActionSheetComponent/ActionSheetColorsSection.js b/apps/mobile/src/components/ActionSheetComponent/ActionSheetColorsSection.js
index 6e70dcc1c..bb67842f7 100644
--- a/apps/mobile/src/components/ActionSheetComponent/ActionSheetColorsSection.js
+++ b/apps/mobile/src/components/ActionSheetComponent/ActionSheetColorsSection.js
@@ -56,7 +56,10 @@ export const ActionSheetColorsSection = ({item, close}) => {
}
localRefresh();
dispatch({type: Actions.COLORS});
- sendNoteEditedEvent(note.id, false, true);
+ sendNoteEditedEvent({
+ id: note.id,
+ forced: true,
+ });
eSendEvent(refreshNotesPage);
}}
customStyle={{
diff --git a/apps/mobile/src/components/ActionSheetComponent/ActionSheetTagsSection.js b/apps/mobile/src/components/ActionSheetComponent/ActionSheetTagsSection.js
index 78d267791..e33a537da 100644
--- a/apps/mobile/src/components/ActionSheetComponent/ActionSheetTagsSection.js
+++ b/apps/mobile/src/components/ActionSheetComponent/ActionSheetTagsSection.js
@@ -281,10 +281,13 @@ const TagItem = ({tag, note, localRefresh}) => {
await db.notes
.note(note.id)
.untag(prevNote.tags[prevNote.tags.indexOf(tag)]);
- sendNoteEditedEvent(note.id, false, true);
- localRefresh(note.type);
+ localRefresh(note.type);
} catch (e) {
- sendNoteEditedEvent(note.id, false, true);
+ } finally {
+ sendNoteEditedEvent({
+ id: note.id,
+ forced: true,
+ });
}
};
diff --git a/apps/mobile/src/components/ActionSheetComponent/index.js b/apps/mobile/src/components/ActionSheetComponent/index.js
index 012dddc96..03d56ba70 100644
--- a/apps/mobile/src/components/ActionSheetComponent/index.js
+++ b/apps/mobile/src/components/ActionSheetComponent/index.js
@@ -320,7 +320,10 @@ export const ActionSheetComponent = ({
await db.notebooks.notebook(note.id).favorite();
}
dispatch({type: Actions.FAVORITES});
- sendNoteEditedEvent(note.id, false, true);
+ sendNoteEditedEvent({
+ id: note.id,
+ forced: true,
+ });
localRefresh(item.type, true);
close();
},
@@ -466,7 +469,10 @@ export const ActionSheetComponent = ({
if (n.locked) {
close();
}
- sendNoteEditedEvent(note.id, false, true);
+ sendNoteEditedEvent({
+ id: note.id,
+ forced: true,
+ });
localRefresh(note.type);
})
.catch(async (e) => {
diff --git a/apps/mobile/src/components/MergeEditor/index.js b/apps/mobile/src/components/MergeEditor/index.js
index 153169f14..e62b4f17d 100644
--- a/apps/mobile/src/components/MergeEditor/index.js
+++ b/apps/mobile/src/components/MergeEditor/index.js
@@ -202,7 +202,10 @@ const MergeEditor = () => {
});
}
eSendEvent(refreshNotesPage);
- sendNoteEditedEvent(note.id);
+ sendNoteEditedEvent({
+ id: note.id,
+ forced: true,
+ });
updateEvent({type: Actions.NOTES});
updateEvent({type: Actions.FAVORITES});
close();
diff --git a/apps/mobile/src/components/MoveNoteDialog/index.js b/apps/mobile/src/components/MoveNoteDialog/index.js
index 4e92fd988..8faa764a4 100644
--- a/apps/mobile/src/components/MoveNoteDialog/index.js
+++ b/apps/mobile/src/components/MoveNoteDialog/index.js
@@ -126,7 +126,10 @@ const MoveNoteComponent = ({close, note, setNote}) => {
if (note && note.id) {
setNote({...db.notes.note(note.id).data});
- sendNoteEditedEvent(note.id);
+ sendNoteEditedEvent({
+ id: note.id,
+ forced: true,
+ });
}
dispatch({type: Actions.NOTEBOOKS});
@@ -146,7 +149,10 @@ const MoveNoteComponent = ({close, note, setNote}) => {
if (note && note.id) {
setNote({...db.notes.note(note.id).data});
- sendNoteEditedEvent(note.id);
+ sendNoteEditedEvent({
+ id: note.id,
+ forced: true,
+ });
}
dispatch({type: Actions.NOTEBOOKS});
};
diff --git a/apps/mobile/src/components/SimpleList/NoteItemWrapper.js b/apps/mobile/src/components/SimpleList/NoteItemWrapper.js
index 0cafc7817..cd82771c3 100644
--- a/apps/mobile/src/components/SimpleList/NoteItemWrapper.js
+++ b/apps/mobile/src/components/SimpleList/NoteItemWrapper.js
@@ -27,7 +27,14 @@ export const NoteItemWrapper = ({item, index, isTrash = false}) => {
}, [item]);
const onNoteChange = (data) => {
- if (!data || data.id !== item.id || data.closed) {
+ if (!data || data.id !== item.id) {
+ return;
+ }
+ if (
+ !data.forced &&
+ data.title === item.title &&
+ data.headline === item.headline
+ ) {
return;
}
let _note = db.notes.note(item.id).data;
diff --git a/apps/mobile/src/components/VaultDialog/index.js b/apps/mobile/src/components/VaultDialog/index.js
index 2f6918772..5b84ddfb9 100644
--- a/apps/mobile/src/components/VaultDialog/index.js
+++ b/apps/mobile/src/components/VaultDialog/index.js
@@ -332,14 +332,15 @@ export class VaultDialog extends Component {
db.vault
.remove(this.state.note.id, this.password)
.then((r) => {
- console.log(r, 'unocking result');
- sendNoteEditedEvent(this.state.note.id);
+ sendNoteEditedEvent({
+ id:this.state.note.id,
+ forced: true,
+ });
updateEvent({type: Actions.NOTES});
eSendEvent(refreshNotesPage);
this.close();
})
.catch((e) => {
- console.log(e, 'unlocking error');
this._takeErrorAction(e);
});
}
diff --git a/apps/mobile/src/services/EventManager.js b/apps/mobile/src/services/EventManager.js
index 1ebe26f91..ccfd8484e 100644
--- a/apps/mobile/src/services/EventManager.js
+++ b/apps/mobile/src/services/EventManager.js
@@ -1,5 +1,10 @@
import {DeviceEventEmitter} from 'react-native';
-import {eHideToast, eOnNoteEdited, eOpenVaultDialog, eShowToast} from '../utils/Events';
+import {
+ eHideToast,
+ eOnNoteEdited,
+ eOpenVaultDialog,
+ eShowToast,
+} from '../utils/Events';
export const eSubscribeEvent = (eventName, action) => {
DeviceEventEmitter.addListener(eventName, action);
@@ -11,8 +16,6 @@ export const eUnSubscribeEvent = (eventName, action) => {
export const eSendEvent = (eventName, data) => {
DeviceEventEmitter.emit(eventName, data);
-
-
};
/**
@@ -28,51 +31,59 @@ export const eSendEvent = (eventName, data) => {
* @property {boolean} revokeFingerprintAccess
* @property {boolean} changePassword
* @property {boolean} copyNote
- * @param {vaultType} data
+ * @param {vaultType} data
*/
export const openVault = (data) => {
eSendEvent(eOpenVaultDialog, data);
};
-export function sendNoteEditedEvent(id="",closed=false,noEdit=false) {
- eSendEvent(eOnNoteEdited , {id,closed, noEdit});
-}
+/**
+ * @typedef {Object} noteEdit
+ * @property {string} id
+ * @property {boolean} closed
+ * @property {boolean} noEdit
+ * @property {boolean} forced
+ * @param {noteEdit} data
+ */
+export function sendNoteEditedEvent(data) {
+ eSendEvent(eOnNoteEdited, data);
+}
export const ToastEvent = {
- show: (
- message,
- type = 'error',
- context = 'global',
- duration = 3000,
- func = null,
- actionText = '',
- ) => {
- eSendEvent(eShowToast, {
- message,
- type,
- context,
- duration,
- func,
- actionText,
- });
- },
- hide: (
- message,
- type = 'error',
- context = 'global',
- duration = 3000,
- func = null,
- actionText = '',
- ) => {
- eSendEvent(eHideToast, {
- message,
- type,
- context,
- duration,
- func,
- actionText,
- });
- },
-};
\ No newline at end of file
+ show: (
+ message,
+ type = 'error',
+ context = 'global',
+ duration = 3000,
+ func = null,
+ actionText = '',
+ ) => {
+ eSendEvent(eShowToast, {
+ message,
+ type,
+ context,
+ duration,
+ func,
+ actionText,
+ });
+ },
+ hide: (
+ message,
+ type = 'error',
+ context = 'global',
+ duration = 3000,
+ func = null,
+ actionText = '',
+ ) => {
+ eSendEvent(eHideToast, {
+ message,
+ type,
+ context,
+ duration,
+ func,
+ actionText,
+ });
+ },
+};
diff --git a/apps/mobile/src/views/Editor/Functions.js b/apps/mobile/src/views/Editor/Functions.js
index 87fc2a33d..ae78a82d3 100644
--- a/apps/mobile/src/views/Editor/Functions.js
+++ b/apps/mobile/src/views/Editor/Functions.js
@@ -184,7 +184,9 @@ export const loadNote = async (item) => {
} else {
clearTimer();
await setNote(item);
- sendNoteEditedEvent(item.id);
+ sendNoteEditedEvent({
+ id: id,
+ });
if (webviewInit) {
await loadNoteInEditor();
}
@@ -265,7 +267,10 @@ export async function clearEditor() {
await saveNote(false);
}
updateEvent({type: Actions.CURRENT_EDITING_NOTE, id: null});
- sendNoteEditedEvent(null, true);
+ sendNoteEditedEvent({
+ id: id,
+ forced:true
+ });
eSendEvent('historyEvent', {
undo: 0,
redo: 0,
@@ -380,7 +385,9 @@ export async function saveNote() {
noteData.contentId = note.contentId;
await db.vault.save(noteData);
}
- sendNoteEditedEvent(id);
+ sendNoteEditedEvent({
+ id: id,
+ });
let n = db.notes.note(id).data.dateEdited;
post('dateEdited', timeConverter(n));
post('saving', 'Saved');