import { useBridge, useData, usePublish, type PanelRef } from '@jaspers-ai/sdk' import './styles.css' interface Story { id: number created: string title: string teaser: string url: string tickers: string [field: string]: unknown } interface State { tickers?: string[] channels?: string[] pageSize?: number } export function NewsView({ panel }: { panel: PanelRef }) { const state = useData(`workspaces/${panel.workspaceId}/panels/${panel.id}/state`) as State | undefined if (state === undefined) return

Loading…

return } function when(iso: string): string { const date = new Date(iso) if (Number.isNaN(date.getTime())) return iso const today = new Date().toDateString() === date.toDateString() return today ? date.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' }) : date.toLocaleDateString([], { month: 'short', day: 'numeric' }) + ' ' + date.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' }) } function List({ panel, tickers, channels, pageSize }: { panel: PanelRef; tickers: string[]; channels: string[]; pageSize: number }) { const args: Record = { pageSize, displayOutput: 'abstract' } if (tickers.length) args.tickers = tickers.join(',') if (channels.length) args.channels = channels.join(',') const { data, error } = useData('benzinga/news', args) const bridge = useBridge() const rows = (data ?? []) as Story[] usePublish(panel, { tickers, count: rows.length, headlines: rows.slice(0, 10).map((r) => ({ created: r.created, title: r.title })), }) const heading = `Benzinga news${tickers.length ? ` · ${tickers.join(', ')}` : ''}` return (

{heading}

{error ? (

{error}

) : !data ? (

Loading…

) : rows.length === 0 ? (

No stories in the last 7 days.

) : ( )}
) }