Skip to content

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

make sure screen renders only once

ammarahm-ed95b658813a85
diff --git a/apps/mobile/src/views/Editor/func.js b/apps/mobile/src/views/Editor/func.js
index 4238fae29..e8be7cd2a 100644
--- a/apps/mobile/src/views/Editor/func.js
+++ b/apps/mobile/src/views/Editor/func.js
@@ -19,6 +19,11 @@ export const injectedJS = `if (!window.location.search) {
link.click();
}
`;
+let noteEdited = false;
+
+export function isNotedEdited() {
+ return noteEdited;
+}
export const INJECTED_JAVASCRIPT = (premium, noMenu) =>
premium
@@ -93,16 +98,28 @@ const onChange = (data) => {
let rawData = JSON.parse(data);
if (rawData.type === 'content') {
- content = rawData;
+ if (
+ content &&
+ JSON.stringify(content.delta) !== JSON.stringify(rawData.delta)
+ ) {
+ content = rawData;
+ noteEdited = true;
+ }
} else {
- title = rawData.value;
+ if (rawData.value !== title) {
+ noteEdited = true;
+ title = rawData.value;
+ }
}
}
};
export const _onMessage = async (evt) => {
- if (evt.nativeEvent.data === 'loaded') {
- } else if (evt.nativeEvent.data !== '' && evt.nativeEvent.data !== 'loaded') {
+ if (!evt || !evt.nativeEvent || !evt.nativeEvent.data) return;
+ let message = evt.nativeEvent.data;
+
+ if (message === 'loaded') {
+ } else if (message !== '' && message !== 'loaded') {
clearTimeout(timer);
timer = null;
@@ -110,9 +127,13 @@ export const _onMessage = async (evt) => {
await sleep(2000);
canSave = true;
}
- onChange(evt.nativeEvent.data);
+ onChange(message);
timer = setTimeout(() => {
- saveNote(true);
+ if (noteEdited) {
+ saveNote(true);
+ } else {
+ console.log('NOTHING CHANGED');
+ }
}, 500);
}
};
@@ -273,7 +294,8 @@ const loadNoteInEditor = async () => {
await sleep(50);
post('title', title);
content.delta = note.content.delta;
- if (note.locked) {
+ console.log(content.delta, 'DELTA');
+ if (!note.locked) {
content.delta = await db.notes.note(id).delta();
}
post('delta', content.delta);
diff --git a/apps/mobile/src/views/Editor/index.js b/apps/mobile/src/views/Editor/index.js
index a3fb428ac..1a16f4513 100755
--- a/apps/mobile/src/views/Editor/index.js
+++ b/apps/mobile/src/views/Editor/index.js
@@ -38,6 +38,7 @@ import {
EditorWebView,
getNote,
injectedJS,
+ isNotedEdited,
loadNote,
onWebViewLoad,
post,
@@ -48,6 +49,8 @@ import {
var handleBack;
var tapCount = 0;
+
+
const Editor = ({noMenu}) => {
// Global State
const [state, dispatch] = useTracked();
@@ -142,11 +145,11 @@ const Editor = ({noMenu}) => {
const _onBackPress = async () => {
editing.currentlyEditing = true;
- if (DDS.isTab) {
+ if (DDS.isTab && !DDS.isSmallTab) {
simpleDialogEvent(TEMPLATE_EXIT_FULLSCREEN());
} else {
exitEditorAnimation();
- if (checkNote()) {
+ if (checkNote() && isNotedEdited()) {
ToastEvent.show('Note Saved!', 'success');
}
setTimeout(async () => {
@@ -163,7 +166,8 @@ const Editor = ({noMenu}) => {
<SafeAreaView
style={{
flex: 1,
- backgroundColor: DDS.isTab ? 'transparent' : colors.bg,
+ backgroundColor:
+ DDS.isTab && !DDS.isSmallTab ? 'transparent' : colors.bg,
height: '100%',
width: '100%',
flexDirection: 'row',
@@ -175,7 +179,7 @@ const Editor = ({noMenu}) => {
height: '100%',
width: '100%',
}}>
- {noMenu ? (
+ {noMenu || DDS.isPhone || DDS.isSmallTab ? (
<View />
) : (
<ActionIcon
@@ -201,18 +205,18 @@ const Editor = ({noMenu}) => {
<View
style={{
flexDirection: 'row',
- width: DDS.isTab ? '30%' : '100%',
+ width: DDS.isTab && !DDS.isSmallTab ? '30%' : '100%',
height: 50,
justifyContent: 'space-between',
alignItems: 'center',
paddingHorizontal: 12,
- position: DDS.isTab ? 'absolute' : 'relative',
+ position: DDS.isTab && !DDS.isSmallTab ? 'absolute' : 'relative',
backgroundColor: colors.bg,
right: 0,
marginTop: Platform.OS === 'ios' ? 0 : StatusBar.currentHeight,
zIndex: 10,
}}>
- {DDS.isTab ? (
+ {DDS.isTab && !DDS.isSmallTab ? (
<View />
) : (
<ActionIcon
@@ -239,7 +243,7 @@ const Editor = ({noMenu}) => {
simpleDialogEvent(TEMPLATE_NEW_NOTE);
}}
/>
- {DDS.isTab && !fullscreen ? (
+ {DDS.isTab && !DDS.isSmallTab && !fullscreen ? (
<ActionIcon
name="fullscreen"
color={colors.heading}
@@ -341,7 +345,12 @@ const Editor = ({noMenu}) => {
maxHeight: '100%',
width: '100%',
backgroundColor: 'transparent',
- marginTop: Platform.OS === 'ios' ? 0 : StatusBar.currentHeight,
+ marginTop:
+ DDS.isTab && !DDS.isSmallTab
+ ? Platform.OS === 'ios'
+ ? 0
+ : StatusBar.currentHeight
+ : 0,
}}
onMessage={_onMessage}
/>
diff --git a/apps/mobile/src/views/Favorites/index.js b/apps/mobile/src/views/Favorites/index.js
index e681f5d83..2f406bb90 100644
--- a/apps/mobile/src/views/Favorites/index.js
+++ b/apps/mobile/src/views/Favorites/index.js
@@ -26,6 +26,16 @@ export const Favorites = ({route, navigation}) => {
heading: 'Favorites',
},
});
+ dispatch({
+ type: ACTIONS.SEARCH_STATE,
+ state: {
+ placeholder: 'Search all favorites',
+ data: favorites,
+ noSearch: false,
+ type: 'notes',
+ color: null,
+ },
+ });
dispatch({
type: ACTIONS.CURRENT_SCREEN,
diff --git a/apps/mobile/src/views/Folders/index.js b/apps/mobile/src/views/Folders/index.js
index c002a0e67..8f67781ee 100644
--- a/apps/mobile/src/views/Folders/index.js
+++ b/apps/mobile/src/views/Folders/index.js
@@ -21,6 +21,16 @@ export const Folders = ({route, navigation}) => {
color: null,
},
});
+ dispatch({
+ type: ACTIONS.SEARCH_STATE,
+ state: {
+ placeholder: 'Search all notebooks',
+ data: notebooks,
+ noSearch: false,
+ type: 'notebooks',
+ color: null,
+ },
+ });
dispatch({
type: ACTIONS.HEADER_VERTICAL_MENU,
@@ -38,6 +48,7 @@ export const Folders = ({route, navigation}) => {
type: ACTIONS.CURRENT_SCREEN,
screen: 'notebooks',
});
+
}, []);
useEffect(() => {
diff --git a/apps/mobile/src/views/Home/index.js b/apps/mobile/src/views/Home/index.js
index b06840976..961a7b3c2 100755
--- a/apps/mobile/src/views/Home/index.js
+++ b/apps/mobile/src/views/Home/index.js
@@ -1,4 +1,6 @@
import React, {useCallback, useEffect} from 'react';
+import {Dimensions} from 'react-native';
+import Orientation from 'react-native-orientation';
import {ContainerBottomButton} from '../../components/Container/ContainerBottomButton';
import {Placeholder} from '../../components/ListPlaceholders';
import SimpleList from '../../components/SimpleList';
@@ -32,6 +34,16 @@ export const Home = ({route, navigation}) => {
type: ACTIONS.HEADER_VERTICAL_MENU,
state: true,
});
+ dispatch({
+ type: ACTIONS.SEARCH_STATE,
+ state: {
+ placeholder: 'Search all notes',
+ data: notes,
+ noSearch: false,
+ type: 'notes',
+ color: null,
+ },
+ });
dispatch({
type: ACTIONS.HEADER_TEXT_STATE,
state: {
@@ -76,17 +88,15 @@ export const Home = ({route, navigation}) => {
}, [notes]);
const _onPressBottomButton = async () => {
- if (DDS.isTab) {
- eSendEvent(eOnLoadNote, {type: 'new'});
- } else {
- eSendEvent(eOnLoadNote, {type: 'new'});
+ eSendEvent(eOnLoadNote, {type: 'new'});
+
+ if (DDS.isPhone || DDS.isSmallTab) {
openEditorAnimation();
}
};
-
useEffect(() => {
- console.log('render home');
- })
+ console.log('render home');
+ });
return (
<>
diff --git a/apps/mobile/src/views/Notebook/index.js b/apps/mobile/src/views/Notebook/index.js
index 880eeb4a0..a25aa1715 100644
--- a/apps/mobile/src/views/Notebook/index.js
+++ b/apps/mobile/src/views/Notebook/index.js
@@ -14,6 +14,7 @@ import {
import {eOnNewTopicAdded, eScrollEvent} from '../../services/events';
import NavigationService from '../../services/NavigationService';
import {db} from '../../utils/utils';
+import { Dimensions } from 'react-native';
export const Notebook = ({route, navigation}) => {
const [, dispatch] = useTracked();
@@ -51,6 +52,16 @@ export const Notebook = ({route, navigation}) => {
color: null,
},
});
+ dispatch({
+ type: ACTIONS.SEARCH_STATE,
+ state: {
+ placeholder: `Search in "${params.title}"`,
+ data: topics,
+ noSearch: false,
+ type: 'topics',
+ color: null,
+ },
+ });
dispatch({
type: ACTIONS.HEADER_VERTICAL_MENU,
@@ -95,6 +106,7 @@ export const Notebook = ({route, navigation}) => {
const _onPressBottomButton = () => {
let n = route.params.notebook;
AddTopicEvent(n);
+
};
return (
diff --git a/apps/mobile/src/views/Notes/index.js b/apps/mobile/src/views/Notes/index.js
index 16a8700de..7349b1aea 100644
--- a/apps/mobile/src/views/Notes/index.js
+++ b/apps/mobile/src/views/Notes/index.js
@@ -156,10 +156,10 @@ export const Notes = ({route, navigation}) => {
};
}
- if (DDS.isTab) {
- eSendEvent(eOnLoadNote, {type: 'new'});
+ eSendEvent(eOnLoadNote, {type: 'new'});
+ if (DDS.isPhone || DDS.isSmallTab) {
+ openEditorAnimation();
}
- openEditorAnimation();
}, [params.type]);
return (
diff --git a/apps/mobile/src/views/Tags/index.js b/apps/mobile/src/views/Tags/index.js
index c889c96e4..52299cab1 100644
--- a/apps/mobile/src/views/Tags/index.js
+++ b/apps/mobile/src/views/Tags/index.js
@@ -32,6 +32,16 @@ export const Tags = ({route, navigation}) => {
state: {
heading: 'Tags',
},
+ });
+ dispatch({
+ type: ACTIONS.SEARCH_STATE,
+ state: {
+ placeholder: 'Search all tags',
+ data: tags,
+ noSearch: false,
+ type: 'tags',
+ color: null,
+ },
});
dispatch({type: ACTIONS.TAGS});
diff --git a/apps/mobile/src/views/Trash/index.js b/apps/mobile/src/views/Trash/index.js
index 0700ef872..e319a5905 100644
--- a/apps/mobile/src/views/Trash/index.js
+++ b/apps/mobile/src/views/Trash/index.js
@@ -34,6 +34,16 @@ export const Trash = ({route, navigation}) => {
heading: 'Trash',
},
});
+ dispatch({
+ type: ACTIONS.SEARCH_STATE,
+ state: {
+ placeholder: 'Search all trash',
+ data: trash,
+ noSearch: false,
+ type: 'trash',
+ color: null,
+ },
+ });
dispatch({
type: ACTIONS.TRASH,