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 'next-auth/react'; import { useRouter } from 'next/navigation'; import { useEffect, useState } from 'react'; import Link from 'next/link'; export default function WatchlistPage() { const { data: session, status } = 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 (status === 'unauthenticated') { router.push('/auth/signin'); return; } if (session?.user) { fetchWatchlist(session.user.id); } }, [session, status, 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(); try { await fetch(`${process.env.NEXT_PUBLIC_API_URL}/api/watchlist`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ user_id: session?.user?.id, ticker: newStock.ticker.toUpperCase(), company_name: newStock.company_name, sector: newStock.sector }) }); setShowAddModal(false); setNewStock({ ticker: '', company_name: '', sector: '' }); fetchWatchlist(session?.user?.id); } 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; try { await fetch(`${process.env.NEXT_PUBLIC_API_URL}/api/watchlist/${id}`, { method: 'DELETE' }); fetchWatchlist(session?.user?.id); } 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