mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-21 22:19:41 +01:00
make sure screen renders only once
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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}
|
||||
/>
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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(() => {
|
||||
|
||||
@@ -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 (
|
||||
<>
|
||||
|
||||
@@ -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 (
|
||||
|
||||
@@ -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 (
|
||||
|
||||
@@ -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});
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user