feat: remove tag on backspace press
This commit is contained in:
@@ -5,6 +5,7 @@ import { Icon } from './Icon';
|
|||||||
import { AutocompleteTagInput } from './AutocompleteTagInput';
|
import { AutocompleteTagInput } from './AutocompleteTagInput';
|
||||||
import { WebApplication } from '@/ui_models/application';
|
import { WebApplication } from '@/ui_models/application';
|
||||||
import { useRef } from 'preact/hooks';
|
import { useRef } from 'preact/hooks';
|
||||||
|
import { SNTag } from '@standardnotes/snjs';
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
application: WebApplication;
|
application: WebApplication;
|
||||||
@@ -15,6 +16,11 @@ const NoteTags = observer(({ application, appState }: Props) => {
|
|||||||
const { activeNoteTags } = appState.notes;
|
const { activeNoteTags } = appState.notes;
|
||||||
const lastTagRef = useRef<HTMLButtonElement>();
|
const lastTagRef = useRef<HTMLButtonElement>();
|
||||||
|
|
||||||
|
const onTagBackspacePress = async (tag: SNTag) => {
|
||||||
|
await appState.notes.removeTagFromActiveNote(tag);
|
||||||
|
lastTagRef.current?.focus();
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-wrap">
|
<div className="flex flex-wrap">
|
||||||
{activeNoteTags.map((tag, index) => (
|
{activeNoteTags.map((tag, index) => (
|
||||||
@@ -22,6 +28,11 @@ const NoteTags = observer(({ application, appState }: Props) => {
|
|||||||
className={`bg-contrast border-0 rounded text-xs color-text p-1 flex items-center
|
className={`bg-contrast border-0 rounded text-xs color-text p-1 flex items-center
|
||||||
mt-2 mr-2 cursor-pointer hover:bg-secondary-contrast focus:bg-secondary-contrast`}
|
mt-2 mr-2 cursor-pointer hover:bg-secondary-contrast focus:bg-secondary-contrast`}
|
||||||
ref={index === activeNoteTags.length - 1 ? lastTagRef : undefined}
|
ref={index === activeNoteTags.length - 1 ? lastTagRef : undefined}
|
||||||
|
onKeyUp={(event) => {
|
||||||
|
if (event.key === 'Backspace') {
|
||||||
|
onTagBackspacePress(tag);
|
||||||
|
}
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<Icon type="hashtag" className="sn-icon--small color-neutral mr-1" />
|
<Icon type="hashtag" className="sn-icon--small color-neutral mr-1" />
|
||||||
{tag.title}
|
{tag.title}
|
||||||
|
|||||||
@@ -158,7 +158,7 @@ export class NotesState {
|
|||||||
reloadActiveNoteTags(): void {
|
reloadActiveNoteTags(): void {
|
||||||
const { activeNote } = this;
|
const { activeNote } = this;
|
||||||
if (activeNote) {
|
if (activeNote) {
|
||||||
this.activeNoteTags = this.application.getSortedTagsForNote(activeNote)
|
this.activeNoteTags = this.application.getSortedTagsForNote(activeNote);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -379,6 +379,18 @@ export class NotesState {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async removeTagFromActiveNote(tag: SNTag): Promise<void> {
|
||||||
|
const { activeNote } = this;
|
||||||
|
if (activeNote) {
|
||||||
|
await this.application.changeItem(tag.uuid, (mutator) => {
|
||||||
|
mutator.removeItemAsRelationship(activeNote);
|
||||||
|
});
|
||||||
|
this.application.sync();
|
||||||
|
this.reloadActiveNoteTags();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
setShowProtectedWarning(show: boolean): void {
|
setShowProtectedWarning(show: boolean): void {
|
||||||
this.showProtectedWarning = show;
|
this.showProtectedWarning = show;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import { WebApplication } from '@/ui_models/application';
|
|
||||||
import { WebDirective } from './../../types';
|
import { WebDirective } from './../../types';
|
||||||
import template from './editor-group-view.pug';
|
import template from './editor-group-view.pug';
|
||||||
import { Editor } from '@/ui_models/editor';
|
import { Editor } from '@/ui_models/editor';
|
||||||
@@ -15,7 +14,7 @@ class EditorGroupViewCtrl extends PureViewCtrl<unknown, {
|
|||||||
super($timeout);
|
super($timeout);
|
||||||
this.state = {
|
this.state = {
|
||||||
showMultipleSelectedNotes: false
|
showMultipleSelectedNotes: false
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
$onInit() {
|
$onInit() {
|
||||||
|
|||||||
Reference in New Issue
Block a user