From e3b5b405c3ee9530fc99c0cc4e80c51f38a858c2 Mon Sep 17 00:00:00 2001 From: Andreas Molnar Date: Thu, 22 Oct 2026 17:01:14 +0200 Subject: [PATCH 1/2] Add standalone news subscription page --- .../components/news/NewsSubscriptionPage.tsx | 141 ++++++++++++++++++ apps/web/src/router.tsx | 5 + 2 files changed, 146 insertions(+) create mode 100644 apps/web/src/components/news/NewsSubscriptionPage.tsx diff --git a/apps/web/src/components/news/NewsSubscriptionPage.tsx b/apps/web/src/components/news/NewsSubscriptionPage.tsx new file mode 100644 index 000000000..77ab32ec7 --- /dev/null +++ b/apps/web/src/components/news/NewsSubscriptionPage.tsx @@ -0,0 +1,141 @@ +import { useEffect, useMemo, useState } from "react"; +import { useNavigate, useSearchParams } from "react-router-dom"; +import useAuth from "@/context/useAuth"; +import { Button } from "@/components/ui/button"; +import SubscriptionDetailsForm from "./SubscriptionDetailsForm"; +import { + getNewsFeedMetadataAction, + getNewsFeedsAction, + getNewsSubscriptionsAction, + subscribeNewsFeedAction, + updateNewsFeedAction, +} from "@/lib/apiClient"; +import { useQueryClient } from "@tanstack/react-query"; +import { queryKeys } from "@/lib/queryClient"; +import type { NewsFeedDraft } from "@dashwise/types/sdk"; + +export default function NewsSubscriptionPage() { + const [searchParams] = useSearchParams(); + const navigate = useNavigate(); + const { token, withAuth } = useAuth(); + const queryClient = useQueryClient(); + const [feeds, setFeeds] = useState<{ id: string; title: string }[]>([]); + const [existingSubscription, setExistingSubscription] = useState(null); + const [saved, setSaved] = useState(false); + const feedUrl = searchParams.get("feedUrl")?.trim() ?? ""; + const feedName = searchParams.get("feedName")?.trim() ?? ""; + + const initialFeed = useMemo(() => feedUrl + ? { feedUrl, name: feedName || feedUrl } + : undefined, [feedName, feedUrl]); + + useEffect(() => { + if (!token) { + navigate("/auth/login", { replace: true }); + return; + } + + let cancelled = false; + void Promise.all([ + withAuth((auth) => getNewsFeedsAction(auth)), + withAuth((auth) => getNewsSubscriptionsAction(auth)), + feedUrl + ? withAuth((auth) => getNewsFeedMetadataAction(auth, feedUrl)).catch(() => null) + : Promise.resolve(null), + ]).then(([feedResponse, subscriptionResponse, metadata]) => { + if (cancelled) return; + setFeeds((feedResponse.feeds ?? []).map((feed) => ({ id: feed.id, title: feed.title }))); + const normalizedTarget = normalizeUrl(metadata?.feedUrl || feedUrl); + const existing = (subscriptionResponse.subscriptions ?? []).find((subscription) => + normalizeUrl(String(subscription.feedUrl ?? subscription.url ?? "")) === normalizedTarget + ); + setExistingSubscription(existing + ? { + ...existing, + feedUrl: String(existing.feedUrl ?? existing.url ?? feedUrl), + name: String(existing.name ?? existing.title ?? feedName ?? feedUrl), + } + : null); + }).catch((error) => console.error("Failed to load news subscription data:", error)); + + return () => { cancelled = true; }; + }, [feedName, feedUrl, navigate, token, withAuth]); + + const closePopup = () => { + if (window.opener) window.close(); + else navigate("/apps/news", { replace: true }); + }; + + if (!token) return null; + + return ( +
+
+
+
+

Dashwise News

+

+ {saved ? "Subscription saved" : existingSubscription ? "Edit subscription" : "New subscription"} +

+
+ +
+ + {saved ? ( +
+

+ {feedName || feedUrl || "The feed"} is now in your News subscriptions. +

+ +
+ ) : ( + withAuth((auth) => getNewsFeedMetadataAction(auth, url))} + onClose={() => undefined} + onSave={async (feed) => { + const payload = { + feedUrl: String(feed.feedUrl ?? feed.url ?? "").trim(), + name: String(feed.name ?? feed.title ?? "").trim(), + icon: String(feed.icon ?? "").trim(), + feedIds: feed.feedIds ?? [], + newFeedTitles: feed.newFeedTitles ?? [], + linkReplaceRule: feed.linkReplaceRule, + fallbackThumbnailUrl: feed.fallbackThumbnailUrl, + thumbnailOverwriteUrl: feed.thumbnailOverwriteUrl, + similarityGroupingWordsBlacklist: feed.similarityGroupingWordsBlacklist, + enableTopicGrouping: feed.enableTopicGrouping !== false, + }; + if (existingSubscription?.id) { + await withAuth((auth) => updateNewsFeedAction(auth, { + subscriptionId: String(existingSubscription.id), + ...payload, + title: payload.name, + })); + } else { + await withAuth((auth) => subscribeNewsFeedAction(auth, payload)); + } + setSaved(true); + await queryClient.invalidateQueries({ queryKey: queryKeys.news.subscriptions(token) }); + await queryClient.invalidateQueries({ queryKey: queryKeys.news.feeds(token) }); + }} + /> + )} +
+
+ ); +} + +function normalizeUrl(value: string) { + try { + const url = new URL(value); + url.hash = ""; + return url.href.replace(/\/$/, ""); + } catch { + return value.trim(); + } +} diff --git a/apps/web/src/router.tsx b/apps/web/src/router.tsx index c855c0a60..17feca90b 100644 --- a/apps/web/src/router.tsx +++ b/apps/web/src/router.tsx @@ -11,6 +11,7 @@ const AuthenticatedLayout = lazy(() => import("./app/(authenticated)/layout")); const OnboardingPage = lazy(() => import("./app/(authenticated)/onboarding/page")); const DynamicPage = lazy(() => import("./app/(authenticated)/dashboard/[page]/page")); const NewsPage = lazy(() => import("./app/(authenticated)/apps/news/page")); +const NewsSubscriptionPage = lazy(() => import("./components/news/NewsSubscriptionPage")); const NewsLayout = lazy(() => import("./components/news/NewsLayout")); const NotificationsPage = lazy(() => import("./app/(authenticated)/apps/monitoring/notifications/page")); const NotificationsInboxPage = lazy(() => import("./app/(authenticated)/apps/notifications/inbox/page")); @@ -68,6 +69,10 @@ export const appRouter = createBrowserRouter([ children: [ { path: "home", element: }, { path: "news", element: }, + { + path: "apps/news/subscribe", + element: , + }, { path: "apps/news", element: ( From 16cb5b4fe4d841de32055a7ed7cf2a234085dbfd Mon Sep 17 00:00:00 2001 From: Andreas Molnar Date: Thu, 22 Oct 2026 17:05:23 +0200 Subject: [PATCH 2/2] Use News dialog for YouTube subscriptions --- .../web/src/components/news/NewsDashboard.tsx | 20 ++- .../components/news/NewsSubscriptionPage.tsx | 141 ------------------ apps/web/src/router.tsx | 5 - 3 files changed, 17 insertions(+), 149 deletions(-) delete mode 100644 apps/web/src/components/news/NewsSubscriptionPage.tsx diff --git a/apps/web/src/components/news/NewsDashboard.tsx b/apps/web/src/components/news/NewsDashboard.tsx index 400aea1a3..b2c442bf0 100644 --- a/apps/web/src/components/news/NewsDashboard.tsx +++ b/apps/web/src/components/news/NewsDashboard.tsx @@ -73,6 +73,7 @@ export default function NewsDashboardComponent() { const [currentPage, setCurrentPage] = useState(1); const [addOpen, setAddOpen] = useState(false); const [editingFeed, setEditingFeed] = useState(null); + const [subscriptionSeed, setSubscriptionSeed] = useState(); const [editFeedOpen, setEditFeedOpen] = useState(false); const [editingNewsFeed, setEditingNewsFeed] = useState(null); const [createFeedOpen, setCreateFeedOpen] = useState(false); @@ -301,6 +302,11 @@ export default function NewsDashboardComponent() { if (sidebarAction === "subscribe") { setEditingFeed(null); + const feedUrl = searchParams.get("feedUrl")?.trim(); + const feedName = searchParams.get("feedName")?.trim(); + setSubscriptionSeed(feedUrl + ? { feedUrl, name: feedName || feedUrl } + : undefined); setAddOpen(true); navigate( `/apps/news/${activeFeedId === "all" ? "" : activeFeedId}` @@ -356,6 +362,7 @@ export default function NewsDashboardComponent() { }, [ sidebarAction, editSubscriptionRef, + searchParams, subscriptions, activeFeedId, navigate, @@ -471,6 +478,7 @@ export default function NewsDashboardComponent() { const openNewSubscription = () => { setEditingFeed(null); + setSubscriptionSeed(undefined); setAddOpen(true); }; @@ -531,8 +539,8 @@ export default function NewsDashboardComponent() { null; const newSubscriptionDefaults = activeFeedId === "all" - ? undefined - : ({ feedIds: [activeFeedId] } as NewsFeedDraft); + ? subscriptionSeed + : ({ ...subscriptionSeed, feedIds: [activeFeedId] } as NewsFeedDraft); const activeSavedListName = activeSavedList ? savedArticlesData?.lists?.find((list) => list.id === activeSavedList || list.name === activeSavedList)?.name || activeSavedList @@ -840,7 +848,10 @@ export default function NewsDashboardComponent() { open={addOpen} onOpenChange={(v) => { setAddOpen(v); - if (!v) setEditingFeed(null); + if (!v) { + setEditingFeed(null); + setSubscriptionSeed(undefined); + } }} > @@ -854,6 +865,7 @@ export default function NewsDashboardComponent() {
{ setAddOpen(false); setEditingFeed(null); + setSubscriptionSeed(undefined); }} onSave={async (feed: any) => { try { @@ -889,6 +902,7 @@ export default function NewsDashboardComponent() { } setAddOpen(false); setEditingFeed(null); + setSubscriptionSeed(undefined); } catch (err) { console.error("Failed to save feed:", err); } diff --git a/apps/web/src/components/news/NewsSubscriptionPage.tsx b/apps/web/src/components/news/NewsSubscriptionPage.tsx deleted file mode 100644 index 77ab32ec7..000000000 --- a/apps/web/src/components/news/NewsSubscriptionPage.tsx +++ /dev/null @@ -1,141 +0,0 @@ -import { useEffect, useMemo, useState } from "react"; -import { useNavigate, useSearchParams } from "react-router-dom"; -import useAuth from "@/context/useAuth"; -import { Button } from "@/components/ui/button"; -import SubscriptionDetailsForm from "./SubscriptionDetailsForm"; -import { - getNewsFeedMetadataAction, - getNewsFeedsAction, - getNewsSubscriptionsAction, - subscribeNewsFeedAction, - updateNewsFeedAction, -} from "@/lib/apiClient"; -import { useQueryClient } from "@tanstack/react-query"; -import { queryKeys } from "@/lib/queryClient"; -import type { NewsFeedDraft } from "@dashwise/types/sdk"; - -export default function NewsSubscriptionPage() { - const [searchParams] = useSearchParams(); - const navigate = useNavigate(); - const { token, withAuth } = useAuth(); - const queryClient = useQueryClient(); - const [feeds, setFeeds] = useState<{ id: string; title: string }[]>([]); - const [existingSubscription, setExistingSubscription] = useState(null); - const [saved, setSaved] = useState(false); - const feedUrl = searchParams.get("feedUrl")?.trim() ?? ""; - const feedName = searchParams.get("feedName")?.trim() ?? ""; - - const initialFeed = useMemo(() => feedUrl - ? { feedUrl, name: feedName || feedUrl } - : undefined, [feedName, feedUrl]); - - useEffect(() => { - if (!token) { - navigate("/auth/login", { replace: true }); - return; - } - - let cancelled = false; - void Promise.all([ - withAuth((auth) => getNewsFeedsAction(auth)), - withAuth((auth) => getNewsSubscriptionsAction(auth)), - feedUrl - ? withAuth((auth) => getNewsFeedMetadataAction(auth, feedUrl)).catch(() => null) - : Promise.resolve(null), - ]).then(([feedResponse, subscriptionResponse, metadata]) => { - if (cancelled) return; - setFeeds((feedResponse.feeds ?? []).map((feed) => ({ id: feed.id, title: feed.title }))); - const normalizedTarget = normalizeUrl(metadata?.feedUrl || feedUrl); - const existing = (subscriptionResponse.subscriptions ?? []).find((subscription) => - normalizeUrl(String(subscription.feedUrl ?? subscription.url ?? "")) === normalizedTarget - ); - setExistingSubscription(existing - ? { - ...existing, - feedUrl: String(existing.feedUrl ?? existing.url ?? feedUrl), - name: String(existing.name ?? existing.title ?? feedName ?? feedUrl), - } - : null); - }).catch((error) => console.error("Failed to load news subscription data:", error)); - - return () => { cancelled = true; }; - }, [feedName, feedUrl, navigate, token, withAuth]); - - const closePopup = () => { - if (window.opener) window.close(); - else navigate("/apps/news", { replace: true }); - }; - - if (!token) return null; - - return ( -
-
-
-
-

Dashwise News

-

- {saved ? "Subscription saved" : existingSubscription ? "Edit subscription" : "New subscription"} -

-
- -
- - {saved ? ( -
-

- {feedName || feedUrl || "The feed"} is now in your News subscriptions. -

- -
- ) : ( - withAuth((auth) => getNewsFeedMetadataAction(auth, url))} - onClose={() => undefined} - onSave={async (feed) => { - const payload = { - feedUrl: String(feed.feedUrl ?? feed.url ?? "").trim(), - name: String(feed.name ?? feed.title ?? "").trim(), - icon: String(feed.icon ?? "").trim(), - feedIds: feed.feedIds ?? [], - newFeedTitles: feed.newFeedTitles ?? [], - linkReplaceRule: feed.linkReplaceRule, - fallbackThumbnailUrl: feed.fallbackThumbnailUrl, - thumbnailOverwriteUrl: feed.thumbnailOverwriteUrl, - similarityGroupingWordsBlacklist: feed.similarityGroupingWordsBlacklist, - enableTopicGrouping: feed.enableTopicGrouping !== false, - }; - if (existingSubscription?.id) { - await withAuth((auth) => updateNewsFeedAction(auth, { - subscriptionId: String(existingSubscription.id), - ...payload, - title: payload.name, - })); - } else { - await withAuth((auth) => subscribeNewsFeedAction(auth, payload)); - } - setSaved(true); - await queryClient.invalidateQueries({ queryKey: queryKeys.news.subscriptions(token) }); - await queryClient.invalidateQueries({ queryKey: queryKeys.news.feeds(token) }); - }} - /> - )} -
-
- ); -} - -function normalizeUrl(value: string) { - try { - const url = new URL(value); - url.hash = ""; - return url.href.replace(/\/$/, ""); - } catch { - return value.trim(); - } -} diff --git a/apps/web/src/router.tsx b/apps/web/src/router.tsx index 17feca90b..c855c0a60 100644 --- a/apps/web/src/router.tsx +++ b/apps/web/src/router.tsx @@ -11,7 +11,6 @@ const AuthenticatedLayout = lazy(() => import("./app/(authenticated)/layout")); const OnboardingPage = lazy(() => import("./app/(authenticated)/onboarding/page")); const DynamicPage = lazy(() => import("./app/(authenticated)/dashboard/[page]/page")); const NewsPage = lazy(() => import("./app/(authenticated)/apps/news/page")); -const NewsSubscriptionPage = lazy(() => import("./components/news/NewsSubscriptionPage")); const NewsLayout = lazy(() => import("./components/news/NewsLayout")); const NotificationsPage = lazy(() => import("./app/(authenticated)/apps/monitoring/notifications/page")); const NotificationsInboxPage = lazy(() => import("./app/(authenticated)/apps/notifications/inbox/page")); @@ -69,10 +68,6 @@ export const appRouter = createBrowserRouter([ children: [ { path: "home", element: }, { path: "news", element: }, - { - path: "apps/news/subscribe", - element: , - }, { path: "apps/news", element: (