From 2257e1df0cfd0a0dc4c3f296a57ab3db6d5c1b47 Mon Sep 17 00:00:00 2001 From: ItzCrazyKns <95534749+ItzCrazyKns@users.noreply.github.com> Date: Fri, 30 May 2025 08:36:40 +0530 Subject: [PATCH] feat(empty-chat): add article widget --- src/components/EmptyChat.tsx | 4 ++ src/components/NewsArticleWidget.tsx | 71 ++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 src/components/NewsArticleWidget.tsx diff --git a/src/components/EmptyChat.tsx b/src/components/EmptyChat.tsx index 8c6bdab..2a06d1d 100644 --- a/src/components/EmptyChat.tsx +++ b/src/components/EmptyChat.tsx @@ -4,6 +4,7 @@ import { useEffect, useState } from 'react'; import { File } from './ChatWindow'; import Link from 'next/link'; import WeatherWidget from './WeatherWidget'; +import NewsArticleWidget from './NewsArticleWidget'; const EmptyChat = ({ sendMessage, @@ -52,6 +53,9 @@ const EmptyChat = ({
+
+ +
diff --git a/src/components/NewsArticleWidget.tsx b/src/components/NewsArticleWidget.tsx new file mode 100644 index 0000000..eca6940 --- /dev/null +++ b/src/components/NewsArticleWidget.tsx @@ -0,0 +1,71 @@ +import { useEffect, useState } from 'react'; + +interface Article { + title: string; + content: string; + url: string; + thumbnail: string; +} + +const NewsArticleWidget = () => { + const [article, setArticle] = useState
(null); + const [loading, setLoading] = useState(true); + const [error, setError] = useState(false); + + useEffect(() => { + fetch('/api/discover?mode=preview') + .then((res) => res.json()) + .then((data) => { + const articles = (data.blogs || []).filter((a: Article) => a.thumbnail); + setArticle(articles[Math.floor(Math.random() * articles.length)]); + setLoading(false); + }) + .catch(() => { + setError(true); + setLoading(false); + }); + }, []); + + return ( +
+ {loading ? ( + <> +
+
+
+
+
+
+
+ + ) : error ? ( +
Could not load news.
+ ) : article ? ( + + {article.title} +
+
+ {article.title} +
+

+ {article.content} +

+
+
+ ) : null} +
+ ); +}; + +export default NewsArticleWidget;