forked from ZhuLinsen/daily_stock_analysis
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.tsx
More file actions
88 lines (79 loc) · 2.67 KB
/
Copy pathApp.tsx
File metadata and controls
88 lines (79 loc) · 2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import type React from 'react';
import { useEffect } from 'react';
import { BrowserRouter as Router, Navigate, Route, Routes, useLocation } from 'react-router-dom';
import HomePage from './pages/HomePage';
import BacktestPage from './pages/BacktestPage';
import SettingsPage from './pages/SettingsPage';
import LoginPage from './pages/LoginPage';
import NotFoundPage from './pages/NotFoundPage';
import ChatPage from './pages/ChatPage';
import PortfolioPage from './pages/PortfolioPage';
import ScreenPage from './pages/ScreenPage';
import { ApiErrorAlert, Shell } from './components/common';
import { AuthProvider, useAuth } from './contexts/AuthContext';
import { useAgentChatStore } from './stores/agentChatStore';
import './App.css';
const AppContent: React.FC = () => {
const location = useLocation();
const { authEnabled, loggedIn, isLoading, loadError, refreshStatus } = useAuth();
useEffect(() => {
useAgentChatStore.getState().setCurrentRoute(location.pathname);
}, [location.pathname]);
if (isLoading) {
return (
<div className="flex min-h-screen items-center justify-center bg-base">
<div className="h-8 w-8 animate-spin rounded-full border-2 border-cyan/20 border-t-cyan" />
</div>
);
}
if (loadError) {
return (
<div className="flex min-h-screen flex-col items-center justify-center gap-4 bg-base px-4">
<div className="w-full max-w-lg">
<ApiErrorAlert error={loadError} />
</div>
<button
type="button"
className="btn-primary"
onClick={() => void refreshStatus()}
>
重试
</button>
</div>
);
}
if (authEnabled && !loggedIn) {
if (location.pathname === '/login') {
return <LoginPage />;
}
const redirect = encodeURIComponent(location.pathname + location.search);
return <Navigate to={`/login?redirect=${redirect}`} replace />;
}
if (location.pathname === '/login') {
return <Navigate to="/" replace />;
}
return (
<Routes>
<Route element={<Shell />}>
<Route path="/" element={<HomePage />} />
<Route path="/screen" element={<ScreenPage />} />
<Route path="/chat" element={<ChatPage />} />
<Route path="/portfolio" element={<PortfolioPage />} />
<Route path="/backtest" element={<BacktestPage />} />
<Route path="/settings" element={<SettingsPage />} />
<Route path="*" element={<NotFoundPage />} />
</Route>
<Route path="/login" element={<LoginPage />} />
</Routes>
);
};
const App: React.FC = () => {
return (
<Router>
<AuthProvider>
<AppContent />
</AuthProvider>
</Router>
);
};
export default App;