import type { ReactElement } from 'react' import { useBridge, useData, usePanelState, usePublish, type PanelRef } from '@jaspers-ai/sdk' import { newsOutput, readNewsState, readSymbol, type Row } from './fmp' import { Loading, NoSymbol, Section, SymbolField, rowsOf, useInitialState } from './shared' import './styles.css' // Stock news for one company: FMP's search-stock-news, newest first. A title opens its article in // the system browser through the bridge, since the frame can open nothing itself. export function NewsView({ panel }: { panel: PanelRef }): ReactElement { const initial = useInitialState(panel) if (initial === undefined) return return } function News({ panel, initial }: { panel: PanelRef; initial: unknown }): ReactElement { const first = readNewsState(initial) const [symbol, setSymbol] = usePanelState(panel, 'symbol', first.symbol) const [limit] = usePanelState(panel, 'limit', first.limit) const state = readNewsState({ symbol, limit }) return (
News
{state.symbol ? : }
) } function Body({ panel, symbol, limit }: { panel: PanelRef; symbol: string; limit: number }): ReactElement { const bridge = useBridge() const news = useData('fmp/news', { endpoint: 'search-stock-news', symbols: [symbol], limit }) const rows = rowsOf(news) usePublish(panel, newsOutput(symbol, news.data)) return (
    {rows.map((row, index) => ( void bridge.openLink(url)} /> ))}
) } function Item({ row, onOpen }: { row: Row; onOpen: (url: string) => void }): ReactElement { const url = typeof row['url'] === 'string' ? row['url'] : '' const title = String(row['title'] ?? '') return (
  • {String(row['publishedDate'] ?? '').slice(0, 16)} {String(row['site'] ?? row['publisher'] ?? '')}
    {url.startsWith('https://') ? ( ) : ( {title} )} {typeof row['text'] === 'string' && row['text'] &&

    {row['text']}

    }
  • ) }