Convert all remaining files to typescript.

This commit is contained in:
Jas Singh
2024-07-26 23:11:33 -07:00
parent ca5dcc629b
commit b511d76e11
84 changed files with 2075 additions and 1987 deletions

View File

@@ -1,56 +0,0 @@
const Controls = (notifs) => {
return Widget.Box({
class_name: "notification-menu-controls",
expand: false,
vertical: false,
children: [
Widget.Box({
class_name: "menu-label-container notifications",
hpack: "start",
vpack: "center",
expand: true,
children: [
Widget.Label({
class_name: "menu-label notifications",
label: "Notifications",
}),
],
}),
Widget.Box({
hpack: "end",
vpack: "center",
expand: false,
children: [
Widget.Switch({
class_name: "menu-switch notifications",
active: notifs.bind("dnd").as((dnd) => !dnd),
on_activate: ({ active }) => {
notifs.dnd = !active;
},
}),
Widget.Box({
children: [
Widget.Separator({
hpack: "center",
vexpand: true,
vertical: true,
class_name: "menu-separator notification-controls",
}),
Widget.Button({
class_name: "clear-notifications-button",
tooltip_text: "Clear Notifications",
on_primary_click: () => notifs.clear(),
child: Widget.Label({
class_name: "clear-notifications-label",
label: "",
}),
}),
],
}),
],
}),
],
});
};
export { Controls };

View File

@@ -0,0 +1,56 @@
const Controls = (notifs) => {
return Widget.Box({
class_name: "notification-menu-controls",
expand: false,
vertical: false,
children: [
Widget.Box({
class_name: "menu-label-container notifications",
hpack: "start",
vpack: "center",
expand: true,
children: [
Widget.Label({
class_name: "menu-label notifications",
label: "Notifications",
}),
],
}),
Widget.Box({
hpack: "end",
vpack: "center",
expand: false,
children: [
Widget.Switch({
class_name: "menu-switch notifications",
active: notifs.bind("dnd").as((dnd: boolean) => !dnd),
on_activate: ({ active }) => {
notifs.dnd = !active;
},
}),
Widget.Box({
children: [
Widget.Separator({
hpack: "center",
vexpand: true,
vertical: true,
class_name: "menu-separator notification-controls",
}),
Widget.Button({
class_name: "clear-notifications-button",
tooltip_text: "Clear Notifications",
on_primary_click: () => notifs.clear(),
child: Widget.Label({
class_name: "clear-notifications-label",
label: "",
}),
}),
],
}),
],
}),
],
});
};
export { Controls };

View File

@@ -1,47 +0,0 @@
const Actions = (notif, notifs) => {
if (notif.actions !== undefined && notif.actions.length > 0) {
return Widget.Box({
class_name: "notification-card-actions menu",
hexpand: true,
vpack: "end",
children: notif.actions.map((action) => {
return Widget.Button({
hexpand: true,
class_name: "notification-action-buttons menu",
on_primary_click: () => {
if (action.id.includes("scriptAction:-")) {
App.closeWindow("notificationsmenu");
Utils.execAsync(
`${action.id.replace("scriptAction:-", "")}`,
).catch((err) => console.error(err));
notifs.CloseNotification(notif.id);
} else {
App.closeWindow("notificationsmenu");
notif.invoke(action.id);
}
},
child: Widget.Box({
hpack: "center",
hexpand: true,
children: [
Widget.Label({
class_name: "notification-action-buttons-label menu",
hexpand: true,
max_width_chars: 15,
truncate: "end",
wrap: true,
label: action.label,
}),
],
}),
});
}),
});
}
return Widget.Box({
class_name: "spacer",
});
};
export { Actions };

View File

@@ -0,0 +1,48 @@
import { Notification, Notifications } from "types/service/notifications";
const Actions = (notif: Notification, notifs: Notifications) => {
if (notif.actions !== undefined && notif.actions.length > 0) {
return Widget.Box({
class_name: "notification-card-actions menu",
hexpand: true,
vpack: "end",
children: notif.actions.map((action) => {
return Widget.Button({
hexpand: true,
class_name: "notification-action-buttons menu",
on_primary_click: () => {
if (action.id.includes("scriptAction:-")) {
App.closeWindow("notificationsmenu");
Utils.execAsync(
`${action.id.replace("scriptAction:-", "")}`,
).catch((err) => console.error(err));
notifs.CloseNotification(notif.id);
} else {
App.closeWindow("notificationsmenu");
notif.invoke(action.id);
}
},
child: Widget.Box({
hpack: "center",
hexpand: true,
children: [
Widget.Label({
class_name: "notification-action-buttons-label menu",
hexpand: true,
max_width_chars: 15,
truncate: "end",
wrap: true,
label: action.label,
}),
],
}),
});
}),
});
}
return Widget.Box({
class_name: "spacer",
});
};
export { Actions };

View File

