Skip to content
This repository has been archived by the owner on Jun 15, 2022. It is now read-only.

Commit

Permalink
Merge branch 'release/3.5.9'
Browse files Browse the repository at this point in the history
  • Loading branch information
radko93 committed Nov 26, 2020
2 parents a11aef2 + d37b03e commit 3caa18d
Showing 1 changed file with 23 additions and 16 deletions.
39 changes: 23 additions & 16 deletions src/screens/Compose/Compose.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,6 @@ export const Compose = React.memo(
);

useEffect(() => {
const unsubscribeStateEventObserver = application
?.getAppState()
.addStateEventObserver(state => {
if (state === AppStateEventType.DrawerOpen) {
dissmissKeybard();
}
});

const unsubscribeAppEventObserver = application?.addEventObserver(
async eventName => {
if (eventName === ApplicationEvent.CompletedFullSync) {
Expand All @@ -148,10 +140,7 @@ export const Compose = React.memo(
}
);

return () => {
unsubscribeAppEventObserver && unsubscribeAppEventObserver();
unsubscribeStateEventObserver && unsubscribeStateEventObserver();
};
return unsubscribeAppEventObserver;
}, [
application,
note?.dirty,
Expand All @@ -162,6 +151,27 @@ export const Compose = React.memo(
theme.stylekitWarningColor,
]);

useEffect(() => {
const unsubscribeStateEventObserver = application
?.getAppState()
.addStateEventObserver(state => {
if (state === AppStateEventType.DrawerOpen) {
dissmissKeybard();
/**
* Saves latest note state before any change might happen in the drawer
*/
if (note?.uuid) {
const updatedNote = application.findItem(note?.uuid) as SNNote;
if (updatedNote) {
setNote(updatedNote);
}
}
}
});

return unsubscribeStateEventObserver;
}, [application, note?.uuid]);

useEffect(() => {
let mounted = true;
if (mounted && editor && editor.isTemplateNote && Platform.OS === 'ios') {
Expand Down Expand Up @@ -318,17 +328,14 @@ export const Compose = React.memo(
setTitle(newNote.title);
setNoteText(newNote.text);
}

/**
* If the note change was triggered by a local change
* we only save it to local state if a meaningful value changed
* to avoid unecessary UI renders.
*/
if (
note?.prefersPlainEditor !== newNote.prefersPlainEditor ||
newNote.locked !== note?.locked ||
newNote.text !== note.text ||
newNote.title !== note.title
newNote.locked !== note?.locked
) {
if (note) {
setNote(newNote);
Expand Down

0 comments on commit 3caa18d

Please sign in to comment.