make sure screen renders only once

This commit is contained in:
ammarahm-ed
2020-10-12 11:22:36 +05:00
parent bab47c9b35
commit 95b658813a
9 changed files with 120 additions and 26 deletions

View File

@@ -19,6 +19,11 @@ export const injectedJS = `if (!window.location.search) {
link.click(); link.click();
} }
`; `;
let noteEdited = false;
export function isNotedEdited() {
return noteEdited;
}
export const INJECTED_JAVASCRIPT = (premium, noMenu) => export const INJECTED_JAVASCRIPT = (premium, noMenu) =>
premium premium
@@ -93,16 +98,28 @@ const onChange = (data) => {
let rawData = JSON.parse(data); let rawData = JSON.parse(data);
if (rawData.type === 'content') { if (rawData.type === 'content') {
content = rawData; if (
content &&
JSON.stringify(content.delta) !== JSON.stringify(rawData.delta)
) {
content = rawData;
noteEdited = true;
}
} else { } else {
title = rawData.value; if (rawData.value !== title) {
noteEdited = true;
title = rawData.value;
}
} }
} }
}; };
export const _onMessage = async (evt) => { export const _onMessage = async (evt) => {
if (evt.nativeEvent.data === 'loaded') { if (!evt || !evt.nativeEvent || !evt.nativeEvent.data) return;
} else if (evt.nativeEvent.data !== '' && evt.nativeEvent.data !== 'loaded') { let message = evt.nativeEvent.data;
if (message === 'loaded') {
} else if (message !== '' && message !== 'loaded') {
clearTimeout(timer); clearTimeout(timer);
timer = null; timer = null;
@@ -110,9 +127,13 @@ export const _onMessage = async (evt) => {
await sleep(2000); await sleep(2000);
canSave = true; canSave = true;
} }
onChange(evt.nativeEvent.data); onChange(message);
timer = setTimeout(() => { timer = setTimeout(() => {
saveNote(true); if (noteEdited) {
saveNote(true);
} else {
console.log('NOTHING CHANGED');
}
}, 500); }, 500);
} }
}; };
@@ -273,7 +294,8 @@ const loadNoteInEditor = async () => {
await sleep(50); await sleep(50);
post('title', title); post('title', title);
content.delta = note.content.delta; content.delta = note.content.delta;
if (note.locked) { console.log(content.delta, 'DELTA');
if (!note.locked) {
content.delta = await db.notes.note(id).delta(); content.delta = await db.notes.note(id).delta();
} }
post('delta', content.delta); post('delta', content.delta);

View File

@@ -38,6 +38,7 @@ import {
EditorWebView, EditorWebView,
getNote, getNote,
injectedJS, injectedJS,
isNotedEdited,
loadNote, loadNote,
onWebViewLoad, onWebViewLoad,
post, post,
@@ -48,6 +49,8 @@ import {
var handleBack; var handleBack;
var tapCount = 0; var tapCount = 0;
const Editor = ({noMenu}) => { const Editor = ({noMenu}) => {
// Global State // Global State
const [state, dispatch] = useTracked(); const [state, dispatch] = useTracked();
@@ -142,11 +145,11 @@ const Editor = ({noMenu}) => {
const _onBackPress = async () => { const _onBackPress = async () => {
editing.currentlyEditing = true; editing.currentlyEditing = true;
if (DDS.isTab) { if (DDS.isTab && !DDS.isSmallTab) {
simpleDialogEvent(TEMPLATE_EXIT_FULLSCREEN()); simpleDialogEvent(TEMPLATE_EXIT_FULLSCREEN());
} else { } else {
exitEditorAnimation(); exitEditorAnimation();
if (checkNote()) { if (checkNote() && isNotedEdited()) {
ToastEvent.show('Note Saved!', 'success'); ToastEvent.show('Note Saved!', 'success');
} }
setTimeout(async () => { setTimeout(async () => {
@@ -163,7 +166,8 @@ const Editor = ({noMenu}) => {
<SafeAreaView <SafeAreaView
style={{ style={{
flex: 1, flex: 1,
backgroundColor: DDS.isTab ? 'transparent' : colors.bg, backgroundColor:
DDS.isTab && !DDS.isSmallTab ? 'transparent' : colors.bg,
height: '100%', height: '100%',
width: '100%', width: '100%',
flexDirection: 'row', flexDirection: 'row',
@@ -175,7 +179,7 @@ const Editor = ({noMenu}) => {
height: '100%', height: '100%',
width: '100%', width: '100%',
}}> }}>
{noMenu ? ( {noMenu || DDS.isPhone || DDS.isSmallTab ? (
<View /> <View />
) : ( ) : (
<ActionIcon <ActionIcon
@@ -201,18 +205,18 @@ const Editor = ({noMenu}) => {
<View <View
style={{ style={{
flexDirection: 'row', flexDirection: 'row',
width: DDS.isTab ? '30%' : '100%', width: DDS.isTab && !DDS.isSmallTab ? '30%' : '100%',
height: 50, height: 50,
justifyContent: 'space-between', justifyContent: 'space-between',
alignItems: 'center', alignItems: 'center',
paddingHorizontal: 12, paddingHorizontal: 12,
position: DDS.isTab ? 'absolute' : 'relative', position: DDS.isTab && !DDS.isSmallTab ? 'absolute' : 'relative',
backgroundColor: colors.bg, backgroundColor: colors.bg,
right: 0, right: 0,
marginTop: Platform.OS === 'ios' ? 0 : StatusBar.currentHeight, marginTop: Platform.OS === 'ios' ? 0 : StatusBar.currentHeight,
zIndex: 10, zIndex: 10,
}}> }}>
{DDS.isTab ? ( {DDS.isTab && !DDS.isSmallTab ? (
<View /> <View />
) : ( ) : (
<ActionIcon <ActionIcon
@@ -239,7 +243,7 @@ const Editor = ({noMenu}) => {
simpleDialogEvent(TEMPLATE_NEW_NOTE); simpleDialogEvent(TEMPLATE_NEW_NOTE);
}} }}
/> />
{DDS.isTab && !fullscreen ? ( {DDS.isTab && !DDS.isSmallTab && !fullscreen ? (
<ActionIcon <ActionIcon
name="fullscreen" name="fullscreen"
color={colors.heading} color={colors.heading}
@@ -341,7 +345,12 @@ const Editor = ({noMenu}) => {
maxHeight: '100%', maxHeight: '100%',
width: '100%', width: '100%',
backgroundColor: 'transparent', backgroundColor: 'transparent',
marginTop: Platform.OS === 'ios' ? 0 : StatusBar.currentHeight, marginTop:
DDS.isTab && !DDS.isSmallTab
? Platform.OS === 'ios'
? 0
: StatusBar.currentHeight
: 0,
}} }}
onMessage={_onMessage} onMessage={_onMessage}
/> />

View File

@@ -26,6 +26,16 @@ export const Favorites = ({route, navigation}) => {
heading: 'Favorites', heading: 'Favorites',
}, },
}); });
dispatch({
type: ACTIONS.SEARCH_STATE,
state: {
placeholder: 'Search all favorites',
data: favorites,
noSearch: false,
type: 'notes',
color: null,
},
});
dispatch({ dispatch({
type: ACTIONS.CURRENT_SCREEN, type: ACTIONS.CURRENT_SCREEN,

View File

@@ -21,6 +21,16 @@ export const Folders = ({route, navigation}) => {
color: null, color: null,
}, },
}); });
dispatch({
type: ACTIONS.SEARCH_STATE,
state: {
placeholder: 'Search all notebooks',
data: notebooks,
noSearch: false,
type: 'notebooks',
color: null,
},
});
dispatch({ dispatch({
type: ACTIONS.HEADER_VERTICAL_MENU, type: ACTIONS.HEADER_VERTICAL_MENU,
@@ -38,6 +48,7 @@ export const Folders = ({route, navigation}) => {
type: ACTIONS.CURRENT_SCREEN, type: ACTIONS.CURRENT_SCREEN,
screen: 'notebooks', screen: 'notebooks',
}); });
}, []); }, []);
useEffect(() => { useEffect(() => {

View File

@@ -1,4 +1,6 @@
import React, {useCallback, useEffect} from 'react'; import React, {useCallback, useEffect} from 'react';
import {Dimensions} from 'react-native';
import Orientation from 'react-native-orientation';
import {ContainerBottomButton} from '../../components/Container/ContainerBottomButton'; import {ContainerBottomButton} from '../../components/Container/ContainerBottomButton';
import {Placeholder} from '../../components/ListPlaceholders'; import {Placeholder} from '../../components/ListPlaceholders';
import SimpleList from '../../components/SimpleList'; import SimpleList from '../../components/SimpleList';
@@ -32,6 +34,16 @@ export const Home = ({route, navigation}) => {
type: ACTIONS.HEADER_VERTICAL_MENU, type: ACTIONS.HEADER_VERTICAL_MENU,
state: true, state: true,
}); });
dispatch({
type: ACTIONS.SEARCH_STATE,
state: {
placeholder: 'Search all notes',
data: notes,
noSearch: false,
type: 'notes',
color: null,
},
});
dispatch({ dispatch({
type: ACTIONS.HEADER_TEXT_STATE, type: ACTIONS.HEADER_TEXT_STATE,
state: { state: {
@@ -76,17 +88,15 @@ export const Home = ({route, navigation}) => {
}, [notes]); }, [notes]);
const _onPressBottomButton = async () => { const _onPressBottomButton = async () => {
if (DDS.isTab) { eSendEvent(eOnLoadNote, {type: 'new'});
eSendEvent(eOnLoadNote, {type: 'new'});
} else { if (DDS.isPhone || DDS.isSmallTab) {
eSendEvent(eOnLoadNote, {type: 'new'});
openEditorAnimation(); openEditorAnimation();
} }
}; };
useEffect(() => { useEffect(() => {
console.log('render home'); console.log('render home');
}) });
return ( return (
<> <>

View File

@@ -14,6 +14,7 @@ import {
import {eOnNewTopicAdded, eScrollEvent} from '../../services/events'; import {eOnNewTopicAdded, eScrollEvent} from '../../services/events';
import NavigationService from '../../services/NavigationService'; import NavigationService from '../../services/NavigationService';
import {db} from '../../utils/utils'; import {db} from '../../utils/utils';
import { Dimensions } from 'react-native';
export const Notebook = ({route, navigation}) => { export const Notebook = ({route, navigation}) => {
const [, dispatch] = useTracked(); const [, dispatch] = useTracked();
@@ -51,6 +52,16 @@ export const Notebook = ({route, navigation}) => {
color: null, color: null,
}, },
}); });
dispatch({
type: ACTIONS.SEARCH_STATE,
state: {
placeholder: `Search in "${params.title}"`,
data: topics,
noSearch: false,
type: 'topics',
color: null,
},
});
dispatch({ dispatch({
type: ACTIONS.HEADER_VERTICAL_MENU, type: ACTIONS.HEADER_VERTICAL_MENU,
@@ -95,6 +106,7 @@ export const Notebook = ({route, navigation}) => {
const _onPressBottomButton = () => { const _onPressBottomButton = () => {
let n = route.params.notebook; let n = route.params.notebook;
AddTopicEvent(n); AddTopicEvent(n);
}; };
return ( return (

View File

@@ -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]); }, [params.type]);
return ( return (

View File

@@ -32,6 +32,16 @@ export const Tags = ({route, navigation}) => {
state: { state: {
heading: 'Tags', heading: 'Tags',
}, },
});
dispatch({
type: ACTIONS.SEARCH_STATE,
state: {
placeholder: 'Search all tags',
data: tags,
noSearch: false,
type: 'tags',
color: null,
},
}); });
dispatch({type: ACTIONS.TAGS}); dispatch({type: ACTIONS.TAGS});

View File

@@ -34,6 +34,16 @@ export const Trash = ({route, navigation}) => {
heading: 'Trash', heading: 'Trash',
}, },
}); });
dispatch({
type: ACTIONS.SEARCH_STATE,
state: {
placeholder: 'Search all trash',
data: trash,
noSearch: false,
type: 'trash',
color: null,
},
});
dispatch({ dispatch({
type: ACTIONS.TRASH, type: ACTIONS.TRASH,