summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/modules/notifications.tsx56
-rw-r--r--src/modules/updates.tsx52
-rw-r--r--src/widgets/popdownwindow.tsx44
3 files changed, 82 insertions, 70 deletions
diff --git a/src/modules/notifications.tsx b/src/modules/notifications.tsx
index 8b50a12..85747ce 100644
--- a/src/modules/notifications.tsx
+++ b/src/modules/notifications.tsx
@@ -2,7 +2,7 @@ import { bind } from "astal";
import { Astal, Gtk } from "astal/gtk3";
import AstalNotifd from "gi://AstalNotifd";
import Notification from "../widgets/notification";
-import PopupWindow from "../widgets/popupwindow";
+import PopdownWindow from "../widgets/popdownwindow";
const List = () => (
<box
@@ -44,40 +44,22 @@ const List = () => (
);
export default () => (
- <PopupWindow name="notifications">
- <box vertical className="notifications">
- <box className="header">
- <label
- label={bind(AstalNotifd.get_default(), "notifications").as(
- n => `${n.length} notification${n.length === 1 ? "" : "s"}`
- )}
- />
- <box hexpand />
- <button
- cursor="pointer"
- onClicked={() => (AstalNotifd.get_default().dontDisturb = !AstalNotifd.get_default().dontDisturb)}
- label="Silence"
- className={bind(AstalNotifd.get_default(), "dontDisturb").as(d => (d ? "enabled" : ""))}
- />
- <button
- cursor="pointer"
- onClicked={() => AstalNotifd.get_default().notifications.forEach(n => n.dismiss())}
- label="Clear"
- />
- </box>
- <stack
- transitionType={Gtk.StackTransitionType.CROSSFADE}
- transitionDuration={150}
- shown={bind(AstalNotifd.get_default(), "notifications").as(n => (n.length > 0 ? "list" : "empty"))}
- >
- <box vertical valign={Gtk.Align.CENTER} name="empty">
- <label className="icon" label="notifications_active" />
- <label label="All caught up!" />
- </box>
- <scrollable expand hscroll={Gtk.PolicyType.NEVER} name="list">
- <List />
- </scrollable>
- </stack>
- </box>
- </PopupWindow>
+ <PopdownWindow
+ name="notifications"
+ count={bind(AstalNotifd.get_default(), "notifications").as(n => n.length)}
+ headerButtons={[
+ {
+ label: "Silence",
+ onClicked: () => (AstalNotifd.get_default().dontDisturb = !AstalNotifd.get_default().dontDisturb),
+ className: bind(AstalNotifd.get_default(), "dontDisturb").as(d => (d ? "enabled" : "")),
+ },
+ {
+ label: "Clear",
+ onClicked: () => AstalNotifd.get_default().notifications.forEach(n => n.dismiss()),
+ },
+ ]}
+ emptyIcon="notifications_active"
+ emptyLabel="All caught up!"
+ list={<List />}
+ />
);
diff --git a/src/modules/updates.tsx b/src/modules/updates.tsx
index 0a8cbea..feaa3cd 100644
--- a/src/modules/updates.tsx
+++ b/src/modules/updates.tsx
@@ -2,7 +2,7 @@ import { bind, execAsync, Variable } from "astal";
import { App, Astal, Gtk } from "astal/gtk3";
import Updates, { Repo as IRepo, Update as IUpdate } from "../services/updates";
import { MenuItem } from "../utils/widgets";
-import PopupWindow from "../widgets/popupwindow";
+import PopdownWindow from "../widgets/popdownwindow";
const constructItem = (label: string, exec: string, quiet = true) =>
new MenuItem({
@@ -67,36 +67,22 @@ const List = () => (
);
export default () => (
- <PopupWindow name="updates">
- <box vertical className="updates">
- <box className="header">
- <label label={bind(Updates.get_default(), "numUpdates").as(n => `${n} update${n === 1 ? "" : "s"}`)} />
- <box hexpand />
- <button
- cursor="pointer"
- onClicked={() =>
- execAsync("uwsm app -T -- yay")
- .then(() => Updates.get_default().getUpdates())
- // Ignore errors
- .catch(() => {})
- }
- label="Update all"
- />
- <button cursor="pointer" onClicked={() => Updates.get_default().getUpdates()} label="Reload" />
- </box>
- <stack
- transitionType={Gtk.StackTransitionType.CROSSFADE}
- transitionDuration={150}
- shown={bind(Updates.get_default(), "numUpdates").as(n => (n > 0 ? "list" : "empty"))}
- >
- <box vertical valign={Gtk.Align.CENTER} name="empty">
- <label className="icon" label="deployed_code_history" />
- <label label="All packages up to date!" />
- </box>
- <scrollable expand hscroll={Gtk.PolicyType.NEVER} name="list">
- <List />
- </scrollable>
- </stack>
- </box>
- </PopupWindow>
+ <PopdownWindow
+ name="updates"
+ count={bind(Updates.get_default(), "numUpdates")}
+ headerButtons={[
+ {
+ label: "Update all",
+ onClicked: () =>
+ execAsync("uwsm app -T -- yay")
+ .then(() => Updates.get_default().getUpdates())
+ // Ignore errors
+ .catch(() => {}),
+ },
+ { label: "Reload", onClicked: () => Updates.get_default().getUpdates() },
+ ]}
+ emptyIcon="deployed_code_history"
+ emptyLabel="All packages up to date!"
+ list={<List />}
+ />
);
diff --git a/src/widgets/popdownwindow.tsx b/src/widgets/popdownwindow.tsx
new file mode 100644
index 0000000..8710a59
--- /dev/null
+++ b/src/widgets/popdownwindow.tsx
@@ -0,0 +1,44 @@
+import type { Binding } from "astal";
+import { Gtk } from "astal/gtk3";
+import PopupWindow from "./popupwindow";
+
+export default ({
+ name,
+ count,
+ headerButtons,
+ emptyIcon,
+ emptyLabel,
+ list,
+}: {
+ name: string;
+ count: Binding<number>;
+ headerButtons: { label: string; onClicked: () => void; className?: Binding<string> }[];
+ emptyIcon: string;
+ emptyLabel: string;
+ list: JSX.Element;
+}) => (
+ <PopupWindow name={name}>
+ <box vertical className={name}>
+ <box className="header">
+ <label label={count.as(c => `${c} ${name.slice(0, -1)}${c === 1 ? "" : "s"}`)} />
+ <box hexpand />
+ {headerButtons.map(({ label, onClicked, className }) => (
+ <button cursor="pointer" onClicked={onClicked} label={label} className={className} />
+ ))}
+ </box>
+ <stack
+ transitionType={Gtk.StackTransitionType.CROSSFADE}
+ transitionDuration={150}
+ shown={count.as(c => (c > 0 ? "list" : "empty"))}
+ >
+ <box vertical valign={Gtk.Align.CENTER} name="empty">
+ <label className="icon" label={emptyIcon} />
+ <label label={emptyLabel} />
+ </box>
+ <scrollable expand hscroll={Gtk.PolicyType.NEVER} name="list">
+ {list}
+ </scrollable>
+ </stack>
+ </box>
+ </PopupWindow>
+);