diff --git a/web/src/App.tsx b/web/src/App.tsx index ef7fff6a8..ac8d729c4 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -101,11 +101,12 @@ function App() { // }; // 获取trader列表(仅在用户登录时) - const { data: traders } = useSWR( + const { data: traders, error: tradersError } = useSWR( user && token ? 'traders' : null, api.getTraders, { refreshInterval: 10000, + shouldRetryOnError: false, // 避免在后端未运行时无限重试 } ) @@ -371,8 +372,14 @@ function App() { lastUpdate={lastUpdate} language={language} traders={traders} + tradersError={tradersError} selectedTraderId={selectedTraderId} onTraderSelect={setSelectedTraderId} + onNavigateToTraders={() => { + window.history.pushState({}, '', '/traders') + setRoute('/traders') + setCurrentPage('traders') + }} /> )} @@ -437,13 +444,17 @@ function TraderDetailsPage({ lastUpdate, language, traders, + tradersError, selectedTraderId, onTraderSelect, + onNavigateToTraders, }: { selectedTrader?: TraderInfo traders?: TraderInfo[] + tradersError?: Error selectedTraderId?: string onTraderSelect: (traderId: string) => void + onNavigateToTraders: () => void status?: SystemStatus account?: AccountInfo positions?: Position[] @@ -452,6 +463,119 @@ function TraderDetailsPage({ lastUpdate: string language: Language }) { + // If API failed with error, show empty state (likely backend not running) + if (tradersError) { + return ( +
+
+ {/* Icon */} +
+ + + +
+ + {/* Title */} +

+ {t('dashboardEmptyTitle', language)} +

+ + {/* Description */} +

+ {t('dashboardEmptyDescription', language)} +

+ + {/* CTA Button */} + +
+
+ ) + } + + // If traders is loaded and empty, show empty state + if (traders && traders.length === 0) { + return ( +
+
+ {/* Icon */} +
+ + + +
+ + {/* Title */} +

+ {t('dashboardEmptyTitle', language)} +

+ + {/* Description */} +

+ {t('dashboardEmptyDescription', language)} +

+ + {/* CTA Button */} + +
+
+ ) + } + + // If traders is still loading or selectedTrader is not ready, show skeleton if (!selectedTrader) { return (
diff --git a/web/src/components/AITradersPage.tsx b/web/src/components/AITradersPage.tsx index c69956c6d..f269f544e 100644 --- a/web/src/components/AITradersPage.tsx +++ b/web/src/components/AITradersPage.tsx @@ -24,6 +24,7 @@ import { AlertTriangle, BookOpen, HelpCircle, + Radio, } from 'lucide-react' // 获取友好的AI模型名称 @@ -691,7 +692,7 @@ export function AITradersPage({ onTraderSelect }: AITradersPageProps) {
-
+