"use client"; import React, { useState } from "react"; import { removeFromWatchlist } from "@/lib/actions/watchlist.actions"; import { getQuote } from "@/lib/actions/finnhub.actions"; import { Bell, Loader2, X } from "lucide-react"; import CreateAlertModal from "./CreateAlertModal"; interface WatchlistStockChipProps { symbol: string; userId: string; } export default function WatchlistStockChip({ symbol, userId }: WatchlistStockChipProps) { const [price, setPrice] = useState(0); const [modalOpen, setModalOpen] = useState(false); const [loadingPrice, setLoadingPrice] = useState(false); const handleBellClick = async () => { setLoadingPrice(true); try { const data = await getQuote(symbol); if (data && data.c) { setPrice(data.c); setModalOpen(true); } else { // Fallback if fetch fails setPrice(0); setModalOpen(true); } } catch (err) { console.error(err); setPrice(0); setModalOpen(true); } finally { setLoadingPrice(false); } }; const handleRemove = async () => { await removeFromWatchlist(userId, symbol); }; return (
{symbol} {/* Divider */}
{/* Alert Button */} {/* Remove Button */}
); }