refactor: pass note as parameter to selectNote

This commit is contained in:
Antonella Sgarlatta
2021-05-10 16:25:43 -03:00
parent f317d6cb7c
commit df5327e638
2 changed files with 7 additions and 9 deletions

View File

@@ -7,7 +7,6 @@ import {
NoteMutator, NoteMutator,
ContentType, ContentType,
SNTag, SNTag,
SNItem,
} from '@standardnotes/snjs'; } from '@standardnotes/snjs';
import { import {
makeObservable, makeObservable,
@@ -115,17 +114,16 @@ export class NotesState {
this.lastSelectedNote = selectedNote; this.lastSelectedNote = selectedNote;
} }
async selectNote(uuid: UuidString): Promise<void> { async selectNote(note: SNNote): Promise<void> {
const note = this.application.findItem(uuid) as SNNote;
if ( if (
this.io.activeModifiers.has( this.io.activeModifiers.has(
KeyboardModifier.Meta || KeyboardModifier.Ctrl KeyboardModifier.Meta || KeyboardModifier.Ctrl
) )
) { ) {
if (this.selectedNotes[uuid]) { if (this.selectedNotes[note.uuid]) {
delete this.selectedNotes[uuid]; delete this.selectedNotes[note.uuid];
} else if (await this.application.authorizeNoteAccess(note)) { } else if (await this.application.authorizeNoteAccess(note)) {
this.selectedNotes[uuid] = note; this.selectedNotes[note.uuid] = note;
this.lastSelectedNote = note; this.lastSelectedNote = note;
} }
} else if (this.io.activeModifiers.has(KeyboardModifier.Shift)) { } else if (this.io.activeModifiers.has(KeyboardModifier.Shift)) {
@@ -133,9 +131,9 @@ export class NotesState {
} else { } else {
if (await this.application.authorizeNoteAccess(note)) { if (await this.application.authorizeNoteAccess(note)) {
this.selectedNotes = { this.selectedNotes = {
[uuid]: note, [note.uuid]: note,
}; };
await this.openEditor(uuid); await this.openEditor(note.uuid);
this.lastSelectedNote = note; this.lastSelectedNote = note;
} }
} }

View File

@@ -355,7 +355,7 @@ class NotesViewCtrl extends PureViewCtrl<unknown, NotesCtrlState> {
} }
async selectNote(note: SNNote): Promise<void> { async selectNote(note: SNNote): Promise<void> {
await this.appState.notes.selectNote(note.uuid); await this.appState.notes.selectNote(note);
} }
async createNewNote() { async createNewNote() {