From b2d15be1845498a656e2300fbf2dbbc3bc0e1783 Mon Sep 17 00:00:00 2001 From: Antonella Sgarlatta Date: Mon, 24 May 2021 17:22:54 -0300 Subject: [PATCH] feat: omit active note tags from dropdown --- .../components/AutocompleteTagInput.tsx | 15 ++++++++++++--- app/assets/javascripts/components/NoteTags.tsx | 2 +- .../ui_models/app_state/notes_state.ts | 4 ++++ 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/app/assets/javascripts/components/AutocompleteTagInput.tsx b/app/assets/javascripts/components/AutocompleteTagInput.tsx index 9eb08995371..a6e6148d828 100644 --- a/app/assets/javascripts/components/AutocompleteTagInput.tsx +++ b/app/assets/javascripts/components/AutocompleteTagInput.tsx @@ -5,19 +5,28 @@ 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 = ({ application, + appState, }) => { const [searchQuery, setSearchQuery] = useState(''); + const [dropdownVisible, setDropdownVisible] = useState(false); + + const getActiveNoteTagResults = (query: string) => { + const { activeNote } = appState.notes; + return application.searchTags(query, activeNote); + }; + const [tagResults, setTagResults] = useState(() => { - return application.searchTags(''); + return getActiveNoteTagResults(''); }); - const [dropdownVisible, setDropdownVisible] = useState(false); const dropdownRef = useRef(); const [closeOnBlur] = useCloseOnBlur(dropdownRef, (visible: boolean) => @@ -26,7 +35,7 @@ export const AutocompleteTagInput: FunctionalComponent = ({ const onSearchQueryChange = (event: Event) => { const query = (event.target as HTMLInputElement).value; - const tags = application.searchTags(query); + const tags = getActiveNoteTagResults(query); setSearchQuery(query); setTagResults(tags); diff --git a/app/assets/javascripts/components/NoteTags.tsx b/app/assets/javascripts/components/NoteTags.tsx index 015185ef5c0..87906b38132 100644 --- a/app/assets/javascripts/components/NoteTags.tsx +++ b/app/assets/javascripts/components/NoteTags.tsx @@ -19,7 +19,7 @@ const NoteTags = observer(({ application, appState }: Props) => { {tag.title} ))} - + ); }); diff --git a/app/assets/javascripts/ui_models/app_state/notes_state.ts b/app/assets/javascripts/ui_models/app_state/notes_state.ts index d8dcccb02f2..18297eb2714 100644 --- a/app/assets/javascripts/ui_models/app_state/notes_state.ts +++ b/app/assets/javascripts/ui_models/app_state/notes_state.ts @@ -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; }