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

Commit

Permalink
fix: add active tag to new note when not using plain editor
Browse files Browse the repository at this point in the history
  • Loading branch information
Antonella Sgarlatta committed Jul 19, 2021
1 parent fed9591 commit 23676d5
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 25 deletions.
13 changes: 11 additions & 2 deletions src/lib/application_state.ts
Expand Up @@ -280,12 +280,21 @@ export class ApplicationState extends ApplicationService {
* editor's note with an empty one.
*/
async createEditor(title?: string) {
const selectedTagUuid = this.selectedTag
? this.selectedTag.isSmartTag
? undefined
: this.selectedTag.uuid
: undefined;
let activeEditor = this.getActiveEditor();
if (!activeEditor || this.multiEditorEnabled) {
await this.application.editorGroup.createEditor(undefined, title);
await this.application.editorGroup.createEditor(
undefined,
title,
selectedTagUuid
);
activeEditor = this.getActiveEditor();
} else {
await activeEditor.reset(title);
await activeEditor.reset(title, selectedTagUuid);
}
const defaultEditor = this.application.componentManager.getDefaultEditor();
if (defaultEditor) {
Expand Down
14 changes: 10 additions & 4 deletions src/lib/editor.ts
Expand Up @@ -3,6 +3,8 @@ import {
PayloadSource,
removeFromArray,
SNNote,
TagMutator,
UuidString,
} from '@standardnotes/snjs';
import { MobileApplication } from './application';

Expand All @@ -21,11 +23,11 @@ export class Editor {

constructor(private application: MobileApplication) {}

async init(noteUuid?: string, noteTitle?: string) {
async init(noteUuid?: string, noteTitle?: string, noteTagUuid?: UuidString) {
if (noteUuid) {
this.note = this.application?.findItem(noteUuid) as SNNote;
} else {
await this.reset(noteTitle);
await this.reset(noteTitle, noteTagUuid);
}

this.removeStreamObserver = this.application?.streamItems(
Expand Down Expand Up @@ -67,13 +69,17 @@ export class Editor {
* Reverts the editor to a blank state, removing any existing note from view,
* and creating a placeholder note.
*/
async reset(noteTitle?: string) {
async reset(noteTitle?: string, noteTagUuid?: UuidString) {
const note = await this.application?.createTemplateItem(ContentType.Note, {
text: '',
title: noteTitle || '',
references: [],
});

if (noteTagUuid) {
await this.application.changeItem<TagMutator>(noteTagUuid, m => {
m.addItemAsRelationship(note);
});
}
this.setNote(note as SNNote, true);
}

Expand Down
10 changes: 7 additions & 3 deletions src/lib/editor_group.ts
@@ -1,4 +1,4 @@
import { removeFromArray } from '@standardnotes/snjs';
import { removeFromArray, UuidString } from '@standardnotes/snjs';
import { MobileApplication } from './application';
import { Editor } from './editor';

Expand All @@ -20,10 +20,14 @@ export class EditorGroup {
}
}

async createEditor(noteUuid?: string, noteTitle?: string) {
async createEditor(
noteUuid?: string,
noteTitle?: string,
noteTagUuid?: UuidString
) {
if (this.application) {
const editor = new Editor(this.application);
await editor.init(noteUuid, noteTitle);
await editor.init(noteUuid, noteTitle, noteTagUuid);
this.editors.push(editor);
this.notifyObservers();
}
Expand Down
8 changes: 0 additions & 8 deletions src/lib/snjs_helper_hooks.ts
Expand Up @@ -431,14 +431,6 @@ export const useChangeNoteChecks = (

if (editor && editor.isTemplateNote) {
await editor.insertTemplatedNote();
if (application?.getAppState().selectedTag?.isSmartTag === false) {
await application?.changeItem(
application?.getAppState().selectedTag!.uuid,
mutator => {
mutator.addItemAsRelationship(note);
}
);
}
}

if (!application?.findItem(note.uuid)) {
Expand Down
8 changes: 0 additions & 8 deletions src/screens/Compose/Compose.tsx
Expand Up @@ -353,14 +353,6 @@ export class Compose extends React.Component<{}, State> {
}
if (editor?.isTemplateNote) {
await editor?.insertTemplatedNote();
if (this.context?.getAppState().selectedTag?.isSmartTag === false) {
await this.context.changeItem(
this.context?.getAppState().selectedTag!.uuid,
mutator => {
mutator.addItemAsRelationship(note!);
}
);
}
}
if (!this.context?.findItem(note!.uuid)) {
this.context?.alertService!.alert(
Expand Down

0 comments on commit 23676d5

Please sign in to comment.