import { useEffect, useState, type ReactElement } from 'react'
import { useBridge, useData, usePublish, type PanelRef } from '@jaspers-ai/sdk'
import { display as d } from './format'
import { Bar, Empty, Loading, Section, Signed, SymbolField, useEvery, usePanelStateValue, useStateWriter } from './shared'
import { num, text } from './values'
import { addSymbol, readWatchlist, REFRESH_MS, removeSymbol, watchlistOutput, WATCHLIST_MAX, yahooPage } from './views'
import './styles.css'
// A list of symbols with their quotes, asked again every minute. The field adds a symbol and the
// cross removes one; both write the whole list to state, which is also how the orchestrator sets it.
export function WatchlistView({ panel }: { panel: PanelRef }): ReactElement {
const state = usePanelStateValue(panel)
const write = useStateWriter(panel)
if (state === undefined) return
| Symbol | Name | Last | Change | % | Volume | Market cap | Day range | |
|---|---|---|---|---|---|---|---|---|
| {q ? text(q['name']) : {run.loading ? '…' : 'not found'}} | {q ? d.price(num(q['price']), hint) : ''} | {q && |
{q && |
{q ? d.big(num(q['volume'])) : ''} | {q ? d.big(num(q['marketCap'])) : ''} | {low !== null && high !== null ? `${d.price(low, hint)}–${d.price(high, hint)}` : ''} |