fix: fix mobx actions

This commit is contained in:
Antonella Sgarlatta
2021-05-19 16:10:38 -03:00
parent 0a262de3db
commit ca04ff43de
2 changed files with 39 additions and 27 deletions

View File

@@ -43,13 +43,10 @@ export class NotesState {
selectedNotesCount: computed, selectedNotesCount: computed,
trashedNotesCount: computed, trashedNotesCount: computed,
selectNote: action,
setArchiveSelectedNotes: action,
setContextMenuOpen: action, setContextMenuOpen: action,
setContextMenuPosition: action, setContextMenuPosition: action,
setTrashSelectedNotes: action,
unselectNotes: action,
setShowProtectedWarning: action, setShowProtectedWarning: action,
unselectNotes: action,
}); });
appEventListeners.push( appEventListeners.push(
@@ -102,37 +99,44 @@ export class NotesState {
); );
for (const note of authorizedNotes) { for (const note of authorizedNotes) {
this.selectedNotes[note.uuid] = note; runInAction(() => {
this.lastSelectedNote = note; this.selectedNotes[note.uuid] = note;
this.lastSelectedNote = note;
});
} }
} }
async selectNote(uuid: UuidString): Promise<void> { async selectNote(uuid: UuidString): Promise<void> {
const note = this.application.findItem(uuid) as SNNote; const note = this.application.findItem(uuid) as SNNote;
if (note) { if (note) {
if ( if (
this.io.activeModifiers.has(KeyboardModifier.Meta) || this.io.activeModifiers.has(KeyboardModifier.Meta) ||
this.io.activeModifiers.has(KeyboardModifier.Ctrl) this.io.activeModifiers.has(KeyboardModifier.Ctrl)
) { ) {
if (this.selectedNotes[note.uuid]) { if (this.selectedNotes[uuid]) {
delete this.selectedNotes[note.uuid]; delete this.selectedNotes[uuid];
} else if (await this.application.authorizeNoteAccess(note)) { } else if (await this.application.authorizeNoteAccess(note)) {
this.selectedNotes[note.uuid] = note; runInAction(() => {
this.lastSelectedNote = note; this.selectedNotes[uuid] = note;
this.lastSelectedNote = note;
});
} }
} else if (this.io.activeModifiers.has(KeyboardModifier.Shift)) { } else if (this.io.activeModifiers.has(KeyboardModifier.Shift)) {
await this.selectNotesRange(note); await this.selectNotesRange(note);
} else { } else {
const shouldSelectNote = const shouldSelectNote =
this.selectedNotesCount > 1 || !this.selectedNotes[note.uuid]; this.selectedNotesCount > 1 || !this.selectedNotes[uuid];
if ( if (
shouldSelectNote && shouldSelectNote &&
(await this.application.authorizeNoteAccess(note)) (await this.application.authorizeNoteAccess(note))
) { ) {
this.selectedNotes = { runInAction(() => {
[note.uuid]: note, this.selectedNotes = {
}; [note.uuid]: note,
this.lastSelectedNote = note; };
this.lastSelectedNote = note;
});
} }
} }
@@ -204,15 +208,19 @@ export class NotesState {
if (trashed) { if (trashed) {
const notesDeleted = await this.deleteNotes(false); const notesDeleted = await this.deleteNotes(false);
if (notesDeleted) { if (notesDeleted) {
this.unselectNotes(); runInAction(() => {
this.contextMenuOpen = false; this.unselectNotes();
this.contextMenuOpen = false;
});
} }
} else { } else {
await this.changeSelectedNotes((mutator) => { await this.changeSelectedNotes((mutator) => {
mutator.trashed = trashed; mutator.trashed = trashed;
}); });
this.unselectNotes(); runInAction(() => {
this.contextMenuOpen = false; this.unselectNotes();
this.contextMenuOpen = false;
});
} }
} }
@@ -283,8 +291,10 @@ export class NotesState {
mutator.archived = archived; mutator.archived = archived;
}); });
this.selectedNotes = {}; runInAction(() => {
this.contextMenuOpen = false; this.selectedNotes = {};
this.contextMenuOpen = false;
});
} }
async setProtectSelectedNotes(protect: boolean): Promise<void> { async setProtectSelectedNotes(protect: boolean): Promise<void> {

View File

@@ -1,5 +1,5 @@
import { ContentType, SNSmartTag, SNTag } from '@standardnotes/snjs'; import { ContentType, SNSmartTag, SNTag } from '@standardnotes/snjs';
import { computed, makeObservable, observable } from 'mobx'; import { computed, makeObservable, observable, runInAction } from 'mobx';
import { WebApplication } from '../application'; import { WebApplication } from '../application';
export class TagsState { export class TagsState {
@@ -20,11 +20,13 @@ export class TagsState {
appEventListeners.push( appEventListeners.push(
this.application.streamItems( this.application.streamItems(
[ContentType.Tag, ContentType.SmartTag], [ContentType.Tag, ContentType.SmartTag],
async () => { () => {
this.tags = this.application.getDisplayableItems( runInAction(() => {
ContentType.Tag this.tags = this.application.getDisplayableItems(
) as SNTag[]; ContentType.Tag
this.smartTags = this.application.getSmartTags(); ) as SNTag[];
this.smartTags = this.application.getSmartTags();
});
} }
) )
); );