feat: add 'add tags' option to menu

This commit is contained in:
Antonella Sgarlatta
2021-05-04 18:53:26 -03:00
parent 45357c1976
commit 601ece8cbd
7 changed files with 137 additions and 4 deletions

View File

@@ -20,6 +20,7 @@ import { NoAccountWarningState } from './no_account_warning_state';
import { SyncState } from './sync_state';
import { SearchOptionsState } from './search_options_state';
import { NotesState } from './notes_state';
import { TagsState } from './tags_state';
export enum AppStateEvent {
TagChanged,
@@ -65,6 +66,7 @@ export class AppState {
readonly sync = new SyncState();
readonly searchOptions: SearchOptionsState;
readonly notes: NotesState;
readonly tags: TagsState;
isSessionsModalVisible = false;
private appEventObserverRemovers: (() => void)[] = [];
@@ -86,6 +88,10 @@ export class AppState {
},
this.appEventObserverRemovers,
);
this.tags = new TagsState(
application,
this.appEventObserverRemovers,
),
this.noAccountWarning = new NoAccountWarningState(
application,
this.appEventObserverRemovers

View File

@@ -0,0 +1,49 @@
import {
ContentType,
SNSmartTag,
SNTag,
} from '@standardnotes/snjs';
import {
action,
makeObservable,
observable,
} from 'mobx';
import { WebApplication } from '../application';
export class TagsState {
tags: SNTag[] = [];
smartTags: SNSmartTag[] = [];
constructor(
private application: WebApplication,
appEventListeners: (() => void)[]
) {
makeObservable(this, {
tags: observable,
smartTags: observable,
addTagToSelectedNotes: action,
});
appEventListeners.push(
this.application.streamItems(
[ContentType.Tag, ContentType.SmartTag],
async () => {
this.tags = this.application.getDisplayableItems(ContentType.Tag) as SNTag[];
this.smartTags = this.application.getSmartTags();
}
),
);
}
async addTagToSelectedNotes(tag: SNTag): Promise<void> {
const selectedNotes = Object.values(this.application.getAppState().notes.selectedNotes);
await Promise.all(
selectedNotes.map(async note =>
await this.application.changeItem(tag.uuid, (mutator) => {
mutator.addItemAsRelationship(note);
})
)
);
this.application.sync();
}
}