feat: instrument analysis

This commit is contained in:
OpenSquared
2026-06-30 16:32:08 +02:00
parent 9904c066b2
commit 9ffcfeeb71
3 changed files with 17 additions and 7 deletions

View File

@@ -1205,8 +1205,8 @@ const PERIODS = [
{ key: '5y', label: '5Y' },
]
export default function InstrumentDashboard({ instrumentIdProp }: { instrumentIdProp?: string } = {}) {
const { id: paramId = 'EURUSD' } = useParams<{ id: string }>()
export default function InstrumentDashboard({ instrumentIdProp, isVisible }: { instrumentIdProp?: string; isVisible?: boolean } = {}) {
const { id: paramId = localStorage.getItem('last_instrument') || 'EURUSD' } = useParams<{ id: string }>()
const navigate = useNavigate()
const [period, setPeriod] = useState('1y')
const [chartStyle, setChartStyle] = useState<'candles' | 'line'>('candles')
@@ -1237,6 +1237,14 @@ export default function InstrumentDashboard({ instrumentIdProp }: { instrumentId
api.get('/causal-lab/templates').then(r => setTemplates(r.data)).catch(() => {})
}, [])
// Silent refresh when the tab becomes visible again (e.g. after analysis updated from MarketEvents)
const mountedRef = useRef(false)
useEffect(() => {
if (!mountedRef.current) { mountedRef.current = true; return }
if (isVisible) fetchSnapshotSilent()
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [isVisible])
const fetchSnapshot = useCallback(() => {
setLoading(true)
api.get(`/instruments/${instrumentId}/snapshot?period=${period}`)