feat: add tag on dropdown option click

This commit is contained in:
Antonella Sgarlatta
2021-05-24 19:07:07 -03:00
parent e2585200ac
commit a8d6080a6f
3 changed files with 28 additions and 25 deletions

View File

@@ -18,7 +18,8 @@ export const AutocompleteTagInput: FunctionalComponent<Props> = ({
}) => { }) => {
const [searchQuery, setSearchQuery] = useState(''); const [searchQuery, setSearchQuery] = useState('');
const [dropdownVisible, setDropdownVisible] = useState(false); const [dropdownVisible, setDropdownVisible] = useState(false);
const [dropdownMaxHeight, setDropdownMaxHeight] = useState<number | 'auto'>('auto'); const [dropdownMaxHeight, setDropdownMaxHeight] =
useState<number | 'auto'>('auto');
const getActiveNoteTagResults = (query: string) => { const getActiveNoteTagResults = (query: string) => {
const { activeNote } = appState.notes; const { activeNote } = appState.notes;
@@ -38,7 +39,7 @@ export const AutocompleteTagInput: FunctionalComponent<Props> = ({
const showDropdown = () => { const showDropdown = () => {
const { clientHeight } = document.documentElement; const { clientHeight } = document.documentElement;
const inputRect = inputRef.current.getBoundingClientRect(); const inputRect = inputRef.current.getBoundingClientRect();
setDropdownMaxHeight(clientHeight - inputRect.bottom - 32*2); setDropdownMaxHeight(clientHeight - inputRect.bottom - 32 * 2);
setDropdownVisible(true); setDropdownVisible(true);
}; };
@@ -53,10 +54,7 @@ export const AutocompleteTagInput: FunctionalComponent<Props> = ({
return ( return (
<form onSubmit={(event) => event.preventDefault()} className="mt-2"> <form onSubmit={(event) => event.preventDefault()} className="mt-2">
<Disclosure <Disclosure open={dropdownVisible} onChange={showDropdown}>
open={dropdownVisible}
onChange={showDropdown}
>
<input <input
ref={inputRef} ref={inputRef}
className="min-w-80 text-xs no-border h-7 focus:outline-none focus:shadow-none focus:border-bottom" className="min-w-80 text-xs no-border h-7 focus:outline-none focus:shadow-none focus:border-bottom"
@@ -82,6 +80,7 @@ export const AutocompleteTagInput: FunctionalComponent<Props> = ({
key={tag.uuid} key={tag.uuid}
className={`flex items-center border-0 focus:inner-ring-info cursor-pointer className={`flex items-center border-0 focus:inner-ring-info cursor-pointer
hover:bg-contrast color-text bg-transparent px-3 text-left py-1.5`} hover:bg-contrast color-text bg-transparent px-3 text-left py-1.5`}
onClick={() => appState.notes.addTagToActiveNote(tag)}
onBlur={closeOnBlur} onBlur={closeOnBlur}
> >
<Icon type="hashtag" className="color-neutral mr-2" /> <Icon type="hashtag" className="color-neutral mr-2" />

View File

@@ -46,6 +46,7 @@ export class NotesState {
selectedNotesCount: computed, selectedNotesCount: computed,
trashedNotesCount: computed, trashedNotesCount: computed,
reloadActiveNoteTags: action,
setContextMenuOpen: action, setContextMenuOpen: action,
setContextMenuPosition: action, setContextMenuPosition: action,
setContextMenuMaxHeight: action, setContextMenuMaxHeight: action,
@@ -154,6 +155,13 @@ export class NotesState {
} }
} }
async reloadActiveNoteTags(): Promise<void> {
const { activeNote } = this;
if (activeNote) {
this.activeNoteTags = this.application.getAppState().getNoteTags(activeNote);
}
}
private async openEditor(noteUuid: string): Promise<void> { private async openEditor(noteUuid: string): Promise<void> {
if (this.activeEditor?.note?.uuid === noteUuid) { if (this.activeEditor?.note?.uuid === noteUuid) {
return; return;
@@ -171,10 +179,7 @@ export class NotesState {
this.activeEditor.setNote(note); this.activeEditor.setNote(note);
} }
runInAction(() => { this.reloadActiveNoteTags();
this.activeNoteTags = this.application.getAppState().getNoteTags(note);
});
await this.onActiveEditorChanged(); await this.onActiveEditorChanged();
if (note.waitingForKey) { if (note.waitingForKey) {
@@ -361,6 +366,16 @@ export class NotesState {
); );
} }
async addTagToActiveNote(tag: SNTag): Promise<void> {
const { activeNote } = this;
if (activeNote) {
await this.application.changeItem(tag.uuid, (mutator) => {
mutator.addItemAsRelationship(activeNote);
});
this.reloadActiveNoteTags();
}
}
setShowProtectedWarning(show: boolean): void { setShowProtectedWarning(show: boolean): void {
this.showProtectedWarning = show; this.showProtectedWarning = show;
} }

View File

@@ -48,21 +48,10 @@
ng-style="self.notesLocked && {'pointer-events' : 'none'}", ng-style="self.notesLocked && {'pointer-events' : 'none'}",
application='self.application' application='self.application'
) )
div.flex note-tags(
note-tags( application='self.application'
application='self.application' app-state='self.appState'
app-state='self.appState' )
)
input.tags-input(
ng-blur='self.onTagsInputBlur()',
ng-disabled='self.noteLocked',
ng-if='!self.state.tagsComponent',
ng-keyup='$event.keyCode == 13 && $event.target.blur();',
ng-model='self.editorValues.tagsInputValue',
placeholder='#tags',
spellcheck='false',
type='text'
)
div.flex.items-center div.flex.items-center
#save-status #save-status
.message( .message(