From 507223c5b738948176add336a1d00231d2ce6bb7 Mon Sep 17 00:00:00 2001 From: Mo Bitar Date: Thu, 8 Oct 2020 11:44:08 -0500 Subject: [PATCH] fix: associate note with selected tag when saving with editor --- .../javascripts/views/editor/editor_view.ts | 45 +++++++++++++------ .../javascripts/views/footer/footer_view.ts | 10 ----- .../javascripts/views/notes/notes_view.ts | 5 --- .../javascripts/views/tags/tags_view.ts | 9 ++-- .../app/assets/javascripts/strings.d.ts | 1 + dist/@types/app/assets/javascripts/utils.d.ts | 2 - package-lock.json | 4 +- package.json | 2 +- 8 files changed, 41 insertions(+), 37 deletions(-) diff --git a/app/assets/javascripts/views/editor/editor_view.ts b/app/assets/javascripts/views/editor/editor_view.ts index 205cd6116..131562893 100644 --- a/app/assets/javascripts/views/editor/editor_view.ts +++ b/app/assets/javascripts/views/editor/editor_view.ts @@ -474,14 +474,15 @@ class EditorViewCtrl extends PureViewCtrl<{}, EditorState> { } if (this.editor.isTemplateNote) { await this.editor.insertTemplatedNote(); - if (this.appState.selectedTag?.isSmartTag() === false) { - await this.application.changeItem( - this.appState.selectedTag!.uuid, - (mutator) => { - mutator.addItemAsRelationship(note); - } - ) - } + } + const selectedTag = this.appState.selectedTag; + if (!selectedTag?.isSmartTag() && !selectedTag?.hasRelationshipWithItem(note)) { + await this.application.changeItem( + selectedTag!.uuid, + (mutator) => { + mutator.addItemAsRelationship(note); + } + ) } if (!this.application.findItem(note.uuid)) { this.application.alertService!.alert( @@ -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); + } + ) + } + } } } }); diff --git a/app/assets/javascripts/views/footer/footer_view.ts b/app/assets/javascripts/views/footer/footer_view.ts index a9bd412a3..e749a5855 100644 --- a/app/assets/javascripts/views/footer/footer_view.ts +++ b/app/assets/javascripts/views/footer/footer_view.ts @@ -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(component.uuid, (mutator) => { - mutator.setLastSize(data); - }) - } - } - }, focusHandler: (component, focused) => { if (component.isEditor() && focused) { this.closeAllRooms(); diff --git a/app/assets/javascripts/views/notes/notes_view.ts b/app/assets/javascripts/views/notes/notes_view.ts index 10746aa73..8f2b61e99 100644 --- a/app/assets/javascripts/views/notes/notes_view.ts +++ b/app/assets/javascripts/views/notes/notes_view.ts @@ -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) { diff --git a/app/assets/javascripts/views/tags/tags_view.ts b/app/assets/javascripts/views/tags/tags_view.ts index cbde0bbee..3f17199ea 100644 --- a/app/assets/javascripts/views/tags/tags_view.ts +++ b/app/assets/javascripts/views/tags/tags_view.ts @@ -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); }); diff --git a/dist/@types/app/assets/javascripts/strings.d.ts b/dist/@types/app/assets/javascripts/strings.d.ts index ffcada422..aaca54a5b 100644 --- a/dist/@types/app/assets/javascripts/strings.d.ts +++ b/dist/@types/app/assets/javascripts/strings.d.ts @@ -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 = "..."; diff --git a/dist/@types/app/assets/javascripts/utils.d.ts b/dist/@types/app/assets/javascripts/utils.d.ts index 97325b4eb..3b7556603 100644 --- a/dist/@types/app/assets/javascripts/utils.d.ts +++ b/dist/@types/app/assets/javascripts/utils.d.ts @@ -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 */ diff --git a/package-lock.json b/package-lock.json index f5c62870f..669e7ef34 100644 --- a/package-lock.json +++ b/package-lock.json @@ -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", diff --git a/package.json b/package.json index 16bb9cd7f..27a4393f3 100644 --- a/package.json +++ b/package.json @@ -70,6 +70,6 @@ }, "dependencies": { "sncrypto": "github:standardnotes/sncrypto#8794c88daa967eaae493cd5fdec7506d52b257ad", - "snjs": "github:standardnotes/snjs#a5f35e57725eaf08edb4454e0d1ce356e6491bad" + "snjs": "github:standardnotes/snjs#6ee96d33064f6542fda86844c8a498b628a0bd6e" } }