import React, { Suspense } from 'react'; import { auth } from '@/lib/better-auth/auth'; import { headers } from 'next/headers'; import { redirect } from 'next/navigation'; import { getUserWatchlist, isStockInWatchlist, removeFromWatchlist } from '@/lib/actions/watchlist.actions'; import { getUserAlerts } from '@/lib/actions/alert.actions'; import { getNews } from '@/lib/actions/finnhub.actions'; import TradingViewWatchlist from '@/components/watchlist/TradingViewWatchlist'; import WatchlistStockChip from '@/components/watchlist/WatchlistStockChip'; 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 // Parallel data fetching const [watchlistItems, alerts, news] = await Promise.all([ getUserWatchlist(userId), getUserAlerts(userId), getNews() // Initial news fetch, maybe refine later to use watchlist symbols ]); const watchlistSymbols = watchlistItems.map((item: any) => item.symbol); // const watchlistData = await getWatchlistData(watchlistSymbols); // OPTIMIZATION: Removed to prevent 429 errors. Widget handles data. // Fallback news if watchlist has items const relevantNews = watchlistSymbols.length > 0 ? await getNews(watchlistSymbols) : news; return (
{/* Header */}

Watchlist

Track your favorite stocks and manage alerts.

{/* Main Content - Watchlist Table */}
{/* Manage Watchlist Section */}

Manage Symbols {watchlistSymbols.length}

{watchlistSymbols.length > 0 ? (
{watchlistItems.map((item: any) => ( ))}
) : (

No stocks in watchlist.

)}
{/* TradingView Widget */}
{/* News Section */}
}>
{/* Sidebar - Alerts */}
); }