fix: associate note with selected tag when saving with editor

This commit is contained in:
Mo Bitar
2020-10-08 11:44:08 -05:00
parent 53b61f941e
commit 507223c5b7
8 changed files with 41 additions and 37 deletions

View File

@@ -474,15 +474,16 @@ class EditorViewCtrl extends PureViewCtrl<{}, EditorState> {
}
if (this.editor.isTemplateNote) {
await this.editor.insertTemplatedNote();
if (this.appState.selectedTag?.isSmartTag() === false) {
}
const selectedTag = this.appState.selectedTag;
if (!selectedTag?.isSmartTag() && !selectedTag?.hasRelationshipWithItem(note)) {
await this.application.changeItem(
this.appState.selectedTag!.uuid,
selectedTag!.uuid,
(mutator) => {
mutator.addItemAsRelationship(note);
}
)
}
}
if (!this.application.findItem(note.uuid)) {
this.application.alertService!.alert(
STRING_INVALID_NOTE
@@ -1016,7 +1017,7 @@ class EditorViewCtrl extends PureViewCtrl<{}, EditorState> {
if (action === ComponentAction.SetSize) {
const setSize = (
element: HTMLElement,
size: { width: number, height: number }
size: { width: string | number, height: string | number }
) => {
const widthString = typeof size.width === 'string'
? size.width
@@ -1034,19 +1035,37 @@ class EditorViewCtrl extends PureViewCtrl<{}, EditorState> {
const container = document.getElementById(
ElementIds.NoteTagsComponentContainer
);
setSize(container!, data);
setSize(container!, { width: data.width!, height: data.height! });
}
}
}
else if (action === ComponentAction.AssociateItem) {
if (data.item.content_type === ContentType.Tag) {
const tag = this.application.findItem(data.item.uuid) as SNTag;
if (data.item!.content_type === ContentType.Tag) {
const tag = this.application.findItem(data.item!.uuid) as SNTag;
this.addTag(tag);
}
}
else if (action === ComponentAction.DeassociateItem) {
const tag = this.application.findItem(data.item.uuid) as SNTag;
const tag = this.application.findItem(data.item!.uuid) as SNTag;
this.removeTag(tag);
} else if (
action === ComponentAction.SaveSuccess
) {
const savedUuid = data.item ? data.item.uuid : data.items![0].uuid;
if (savedUuid === this.note.uuid) {
const selectedTag = this.appState.selectedTag;
if (
!selectedTag?.isSmartTag() &&
!selectedTag?.hasRelationshipWithItem(this.note)
) {
this.application.changeAndSaveItem(
selectedTag!.uuid,
(mutator) => {
mutator.addItemAsRelationship(this.note);
}
)
}
}
}
}
});

View File

@@ -316,16 +316,6 @@ class FooterViewCtrl extends PureViewCtrl<{}, {
this.unregisterComponent = this.application.componentManager!.registerHandler({
identifier: 'room-bar',
areas: [ComponentArea.Rooms, ComponentArea.Modal],
actionHandler: (component, action, data) => {
if (action === ComponentAction.SetSize) {
/** Do comparison to avoid repetitive calls by arbitrary component */
if (!topLevelCompare(component.getLastSize(), data)) {
this.application.changeItem<ComponentMutator>(component.uuid, (mutator) => {
mutator.setLastSize(data);
})
}
}
},
focusHandler: (component, focused) => {
if (component.isEditor() && focused) {
this.closeAllRooms();

View File

@@ -346,11 +346,6 @@ class NotesViewCtrl extends PureViewCtrl<{}, NotesState> {
return this.application!.getAppState().getSelectedTag();
}
currentTagCanHavePlaceholderNotes() {
const selectedTag = this.selectedTag!;
return selectedTag.isAllTag || !selectedTag.isSmartTag()
}
private async performReloadNotes() {
const tag = this.appState.selectedTag!;
if (!tag) {

View File

@@ -1,3 +1,4 @@
import { PayloadContent } from 'snjs/dist/@types/protocol/payloads/generator';
import { WebDirective, PanelPuppet } from '@/types';
import { WebApplication } from '@/ui_models/application';
import {
@@ -248,15 +249,15 @@ class TagsViewCtrl extends PureViewCtrl<{}, TagState> {
areas: [ComponentArea.TagsList],
actionHandler: (_, action, data) => {
if (action === ComponentAction.SelectItem) {
if (data.item.content_type === ContentType.Tag) {
const tag = this.application.findItem(data.item.uuid);
if (data.item!.content_type === ContentType.Tag) {
const tag = this.application.findItem(data.item!.uuid);
if (tag) {
this.selectTag(tag as SNTag);
}
} else if (data.item.content_type === ContentType.SmartTag) {
} else if (data.item!.content_type === ContentType.SmartTag) {
this.application.createTemplateItem(
ContentType.SmartTag,
data.item.content
data.item!.content as PayloadContent
).then(smartTag => {
this.selectTag(smartTag as SNSmartTag);
});

View File

@@ -8,6 +8,7 @@ export declare const STRING_NEW_UPDATE_READY = "A new update is ready to install
/** @tags */
export declare const STRING_DELETE_TAG = "Are you sure you want to delete this tag? Note: deleting a tag will not delete its notes.";
/** @editor */
export declare const STRING_SAVING_WHILE_DOCUMENT_HIDDEN = "Attempting to save an item while the application is hidden. To protect data integrity, please refresh the application window and try again.";
export declare const STRING_DELETED_NOTE = "The note you are attempting to edit has been deleted, and is awaiting sync. Changes you make will be disregarded.";
export declare const STRING_INVALID_NOTE = "The note you are attempting to save can not be found or has been deleted. Changes you make will not be synced. Please copy this note's text and start a new note.";
export declare const STRING_ELLIPSES = "...";

View File

@@ -1,6 +1,4 @@
export declare const isDev: boolean;
export declare function getParameterByName(name: string, url: string): string | null;
export declare function isNullOrUndefined(value: any): boolean;
export declare function getPlatformString(): string;
export declare function dateToLocalizedString(date: Date): string;
/** Via https://davidwalsh.name/javascript-debounce-function */

4
package-lock.json generated
View File

@@ -10956,8 +10956,8 @@
"from": "github:standardnotes/sncrypto#8794c88daa967eaae493cd5fdec7506d52b257ad"
},
"snjs": {
"version": "github:standardnotes/snjs#a5f35e57725eaf08edb4454e0d1ce356e6491bad",
"from": "github:standardnotes/snjs#a5f35e57725eaf08edb4454e0d1ce356e6491bad"
"version": "github:standardnotes/snjs#6ee96d33064f6542fda86844c8a498b628a0bd6e",
"from": "github:standardnotes/snjs#6ee96d33064f6542fda86844c8a498b628a0bd6e"
},
"sockjs": {
"version": "0.3.20",

View File

@@ -70,6 +70,6 @@
},
"dependencies": {
"sncrypto": "github:standardnotes/sncrypto#8794c88daa967eaae493cd5fdec7506d52b257ad",
"snjs": "github:standardnotes/snjs#a5f35e57725eaf08edb4454e0d1ce356e6491bad"
"snjs": "github:standardnotes/snjs#6ee96d33064f6542fda86844c8a498b628a0bd6e"
}
}