import React, { useEffect, useState } from "react"; import axios from "axios"; import AboutScanner from "./AboutScanner"; function Scanner({ onSelectStock, onSignal, onBuyClick, onResearchClick }) { const [data, setData] = useState(null); const [lastBest, setLastBest] = useState(null); const loadData = async () => { try { const res = await axios.get("/api/scanner/scan"); const newData = res.data; const best = newData.best_5 && newData.best_5.length > 0 ? newData.best_5[0] : null; if (best && best.symbol !== lastBest) { if (onSignal) onSignal(`New Best Trade: ${best.symbol}`); setLastBest(best.symbol); } setData(newData); } catch (err) { console.error(err); } }; useEffect(() => { loadData(); const interval = setInterval(loadData, 100000); return () => clearInterval(interval); }, []); const openChart = (symbol) => { window.open(`https://www.tradingview.com/chart/?symbol=NSE:${symbol}`, "_blank"); }; const removeStockFromSector = async (symbol, sector) => { try { await axios.delete("/api/scanner/sectors", { data: { sector, symbol } }); setData(prev => { const newData = JSON.parse(JSON.stringify(prev)); if (newData.sectors && newData.sectors[sector]) { newData.sectors[sector].stocks = newData.sectors[sector].stocks.filter(s => s.symbol !== symbol); } if (newData.best_5) { newData.best_5 = newData.best_5.filter(s => s.symbol !== symbol); } return newData; }); } catch (err) { console.error("Error removing stock", err); } }; if (!data) return ( <>
Loading Scanner Data (this may take up to 60 seconds for large watchlists)...
); return (
{/* Top 5 Trades */} {(data.best_5 || []).length > 0 && (

🔥 Top 10 Momentum Picks

{(data.best_5 || []).filter(s => s).map((s, i) => ( ))}
Stock Price RSI MACD Signal AI Score Grade Institutional Action
{s?.symbol} ₹{s?.price} 60 ? 'badge-success' : 'badge-neutral'}`}>{s?.rsi} 0 ? 'badge-success' : 'badge-danger'}`}>{s?.macd_hist} {s?.signal} {s.ai_score} / 100 {s.grade} {s.institutional ? 🔥 Yes : No}
{s?.sector && ( )}
)} {/* Sector Tables */} {Object.entries(data.sectors || {}).map(([sector, info]) => { const best = info.top_stock; return (

{sector} ({info.stocks.length} Stocks)

{best && (

Top Pick: {best.symbol} (Score: {best.score})

)}
{(info.stocks || []).map((s, i) => ( ))}
Stock Price MACD Signal Volume Target AI Score Action
{s?.symbol} ₹{s?.price} 0 ? 'badge-success' : 'badge-danger'}`}>{s?.macd_hist} {s?.signal} {s?.volume?.toLocaleString()} ₹{s?.target} {s?.ai_score}
); })}
); } export default Scanner;