import type { ReactElement } from 'react' import { useBridge, useData, usePublish, type PanelRef } from '@jaspers-ai/sdk' import { display as d } from './format' import type { MoverList } from './server/quotes' import { Bar, Loading, Section, Signed, useEvery, usePanelStateValue, useStateWriter } from './shared' import { num, text } from './values' import { MARKET_SCREENS, MARKET_TABS, marketsOutput, readMarketList, REFRESH_MS, tone, yahooPage } from './views' import './styles.css' // The market at a glance: Yahoo's summary strip (index futures, commodities, rates, currencies, // crypto) as tiles, then one of Yahoo's lists of stocks. Both are asked again every minute. A tab or // the screens menu writes `list`. const LIMIT = 25 export function MarketsView({ panel }: { panel: PanelRef }): ReactElement { const state = usePanelStateValue(panel) const write = useStateWriter(panel) if (state === undefined) return const list = readMarketList(state) const screen = MARKET_SCREENS.some((s) => s.list === list) return (
) } function Markets({ panel, list }: { panel: PanelRef; list: MoverList }): ReactElement { const bridge = useBridge() const summary = useData('yfinance/market-summary', {}) const movers = useData('yfinance/movers', { list, limit: LIMIT }) useEvery(summary.refetch, REFRESH_MS) useEvery(movers.refetch, REFRESH_MS) const tiles = summary.data ?? [] const rows = movers.data ?? [] const title = text(movers.meta['title']) const total = num(movers.meta['total']) usePublish(panel, marketsOutput(list, tiles, { title, total, rows })) const open = (symbol: string): void => void bridge.openLink(yahooPage(symbol)) return ( <>
{tiles.map((t) => { const symbol = text(t['symbol']) ?? '' const hint = num(t['priceHint']) return ( ) })}
t.list === list)?.label ?? list} run={movers} aside={rows.length ? `${rows.length}${total !== null ? ` of ${d.fixed(total, 0)}` : ''}` : undefined} empty={rows.length === 0} > {text(movers.meta['description']) &&

{text(movers.meta['description'])}

} {rows.map((q) => { const symbol = text(q['symbol']) ?? '' const hint = num(q['priceHint']) return ( ) })}
Symbol Name Price Change % Volume Avg volume Market cap P/E
{text(q['name'])} {d.price(num(q['price']), hint)} {d.big(num(q['volume']))} {d.big(num(q['averageVolume']))} {d.big(num(q['marketCap']))} {d.fixed(num(q['pe']))}
) }