Skip to content

Commit

Permalink
feat: Remove Set Default & Undefault buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
amanharwara committed Oct 1, 2021
1 parent a98409a commit 1a92fff
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 59 deletions.
70 changes: 15 additions & 55 deletions app/assets/javascripts/directives/views/editorMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
});
}

Expand All @@ -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 {
Expand All @@ -121,7 +81,7 @@ export class EditorMenu extends WebDirective {
callback: '&',
selectedEditorUuid: '=',
currentItem: '=',
application: '='
application: '=',
};
}
}
4 changes: 0 additions & 4 deletions app/assets/templates/directives/editor-menu.pug
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)
Expand Down

0 comments on commit 1a92fff

Please sign in to comment.