feat: add 'add tags' option to menu
This commit is contained in:
@@ -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
|
||||
|
||||
49
app/assets/javascripts/ui_models/app_state/tags_state.ts
Normal file
49
app/assets/javascripts/ui_models/app_state/tags_state.ts
Normal 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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user