feat: omit active note tags from dropdown
This commit is contained in:
@@ -5,20 +5,29 @@ import { useRef, useState } from 'preact/hooks';
|
||||
import { Icon } from './Icon';
|
||||
import { Disclosure, DisclosurePanel } from '@reach/disclosure';
|
||||
import { useCloseOnBlur } from './utils';
|
||||
import { AppState } from '@/ui_models/app_state';
|
||||
|
||||
type Props = {
|
||||
application: WebApplication;
|
||||
appState: AppState;
|
||||
};
|
||||
|
||||
export const AutocompleteTagInput: FunctionalComponent<Props> = ({
|
||||
application,
|
||||
appState,
|
||||
}) => {
|
||||
const [searchQuery, setSearchQuery] = useState('');
|
||||
const [tagResults, setTagResults] = useState<SNTag[]>(() => {
|
||||
return application.searchTags('');
|
||||
});
|
||||
const [dropdownVisible, setDropdownVisible] = useState(false);
|
||||
|
||||
const getActiveNoteTagResults = (query: string) => {
|
||||
const { activeNote } = appState.notes;
|
||||
return application.searchTags(query, activeNote);
|
||||
};
|
||||
|
||||
const [tagResults, setTagResults] = useState<SNTag[]>(() => {
|
||||
return getActiveNoteTagResults('');
|
||||
});
|
||||
|
||||
const dropdownRef = useRef<HTMLDivElement>();
|
||||
const [closeOnBlur] = useCloseOnBlur(dropdownRef, (visible: boolean) =>
|
||||
setDropdownVisible(visible)
|
||||
@@ -26,7 +35,7 @@ export const AutocompleteTagInput: FunctionalComponent<Props> = ({
|
||||
|
||||
const onSearchQueryChange = (event: Event) => {
|
||||
const query = (event.target as HTMLInputElement).value;
|
||||
const tags = application.searchTags(query);
|
||||
const tags = getActiveNoteTagResults(query);
|
||||
|
||||
setSearchQuery(query);
|
||||
setTagResults(tags);
|
||||
|
||||
@@ -19,7 +19,7 @@ const NoteTags = observer(({ application, appState }: Props) => {
|
||||
{tag.title}
|
||||
</span>
|
||||
))}
|
||||
<AutocompleteTagInput application={application} />
|
||||
<AutocompleteTagInput application={application} appState={appState} />
|
||||
</div>
|
||||
);
|
||||
});
|
||||
|
||||
@@ -70,6 +70,10 @@ export class NotesState {
|
||||
return this.application.editorGroup.editors[0];
|
||||
}
|
||||
|
||||
get activeNote(): SNNote | undefined {
|
||||
return this.activeEditor?.note;
|
||||
}
|
||||
|
||||
get selectedNotesCount(): number {
|
||||
return Object.keys(this.selectedNotes).length;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user