mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 22:12:21 -04:00
Use noSuggestions
This commit is contained in:
parent
ae225f9569
commit
8d8a559f73
2 changed files with 17 additions and 6 deletions
|
@ -48,7 +48,9 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||
let activeInput: HTMLInputElement;
|
||||
|
||||
let autocomplete: any;
|
||||
let suggestionsPromise: Promise<string[]> = Promise.resolve([]);
|
||||
|
||||
const noSuggestions = Promise.resolve([]);
|
||||
let suggestionsPromise: Promise<string[]> = noSuggestions;
|
||||
|
||||
async function fetchSuggestions(input: string): Promise<string[]> {
|
||||
const data = await postRequest(
|
||||
|
@ -63,10 +65,14 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||
|
||||
function updateSuggestions(): void {
|
||||
const activeTag = tags[active!];
|
||||
const activeName = activeTag.name;
|
||||
|
||||
suggestionsPromise = fetchSuggestions(activeTag.name).then(
|
||||
(names: string[]): string[] => names.map(replaceWithUnicodeSeparator)
|
||||
);
|
||||
suggestionsPromise =
|
||||
activeName.length === 0
|
||||
? noSuggestions
|
||||
: fetchSuggestions(activeTag.name).then((names: string[]): string[] =>
|
||||
names.map(replaceWithUnicodeSeparator)
|
||||
);
|
||||
}
|
||||
|
||||
function onAutocomplete(selected: string): void {
|
||||
|
|
|
@ -83,10 +83,10 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||
async function chooseSelected() {
|
||||
active = true;
|
||||
dispatch("choose", { chosen: suggestionsItems[selected ?? -1] });
|
||||
await tick();
|
||||
}
|
||||
|
||||
async function update() {
|
||||
dropdown = dropdown as Dropdown;
|
||||
dropdown.update();
|
||||
await tick();
|
||||
|
||||
|
@ -97,6 +97,10 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||
return selected !== null;
|
||||
}
|
||||
|
||||
function disable(): void {
|
||||
disabled = true;
|
||||
}
|
||||
|
||||
const createAutocomplete =
|
||||
(createDropdown: (element: HTMLElement) => Dropdown) =>
|
||||
(element: HTMLElement): any => {
|
||||
|
@ -110,8 +114,9 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||
selectPrevious,
|
||||
selectNext,
|
||||
chooseSelected,
|
||||
hasSelected,
|
||||
update,
|
||||
hasSelected,
|
||||
disable,
|
||||
};
|
||||
|
||||
return api;
|
||||
|
|
Loading…
Reference in a new issue