@@ -1,23 +0,0 @@
import { notifHasImg } from "../../utils.js";
export const Body = (notif) => {
return Widget.Box({
vpack: "start",
hexpand: true,
class_name: "notification-card-body menu",
children: [
Widget.Label({
hexpand: true,
use_markup: true,
xalign: 0,
justification: "left",
truncate: "end",
lines: 2,
max_width_chars: !notifHasImg(notif) ? 35 : 28,
wrap: true,
class_name: "notification-card-body-label menu",
label: notif["body"],
}),
],
});
};

View File

@@ -0,0 +1,24 @@
import { notifHasImg } from "../../utils.js";
import { Notification } from "types/service/notifications";
export const Body = (notif: Notification) => {
return Widget.Box({
vpack: "start",
hexpand: true,
class_name: "notification-card-body menu",
children: [
Widget.Label({
hexpand: true,
use_markup: true,
xalign: 0,
justification: "left",
truncate: "end",
lines: 2,
max_width_chars: !notifHasImg(notif) ? 35 : 28,
wrap: true,
class_name: "notification-card-body-label menu",
label: notif["body"],
}),
],
});
};

View File

@@ -1,12 +0,0 @@
export const CloseButton = (notif, notifs) => {
return Widget.Button({
class_name: "close-notification-button menu",
on_primary_click: () => {
notifs.CloseNotification(notif.id);
},
child: Widget.Label({
label: "󰅜",
hpack: "center",
}),
});
};

View File

@@ -0,0 +1,13 @@
import { Notification, Notifications } from "types/service/notifications";
export const CloseButton = (notif: Notification, notifs: Notifications) => {
return Widget.Button({
class_name: "close-notification-button menu",
on_primary_click: () => {
notifs.CloseNotification(notif.id);
},
child: Widget.Label({
label: "󰅜",
hpack: "center",
}),
});
};

View File

@@ -1,48 +0,0 @@
import GLib from "gi://GLib";
import { NotificationIcon } from "./icon.js";
import { notifHasImg } from "../../utils.js";
const time = (time, format = "%I:%M %p") =>
GLib.DateTime.new_from_unix_local(time).format(format);
export const Header = (notif) => {
return Widget.Box({
vertical: false,
hexpand: true,
children: [
Widget.Box({
class_name: "notification-card-header menu",
hpack: "start",
children: [NotificationIcon(notif)],
}),
Widget.Box({
class_name: "notification-card-header menu",
hexpand: true,
vpack: "start",
children: [
Widget.Label({
class_name: "notification-card-header-label menu",
hpack: "start",
hexpand: true,
vexpand: true,
max_width_chars: !notifHasImg(notif) ? 34 : 22,
truncate: "end",
wrap: true,
label: notif["summary"],
}),
],
}),
Widget.Box({
class_name: "notification-card-header menu",
hpack: "end",
vpack: "start",
hexpand: true,
child: Widget.Label({
vexpand: true,
class_name: "notification-time",
label: time(notif.time),
}),
}),
],
});
};

View File

@@ -0,0 +1,49 @@
import GLib from "gi://GLib";
import { Notification } from "types/service/notifications";
import { NotificationIcon } from "./icon.js";
import { notifHasImg } from "../../utils.js";
const time = (time: number, format = "%I:%M %p") =>
GLib.DateTime.new_from_unix_local(time).format(format);
export const Header = (notif: Notification) => {
return Widget.Box({
vertical: false,
hexpand: true,
children: [
Widget.Box({
class_name: "notification-card-header menu",
hpack: "start",
children: [NotificationIcon(notif)],
}),
Widget.Box({
class_name: "notification-card-header menu",
hexpand: true,
vpack: "start",
children: [
Widget.Label({
class_name: "notification-card-header-label menu",
hpack: "start",
hexpand: true,
vexpand: true,
max_width_chars: !notifHasImg(notif) ? 34 : 22,
truncate: "end",
wrap: true,
label: notif["summary"],
}),
],
}),
Widget.Box({
class_name: "notification-card-header menu",
hpack: "end",
vpack: "start",
hexpand: true,
child: Widget.Label({
vexpand: true,
class_name: "notification-time",
label: time(notif.time),
}),
}),
],
});
};

View File

@@ -1,22 +0,0 @@
import { notifHasImg } from "../../utils.js";
const Image = (notif) => {
if (notifHasImg(notif)) {
return Widget.Box({
class_name: "notification-card-image-container menu",
hpack: "center",
vpack: "center",
vexpand: false,
child: Widget.Box({
hpack: "center",
vexpand: false,
class_name: "notification-card-image menu",
css: `background-image: url("${notif.image}")`,
}),
});
}
return Widget.Box();
};
export { Image };

View File

