From 48b6b0742fb21a298985dc6c86605099e6d5abd1 Mon Sep 17 00:00:00 2001
From: Aylur <k.demeter@protonmail.com>
Date: Fri, 8 Nov 2024 20:54:11 +0000
Subject: example: fix applauncher text reset

---
 examples/js/applauncher/widget/Applauncher.tsx | 24 ++++++++++++++----------
 1 file changed, 14 insertions(+), 10 deletions(-)

(limited to 'examples/js/applauncher/widget/Applauncher.tsx')

diff --git a/examples/js/applauncher/widget/Applauncher.tsx b/examples/js/applauncher/widget/Applauncher.tsx
index d92b5e3..f52780b 100644
--- a/examples/js/applauncher/widget/Applauncher.tsx
+++ b/examples/js/applauncher/widget/Applauncher.tsx
@@ -27,13 +27,12 @@ function AppButton({ app }: { app: Apps.Application }) {
 }
 
 export default function Applauncher() {
+    const { CENTER } = Gtk.Align
     const apps = new Apps.Apps()
-    const list = Variable(apps.get_list().slice(0, MAX_ITEMS))
-    const hide = () => App.get_window("launcher")!.hide()
 
-    function search(text: string) {
-        list.set(apps.fuzzy_query(text).slice(0, MAX_ITEMS))
-    }
+    const text = Variable("")
+    const list = text(text => apps.fuzzy_query(text).slice(0, MAX_ITEMS))
+    const hide = () => App.get_window("launcher")!.hide()
 
     return <window
         name="launcher"
@@ -41,7 +40,7 @@ export default function Applauncher() {
         exclusivity={Astal.Exclusivity.IGNORE}
         keymode={Astal.Keymode.ON_DEMAND}
         application={App}
-        onShow={() => list.set(apps.get_list().slice(0, MAX_ITEMS))}
+        onShow={() => text.set("")}
         onKeyPressEvent={function (self, event: Gdk.Event) {
             if (event.get_keyval()[1] === Gdk.KEY_Escape)
                 self.hide()
@@ -53,16 +52,21 @@ export default function Applauncher() {
                 <box widthRequest={500} className="Applauncher" vertical>
                     <entry
                         placeholderText="Search"
-                        onChanged={({ text }) => search(text)}
+                        text={text()}
+                        onChanged={self => text.set(self.text)}
                     />
                     <box spacing={6} vertical>
-                        {list(list => list.map(app => (
+                        {list.as(list => list.map(app => (
                             <AppButton app={app} />
                         )))}
                     </box>
-                    <box visible={list(l => l.length === 0)}>
+                    <box
+                        halign={CENTER}
+                        className="not-found"
+                        vertical
+                        visible={list.as(l => l.length === 0)}>
                         <icon icon="system-search-symbolic" />
-                        No match found
+                        <label label="No match found" />
                     </box>
                 </box>
                 <eventbox expand onClick={hide} />
-- 
cgit v1.2.3


From 302fcae7ae0b58767518e6003d0a80966d7ca4bb Mon Sep 17 00:00:00 2001
From: Aylur <k.demeter@protonmail.com>
Date: Fri, 8 Nov 2024 21:23:07 +0000
Subject: example(applauncher): hide on app launch

---
 examples/js/applauncher/widget/Applauncher.tsx | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

(limited to 'examples/js/applauncher/widget/Applauncher.tsx')

diff --git a/examples/js/applauncher/widget/Applauncher.tsx b/examples/js/applauncher/widget/Applauncher.tsx
index f52780b..c7bac68 100644
--- a/examples/js/applauncher/widget/Applauncher.tsx
+++ b/examples/js/applauncher/widget/Applauncher.tsx
@@ -4,8 +4,14 @@ import { Variable } from "astal"
 
 const MAX_ITEMS = 8
 
+function hide() {
+    App.get_window("launcher")!.hide()
+}
+
 function AppButton({ app }: { app: Apps.Application }) {
-    return <button className="AppButton" onClicked={() => app.launch()}>
+    return <button
+        className="AppButton"
+        onClicked={() => { hide(); app.launch() }}>
         <box>
             <icon icon={app.iconName} />
             <box valign={Gtk.Align.CENTER} vertical>
@@ -32,7 +38,10 @@ export default function Applauncher() {
 
     const text = Variable("")
     const list = text(text => apps.fuzzy_query(text).slice(0, MAX_ITEMS))
-    const hide = () => App.get_window("launcher")!.hide()
+    const onEnter = () => {
+        apps.fuzzy_query(text.get())?.[0].launch()
+        hide()
+    }
 
     return <window
         name="launcher"
@@ -54,6 +63,7 @@ export default function Applauncher() {
                         placeholderText="Search"
                         text={text()}
                         onChanged={self => text.set(self.text)}
+                        onActivate={onEnter}
                     />
                     <box spacing={6} vertical>
                         {list.as(list => list.map(app => (
-- 
cgit v1.2.3

