diff --git a/app/routes/analyze.tsx b/app/routes/analyze.tsx index 4335626..61dee98 100644 --- a/app/routes/analyze.tsx +++ b/app/routes/analyze.tsx @@ -210,6 +210,22 @@ export default function Analyze() { loadPortfolio(); }, []); + // Auto-load indicators for stocks that don't have them yet + useEffect(() => { + const unloaded = stocks.filter((s) => !s.indicatorsLoading && s.indicators.rsi == null); + if (unloaded.length === 0) return; + + unloaded.forEach(async (stock) => { + setStocks((s) => s.map((st) => st.id === stock.id ? { ...st, indicatorsLoading: true } : st)); + const indicators = await loadIndicators(stock.ticker); + if (indicators) { + setStocks((s) => s.map((st) => st.id === stock.id ? { ...st, indicators, indicatorsLoading: false } : st)); + } else { + setStocks((s) => s.map((st) => st.id === stock.id ? { ...st, indicatorsLoading: false } : st)); + } + }); + }, [stocks]); + useEffect(() => { const interval = setInterval(() => { stocks.forEach((stock) => { @@ -388,7 +404,6 @@ export default function Analyze() { const loadAllIndicators = async () => { for (const stock of stocks) { - if (stock.indicators.rsi != null) continue; setStocks((s) => s.map((st) => st.id === stock.id ? { ...st, indicatorsLoading: true } : st)); const indicators = await loadIndicators(stock.ticker); if (indicators) { @@ -408,7 +423,7 @@ export default function Analyze() {