@@ -0,0 +1,23 @@
import { Notification } from "types/service/notifications";
import { notifHasImg } from "../../utils.js";
const Image = (notif: Notification) => {
if (notifHasImg(notif)) {
return Widget.Box({
class_name: "notification-card-image-container menu",
hpack: "center",
vpack: "center",
vexpand: false,
child: Widget.Box({
hpack: "center",
vexpand: false,
class_name: "notification-card-image menu",
css: `background-image: url("${notif.image}")`,
}),
});
}
return Widget.Box();
};
export { Image };

View File

@@ -1,59 +0,0 @@
import { notifHasImg } from "../utils.js";
import { Header } from "./header/index.js";
import { Actions } from "./actions/index.js";
import { Image } from "./image/index.js";
import { Placeholder } from "./placeholder/index.js";
import { Body } from "./body/index.js";
import { CloseButton } from "./close/index.js";
const NotificationCard = (notifs) => {
return Widget.Box({
class_name: "menu-content-container notifications",
hpack: "center",
vexpand: true,
spacing: 0,
vertical: true,
setup: (self) => {
self.hook(notifs, () => {
const sortedNotifications = notifs.notifications.sort(
(a, b) => b.time - a.time,
);
if (notifs.notifications.length <= 0) {
return (self.children = [Placeholder(notifs)]);
}
return (self.children = sortedNotifications.map((notif) => {
return Widget.Box({
class_name: "notification-card-content-container",
children: [
Widget.Box({
class_name: "notification-card menu",
vpack: "start",
hexpand: true,
vexpand: false,
children: [
Image(notif),
Widget.Box({
vpack: "center",
vertical: true,
hexpand: true,
class_name: `notification-card-content ${!notifHasImg(notif) ? "noimg" : " menu"}`,
children: [
Header(notif),
Body(notif),
Actions(notif, notifs),
],
}),
],
}),
CloseButton(notif, notifs),
],
});
}));
});
},
});
};
export { NotificationCard };

View File

@@ -0,0 +1,60 @@
import { Notifications, Notification } from "types/service/notifications";
import { notifHasImg } from "../utils.js";
import { Header } from "./header/index.js";
import { Actions } from "./actions/index.js";
import { Image } from "./image/index.js";
import { Placeholder } from "./placeholder/index.js";
import { Body } from "./body/index.js";
import { CloseButton } from "./close/index.js";
const NotificationCard = (notifs: Notifications) => {
return Widget.Box({
class_name: "menu-content-container notifications",
hpack: "center",
vexpand: true,
spacing: 0,
vertical: true,
setup: (self) => {
self.hook(notifs, () => {
const sortedNotifications = notifs.notifications.sort(
(a, b) => b.time - a.time,
);
if (notifs.notifications.length <= 0) {
return (self.children = [Placeholder(notifs)]);
}
return (self.children = sortedNotifications.map((notif: Notification) => {
return Widget.Box({
class_name: "notification-card-content-container",
children: [
Widget.Box({
class_name: "notification-card menu",
vpack: "start",
hexpand: true,
vexpand: false,
children: [
Image(notif),
Widget.Box({
vpack: "center",
vertical: true,
hexpand: true,
class_name: `notification-card-content ${!notifHasImg(notif) ? "noimg" : " menu"}`,
children: [
Header(notif),
Body(notif),
Actions(notif, notifs),
],
}),
],
}),
CloseButton(notif, notifs),
],
});
}));
});
},
});
};
export { NotificationCard };

View File

@@ -1,27 +0,0 @@
const Placeholder = (notifs) => {
return Widget.Box({
class_name: "notification-label-container",
vpack: "fill",
hpack: "center",
expand: true,
child: Widget.Box({
vpack: "center",
vertical: true,
expand: true,
children: [
Widget.Label({
vpack: "center",
class_name: "placeholder-label dim bell",
label: notifs.bind("dnd").as((dnd) => (dnd ? "󰂛" : "󰂚")),
}),
Widget.Label({
vpack: "start",
class_name: "placehold-label dim message",
label: "You're all caught up :)",
}),
],
}),
});
};
export { Placeholder };

View File

@@ -0,0 +1,29 @@
import { Notifications } from "types/service/notifications";
const Placeholder = (notifs: Notifications) => {
return Widget.Box({
class_name: "notification-label-container",
vpack: "fill",
hpack: "center",
expand: true,
child: Widget.Box({
vpack: "center",
vertical: true,
expand: true,
children: [
Widget.Label({
vpack: "center",
class_name: "placeholder-label dim bell",
label: notifs.bind("dnd").as((dnd) => (dnd ? "󰂛" : "󰂚")),
}),
Widget.Label({
vpack: "start",
class_name: "placehold-label dim message",
label: "You're all caught up :)",
}),
],
}),
});
};
export { Placeholder };

View File

@@ -1,5 +0,0 @@
const notifHasImg = (notif) => {
return notif.image !== undefined && notif.image.length;
};
export { notifHasImg };

View File

@@ -0,0 +1,7 @@
import { Notification } from "types/service/notifications";
const notifHasImg = (notif: Notification) => {
return notif.image !== undefined && notif.image.length;
};
export { notifHasImg };