Skip to content

Commit

Permalink
feat: omit active note tags from dropdown
Browse files Browse the repository at this point in the history
  • Loading branch information
Antonella Sgarlatta committed May 24, 2021
1 parent f23e4a4 commit b2d15be
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
15 changes: 12 additions & 3 deletions app/assets/javascripts/components/AutocompleteTagInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<Props> = ({
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<SNTag[]>(() => {
return application.searchTags('');
return getActiveNoteTagResults('');
});
const [dropdownVisible, setDropdownVisible] = useState(false);

const dropdownRef = useRef<HTMLDivElement>();
const [closeOnBlur] = useCloseOnBlur(dropdownRef, (visible: boolean) =>
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion app/assets/javascripts/components/NoteTags.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const NoteTags = observer(({ application, appState }: Props) => {
{tag.title}
</span>
))}
<AutocompleteTagInput application={application} />
<AutocompleteTagInput application={application} appState={appState} />
</div>
);
});
Expand Down
4 changes: 4 additions & 0 deletions app/assets/javascripts/ui_models/app_state/notes_state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit b2d15be

Please sign in to comment.