diff --git a/app/assets/javascripts/directives/views/editorMenu.ts b/app/assets/javascripts/directives/views/editorMenu.ts index 3f2d0244e..44427d675 100644 --- a/app/assets/javascripts/directives/views/editorMenu.ts +++ b/app/assets/javascripts/directives/views/editorMenu.ts @@ -4,34 +4,30 @@ import { SNComponent, SNItem, ComponentArea } from '@standardnotes/snjs'; import { isDesktopApplication } from '@/utils'; import template from '%/directives/editor-menu.pug'; import { PureViewCtrl } from '@Views/abstract/pure_view_ctrl'; -import { ComponentMutator } from '@standardnotes/snjs'; interface EditorMenuScope { - callback: (component: SNComponent) => void - selectedEditorUuid: string - currentItem: SNItem - application: WebApplication + callback: (component: SNComponent) => void; + selectedEditorUuid: string; + currentItem: SNItem; + application: WebApplication; } class EditorMenuCtrl extends PureViewCtrl implements EditorMenuScope { - - callback!: () => (component: SNComponent) => void - selectedEditorUuid!: string - currentItem!: SNItem - application!: WebApplication + callback!: () => (component: SNComponent) => void; + selectedEditorUuid!: string; + currentItem!: SNItem; + application!: WebApplication; /* @ngInject */ - constructor( - $timeout: ng.ITimeoutService, - ) { + constructor($timeout: ng.ITimeoutService) { super($timeout); this.state = { - isDesktop: isDesktopApplication() + isDesktop: isDesktopApplication(), }; } public isEditorSelected(editor: SNComponent) { - if(!this.selectedEditorUuid) { + if (!this.selectedEditorUuid) { return false; } return this.selectedEditorUuid === editor.uuid; @@ -43,14 +39,15 @@ class EditorMenuCtrl extends PureViewCtrl implements EditorMenuScope { $onInit() { super.$onInit(); - const editors = this.application.componentManager!.componentsForArea(ComponentArea.Editor) + const editors = this.application + .componentManager!.componentsForArea(ComponentArea.Editor) .sort((a, b) => { return a.name.toLowerCase() < b.name.toLowerCase() ? -1 : 1; }); const defaultEditor = editors.filter((e) => e.isDefaultEditor())[0]; this.setState({ editors: editors, - defaultEditor: defaultEditor + defaultEditor: defaultEditor, }); } @@ -67,46 +64,9 @@ class EditorMenuCtrl extends PureViewCtrl implements EditorMenuScope { }); } - toggleDefaultForEditor(editor: SNComponent) { - if (this.state.defaultEditor === editor) { - this.removeEditorDefault(editor); - } else { - this.makeEditorDefault(editor); - } - } - offlineAvailableForComponent(component: SNComponent) { return component.local_url && this.state.isDesktop; } - - makeEditorDefault(component: SNComponent) { - const currentDefault = this.application.componentManager! - .componentsForArea(ComponentArea.Editor) - .filter((e) => e.isDefaultEditor())[0]; - if (currentDefault) { - this.application.changeItem(currentDefault.uuid, (m) => { - const mutator = m as ComponentMutator; - mutator.defaultEditor = false; - }); - } - this.application.changeAndSaveItem(component.uuid, (m) => { - const mutator = m as ComponentMutator; - mutator.defaultEditor = true; - }); - this.setState({ - defaultEditor: component - }); - } - - removeEditorDefault(component: SNComponent) { - this.application.changeAndSaveItem(component.uuid, (m) => { - const mutator = m as ComponentMutator; - mutator.defaultEditor = false; - }); - this.setState({ - defaultEditor: null - }); - } } export class EditorMenu extends WebDirective { @@ -121,7 +81,7 @@ export class EditorMenu extends WebDirective { callback: '&', selectedEditorUuid: '=', currentItem: '=', - application: '=' + application: '=', }; } } diff --git a/app/assets/templates/directives/editor-menu.pug b/app/assets/templates/directives/editor-menu.pug index 67710575f..7d278faca 100644 --- a/app/assets/templates/directives/editor-menu.pug +++ b/app/assets/templates/directives/editor-menu.pug @@ -11,11 +11,7 @@ menu-row( ng-repeat='editor in self.state.editors track by editor.uuid' action='self.selectComponent(editor)', - button-action='self.toggleDefaultForEditor(editor)', - button-class="self.isEditorSelected(editor) ? 'warning' : 'info'", - button-text="self.isEditorDefault(editor) ? 'Undefault' : 'Set Default'", circle="self.isEditorSelected(editor) && 'success'", - has-button='self.isEditorSelected(editor) || isEditorDefault(editor)', label='editor.name', subtitle="self.isEditorSelected(editor) && 'Version ' + editor.package_info.version", )