import { useState } from 'react' import type { FeedResult } from './Feeds' import { INTERVALS, type Interval } from './plan' import { DATABENTO_INTRADAY_TIP, SOURCES, SOURCE_INTERVALS, SOURCE_NAMES, type Source } from './sources' export const COLORS = ['#3b82f6', '#f59e0b', '#10b981', '#ef4444', '#a855f7', '#06b6d4', '#ec4899', '#84cc16', '#f97316', '#94a3b8'] export interface ToolbarProps { symbols: string[] active: string | null source: Source onSource: (s: Source) => void interval: Interval mode: 'lines' | 'candles' volume: boolean feeds: Record onInterval: (i: Interval) => void onMode: (m: 'lines' | 'candles') => void onVolume: (v: boolean) => void onAdd: (symbol: string) => void onRemove: (symbol: string) => void onActive: (symbol: string) => void } /** The controls row and the symbol chips. */ export function Toolbar(p: ToolbarProps) { const [draft, setDraft] = useState('') const add = () => { const symbol = draft.trim().toUpperCase() if (/^[A-Z0-9.^=-]{1,20}$/.test(symbol)) p.onAdd(symbol) setDraft('') } return (
{SOURCE_NAMES[p.source]}
{(['lines', 'candles'] as const).map((m) => ( ))}
setDraft(e.target.value)} onKeyDown={(e) => { if (e.key === 'Enter') add() }} />
{p.symbols.map((s, i) => { const feed = p.feeds[s] const color = COLORS[i % COLORS.length] return ( p.onActive(s)} title={[s, feed?.note, feed?.error ?? feed?.detail].filter(Boolean).join(': ')} > {s} {feed?.error ? ! : null} {feed?.note ? ( {feed.note} ) : null} ) })}
) }