Watchlist
{stock.ticker}
{stock.company_name}
Your watchlist is empty
Add stocks to track their SEC filings and monitor performance
'use client'; import { useSession } from '@/lib/better-auth'; import { useRouter } from 'next/navigation'; import { useEffect, useState } from 'react'; import Link from 'next/link'; export default function WatchlistPage() { const { data: session, isPending } = useSession(); const router = useRouter(); const [watchlist, setWatchlist] = useState([]); const [loading, setLoading] = useState(true); const [showAddModal, setShowAddModal] = useState(false); const [newStock, setNewStock] = useState({ ticker: '', company_name: '', sector: '' }); useEffect(() => { if (!isPending && !session) { router.push('/auth/signin'); return; } if (session?.user?.id) { fetchWatchlist(session.user.id); } }, [session, isPending, router]); const fetchWatchlist = async (userId: string) => { try { const response = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/api/watchlist/${userId}`); const data = await response.json(); setWatchlist(data); } catch (error) { console.error('Error fetching watchlist:', error); } finally { setLoading(false); } }; const handleAddStock = async (e: React.FormEvent) => { e.preventDefault(); const userId = session?.user?.id; if (!userId) return; try { await fetch(`${process.env.NEXT_PUBLIC_API_URL}/api/watchlist`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ user_id: userId, ticker: newStock.ticker.toUpperCase(), company_name: newStock.company_name, sector: newStock.sector }) }); setShowAddModal(false); setNewStock({ ticker: '', company_name: '', sector: '' }); fetchWatchlist(userId); } catch (error) { console.error('Error adding stock:', error); } }; const handleDeleteStock = async (id: number) => { if (!confirm('Are you sure you want to remove this stock from watchlist?')) return; const userId = session?.user?.id; if (!userId) return; try { await fetch(`${process.env.NEXT_PUBLIC_API_URL}/api/watchlist/${id}`, { method: 'DELETE' }); fetchWatchlist(userId); } catch (error) { console.error('Error deleting stock:', error); } }; if (loading) { return
{stock.company_name}
Your watchlist is empty
Add stocks to track their SEC filings and monitor performance