summaryrefslogtreecommitdiff
path: root/examples/js/applauncher/widget/Applauncher.tsx
diff options
context:
space:
mode:
authorAylur <[email protected]>2024-11-08 20:54:11 +0000
committerAylur <[email protected]>2024-11-08 20:54:11 +0000
commit48b6b0742fb21a298985dc6c86605099e6d5abd1 (patch)
tree5db4f09d2c09a06e16dc703c8c541610f00def68 /examples/js/applauncher/widget/Applauncher.tsx
parent321350f7d52a65afae095cd5b874c1866084fb64 (diff)
example: fix applauncher text reset
Diffstat (limited to 'examples/js/applauncher/widget/Applauncher.tsx')
-rw-r--r--examples/js/applauncher/widget/Applauncher.tsx24
1 files changed, 14 insertions, 10 deletions
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} />