Merge pull request #709 from esmaeelE/fix/globalticker-offline-state

Markets ticker: show offline state when financial feed disabled
This commit is contained in:
Shadowbroker authored and GitHub committed 2026-11-17 04:26:14 -07:00
commit aa53b355ae
2 files changed
+50 -7

No files matched your search

+32 -3
View File
@@ -115,6 +115,18 @@ export default function Dashboard() {
const [leftOpen, setLeftOpen] = useState(true);
const [rightOpen, setRightOpen] = useState(true);
const [tickerOpen, setTickerOpen] = useState(true);
// True once the user has explicitly toggled the ticker (button or
// shortcut) or carried a "closed" preference from a previous session.
// Until then the open state follows whether the backend has market data,
// so fresh installs (FINANCIAL_ENABLED=false) keep the empty bottom edge
// and the offline hint only appears after a deliberate MARKETS click.
const tickerUserSetRef = useRef(false);
const { stocks: marketStocks } = useDataKeys(['stocks'] as const);
const toggleTickerByUser = () => {
tickerUserSetRef.current = true;
setTickerOpen((p) => !p);
};
// Persist UI panel states
useEffect(() => {
@@ -123,9 +135,23 @@ export default function Dashboard() {
const tk = localStorage.getItem('sb_ticker_open');
if (l !== null) setLeftOpen(l === 'true');
if (r !== null) setRightOpen(r === 'true');
if (tk !== null) setTickerOpen(tk === 'true');
// Only a stored "false" is an unambiguous past user choice (older
// builds auto-wrote "true" on every load); treat that as explicit and
// let "true"/absent follow the data-driven default below.
if (tk !== null) {
tickerUserSetRef.current = tk === 'false';
setTickerOpen(tk === 'true');
}
}, []);
// Data-driven default: open only when market data exists, and only while
// the user hasn't expressed a preference. stocks === undefined means the
// first /api/live-data/slow response hasn't arrived yet — wait for it.
useEffect(() => {
if (tickerUserSetRef.current || marketStocks === undefined) return;
setTickerOpen(Object.keys(marketStocks).length > 0);
}, [marketStocks]);
useEffect(() => {
localStorage.setItem('sb_left_open', leftOpen.toString());
}, [leftOpen]);
@@ -135,6 +161,9 @@ export default function Dashboard() {
}, [rightOpen]);
useEffect(() => {
// Only persist explicit user choices — auto-open/close driven by
// market data must not overwrite (or masquerade as) a preference.
if (!tickerUserSetRef.current) return;
localStorage.setItem('sb_ticker_open', tickerOpen.toString());
}, [tickerOpen]);
@@ -329,7 +358,7 @@ export default function Dashboard() {
useKeyboardShortcuts({
toggleLeft: () => setLeftOpen((p) => !p),
toggleRight: () => setRightOpen((p) => !p),
toggleMarkets: () => setTickerOpen((p) => !p),
toggleMarkets: toggleTickerByUser,
openSettings: () => setSettingsOpen(true),
openLegend: () => setLegendOpen((p) => !p),
openShortcuts: () => setShortcutsOpen((p) => !p),
@@ -1274,7 +1303,7 @@ export default function Dashboard() {
transition={{ type: 'spring', damping: 30, stiffness: 250 }}
>
<button
onClick={() => setTickerOpen(!tickerOpen)}
onClick={toggleTickerByUser}
className="flex items-center gap-2 px-3 py-1 sb-edge-tab border border-b-0 rounded-t-lg text-cyan-400/80 hover:text-cyan-400 hover:bg-cyan-950/60 hover:border-cyan-500/40 transition-colors"
>
<div className="text-[10px] font-mono tracking-[0.25em] font-bold uppercase">
+18 -4
View File
@@ -1,16 +1,30 @@
'use client';
import { useState } from 'react';
import { motion } from '@/lib/motion';
import { ArrowUpRight, ArrowDownRight, TrendingUp, AlertTriangle, ChevronUp } from 'lucide-react';
import { ArrowUpRight, ArrowDownRight, AlertTriangle } from 'lucide-react';
import { useDataKeys } from '@/hooks/useDataStore';
export default function GlobalTicker() {
const { stocks, financial_source } = useDataKeys(['stocks', 'financial_source'] as const);
const entries = Object.entries(stocks || {});
// Not loaded yet — keep the bar hidden so users with finance enabled
// never see a flash of the offline state while the first response is in
// flight. The backend always sends `stocks` and uses {} when the feed is
// off, so undefined strictly means "loading".
if (stocks === undefined) return null;
const entries = Object.entries(stocks);
const fallback = financial_source === 'yfinance';
if (entries.length === 0) return null;
if (entries.length === 0) {
return (
<div className="sb-ticker absolute bottom-0 left-0 right-0 h-7 bg-[rgba(var(--sb-bg-rgb),0.92)] border-t border-[var(--border-primary)] z-[8000] flex items-center justify-center pointer-events-auto backdrop-blur-xl">
<span className="text-[10px] font-mono tracking-[0.2em] uppercase text-[var(--text-muted)]">
MARKETS OFFLINE · see FINANCIAL_ENABLED in backend/.env
</span>
</div>
);
}
// Render a single ticker item
const renderItem = ([ticker, info]: [string, any], index: number) => {