From 5b221fb72d6b915a56df4c17ecc747bb6f15dee8 Mon Sep 17 00:00:00 2001
From: 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com>
Date: Wed, 9 Apr 2025 14:21:50 +1000
Subject: feat: news headlines for alerts pane
Also handle news api errors
Also config num pages
---
src/modules/sidebar/alerts.tsx | 3 +
src/modules/sidebar/modules/headlines.tsx | 172 ++++++++++++++++++++++++++++++
src/modules/sidebar/modules/news.tsx | 2 +-
3 files changed, 176 insertions(+), 1 deletion(-)
create mode 100644 src/modules/sidebar/modules/headlines.tsx
(limited to 'src/modules/sidebar')
diff --git a/src/modules/sidebar/alerts.tsx b/src/modules/sidebar/alerts.tsx
index 3dd4b5a..b669514 100644
--- a/src/modules/sidebar/alerts.tsx
+++ b/src/modules/sidebar/alerts.tsx
@@ -1,7 +1,10 @@
+import Headlines from "./modules/headlines";
import Notifications from "./modules/notifications";
export default () => (
+
+
);
diff --git a/src/modules/sidebar/modules/headlines.tsx b/src/modules/sidebar/modules/headlines.tsx
new file mode 100644
index 0000000..924e5b8
--- /dev/null
+++ b/src/modules/sidebar/modules/headlines.tsx
@@ -0,0 +1,172 @@
+import News, { type IArticle } from "@/services/news";
+import Palette, { type IPalette } from "@/services/palette";
+import { capitalize } from "@/utils/strings";
+import { setupCustomTooltip } from "@/utils/widgets";
+import { bind, execAsync, Variable } from "astal";
+import { Gtk } from "astal/gtk3";
+
+const fixGoogleNews = (colours: IPalette, title: string, desc: string) => {
+ // Add separator, bold and split at domain (domain is at the end of each headline)
+ const domain = title.split(" - ").at(-1);
+ if (domain) desc = desc.replaceAll(domain, `— ${domain}\n\n`);
+ // Add spaces between sentences
+ desc = desc.replace(/\.([A-Z])/g, ". $1");
+ // Split headlines
+ desc = desc.replace(/(( |\.)[^A-Z][a-z]+)([A-Z])/g, "$1\n\n$3");
+ desc = desc.replace(/( [A-Z]+)([A-Z](?![s])[a-z])/g, "$1\n\n$2");
+ // Add separator and bold domains
+ desc = desc.replace(/ ([a-zA-Z.]+)\n\n/g, ` — $1\n\n`);
+ desc = desc.replace(/ ([a-zA-Z.]+)$/, ` — $1`); // Last domain
+ return desc.trim();
+};
+
+const getCategoryIcon = (category: string) => {
+ if (category === "business") return "monitoring";
+ if (category === "crime") return "speed_camera";
+ if (category === "domestic") return "home";
+ if (category === "education") return "school";
+ if (category === "entertainment") return "tv";
+ if (category === "environment") return "eco";
+ if (category === "food") return "restaurant";
+ if (category === "health") return "health_and_safety";
+ if (category === "lifestyle") return "digital_wellbeing";
+ if (category === "politics") return "account_balance";
+ if (category === "science") return "science";
+ if (category === "sports") return "sports_basketball";
+ if (category === "technology") return "account_tree";
+ if (category === "top") return "breaking_news";
+ if (category === "tourism") return "travel";
+ if (category === "world") return "public";
+ return "newsmode";
+};
+
+const Article = ({ title, description, creator, pubDate, source_name, link }: IArticle) => {
+ const expanded = Variable(false);
+
+ return (
+
+
+
+
+
+
+ );
+};
+
+const Category = ({ title, articles }: { title: string; articles: IArticle[] }) => {
+ const expanded = Variable(false);
+
+ return (
+
+
+
+
+ {articles.map(a => (
+
+ ))}
+
+
+
+ );
+};
+
+const List = () => (
+
+ {bind(News.get_default(), "categories").as(c =>
+ Object.entries(c).map(([k, v]) => )
+ )}
+
+);
+
+const NoNews = () => (
+
+
+
+
+
+
+);
+
+export default () => (
+
+
+
+
+
+ (a.length > 0 ? "list" : "empty"))}
+ >
+
+ (a.length > 0 ? "expanded" : ""))}
+ hscroll={Gtk.PolicyType.NEVER}
+ name="list"
+ >
+
+
+
+
+);
diff --git a/src/modules/sidebar/modules/news.tsx b/src/modules/sidebar/modules/news.tsx
index aba37c7..1ab2383 100644
--- a/src/modules/sidebar/modules/news.tsx
+++ b/src/modules/sidebar/modules/news.tsx
@@ -69,7 +69,7 @@ const List = () => (
const NoNews = () => (
-
+
--
cgit v1.2.3-freya