From ca04ff43def4ea2ff48dc9ed2001778e56877d02 Mon Sep 17 00:00:00 2001 From: Antonella Sgarlatta Date: Wed, 19 May 2021 16:10:38 -0300 Subject: [PATCH] fix: fix mobx actions --- .../ui_models/app_state/notes_state.ts | 52 +++++++++++-------- .../ui_models/app_state/tags_state.ts | 14 ++--- 2 files changed, 39 insertions(+), 27 deletions(-) diff --git a/app/assets/javascripts/ui_models/app_state/notes_state.ts b/app/assets/javascripts/ui_models/app_state/notes_state.ts index 1ea6a5a4e..7570d0262 100644 --- a/app/assets/javascripts/ui_models/app_state/notes_state.ts +++ b/app/assets/javascripts/ui_models/app_state/notes_state.ts @@ -43,13 +43,10 @@ export class NotesState { selectedNotesCount: computed, trashedNotesCount: computed, - selectNote: action, - setArchiveSelectedNotes: action, setContextMenuOpen: action, setContextMenuPosition: action, - setTrashSelectedNotes: action, - unselectNotes: action, setShowProtectedWarning: action, + unselectNotes: action, }); appEventListeners.push( @@ -102,37 +99,44 @@ export class NotesState { ); for (const note of authorizedNotes) { - this.selectedNotes[note.uuid] = note; - this.lastSelectedNote = note; + runInAction(() => { + this.selectedNotes[note.uuid] = note; + this.lastSelectedNote = note; + }); } } async selectNote(uuid: UuidString): Promise { const note = this.application.findItem(uuid) as SNNote; + if (note) { if ( this.io.activeModifiers.has(KeyboardModifier.Meta) || this.io.activeModifiers.has(KeyboardModifier.Ctrl) ) { - if (this.selectedNotes[note.uuid]) { - delete this.selectedNotes[note.uuid]; + if (this.selectedNotes[uuid]) { + delete this.selectedNotes[uuid]; } else if (await this.application.authorizeNoteAccess(note)) { - this.selectedNotes[note.uuid] = note; - this.lastSelectedNote = note; + runInAction(() => { + this.selectedNotes[uuid] = note; + this.lastSelectedNote = note; + }); } } else if (this.io.activeModifiers.has(KeyboardModifier.Shift)) { await this.selectNotesRange(note); } else { const shouldSelectNote = - this.selectedNotesCount > 1 || !this.selectedNotes[note.uuid]; + this.selectedNotesCount > 1 || !this.selectedNotes[uuid]; if ( shouldSelectNote && (await this.application.authorizeNoteAccess(note)) ) { - this.selectedNotes = { - [note.uuid]: note, - }; - this.lastSelectedNote = note; + runInAction(() => { + this.selectedNotes = { + [note.uuid]: note, + }; + this.lastSelectedNote = note; + }); } } @@ -204,15 +208,19 @@ export class NotesState { if (trashed) { const notesDeleted = await this.deleteNotes(false); if (notesDeleted) { - this.unselectNotes(); - this.contextMenuOpen = false; + runInAction(() => { + this.unselectNotes(); + this.contextMenuOpen = false; + }); } } else { await this.changeSelectedNotes((mutator) => { mutator.trashed = trashed; }); - this.unselectNotes(); - this.contextMenuOpen = false; + runInAction(() => { + this.unselectNotes(); + this.contextMenuOpen = false; + }); } } @@ -283,8 +291,10 @@ export class NotesState { mutator.archived = archived; }); - this.selectedNotes = {}; - this.contextMenuOpen = false; + runInAction(() => { + this.selectedNotes = {}; + this.contextMenuOpen = false; + }); } async setProtectSelectedNotes(protect: boolean): Promise { diff --git a/app/assets/javascripts/ui_models/app_state/tags_state.ts b/app/assets/javascripts/ui_models/app_state/tags_state.ts index 439a47e7a..a2e2377e6 100644 --- a/app/assets/javascripts/ui_models/app_state/tags_state.ts +++ b/app/assets/javascripts/ui_models/app_state/tags_state.ts @@ -1,5 +1,5 @@ import { ContentType, SNSmartTag, SNTag } from '@standardnotes/snjs'; -import { computed, makeObservable, observable } from 'mobx'; +import { computed, makeObservable, observable, runInAction } from 'mobx'; import { WebApplication } from '../application'; export class TagsState { @@ -20,11 +20,13 @@ export class TagsState { appEventListeners.push( this.application.streamItems( [ContentType.Tag, ContentType.SmartTag], - async () => { - this.tags = this.application.getDisplayableItems( - ContentType.Tag - ) as SNTag[]; - this.smartTags = this.application.getSmartTags(); + () => { + runInAction(() => { + this.tags = this.application.getDisplayableItems( + ContentType.Tag + ) as SNTag[]; + this.smartTags = this.application.getSmartTags(); + }); } ) );