From 8f36b4906197d5cf48ee15354008305ab8b5e205 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Thu, 23 Sep 2021 16:34:11 +0200 Subject: [PATCH] web/user: search apps when user typed before apps have loaded Signed-off-by: Jens Langhammer --- web/src/user/LibraryPage.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/web/src/user/LibraryPage.ts b/web/src/user/LibraryPage.ts index c3e826249..a170d0017 100644 --- a/web/src/user/LibraryPage.ts +++ b/web/src/user/LibraryPage.ts @@ -29,6 +29,9 @@ export class LibraryPage extends LitElement { @property({ attribute: false }) selectedApp?: Application; + @property() + query?: string; + fuse?: Fuse; constructor() { @@ -38,6 +41,10 @@ export class LibraryPage extends LitElement { this.fuse = new Fuse(apps.results, { keys: ["slug", "name"], }); + if (!this.fuse || !this.query) return; + const matchingApps = this.fuse.search(this.query); + if (matchingApps.length < 1) return; + this.selectedApp = matchingApps[0].item; }); } @@ -116,9 +123,9 @@ export class LibraryPage extends LitElement { ${config.enabledFeatures.search ? html` { - const query = (ev.target as HTMLInputElement).value; + this.query = (ev.target as HTMLInputElement).value; if (!this.fuse) return; - const apps = this.fuse.search(query); + const apps = this.fuse.search(this.query); if (apps.length < 1) return; this.selectedApp = apps[0].item; }}