import React, { Suspense } from 'react'; import { auth } from '@/lib/better-auth/auth'; import { headers } from 'next/headers'; import { redirect } from 'next/navigation'; import { getUserWatchlist } from '@/lib/actions/watchlist.actions'; import { getUserAlerts } from '@/lib/actions/alert.actions'; import { getNews } from '@/lib/actions/finnhub.actions'; import WatchlistManager from '@/components/watchlist/WatchlistManager'; import AlertsPanel from '@/components/watchlist/AlertsPanel'; import NewsGrid from '@/components/watchlist/NewsGrid'; import SearchCommand from '@/components/SearchCommand'; import { Loader2 } from 'lucide-react'; export default async function WatchlistPage() { const session = await auth.api.getSession({ headers: await headers() }); if (!session) { redirect('/sign-in'); } const userId = session.user.id; // Parallel data fetching const [watchlistItems, alerts, news] = await Promise.all([ getUserWatchlist(userId), getUserAlerts(userId), getNews() // Initial news fetch ]); const watchlistSymbols = watchlistItems.map((item: any) => item.symbol); // Fallback news if watchlist has items const relevantNews = watchlistSymbols.length > 0 ? await getNews(watchlistSymbols) : news; return (
Track your favorite stocks and manage alerts.