-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.tsx
More file actions
106 lines (94 loc) · 3.1 KB
/
App.tsx
File metadata and controls
106 lines (94 loc) · 3.1 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import { useState, useEffect } from 'react';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { BrowserRouter as Router, Routes, Route } from 'react-router-dom';
import { ErrorBoundary } from './components/ErrorBoundary';
import { Layout } from './components/Layout';
import { LoginScreen } from './components/LoginScreen';
import { Dashboard } from './pages/Dashboard';
import { GraphPage } from './pages/GraphPage';
import { NotesPage } from './pages/NotesPage';
import { RulesPage } from './pages/RulesPage';
import { SettingsPage } from './pages/SettingsPage';
import { SharePage } from './pages/SharePage';
// Create a client
const queryClient = new QueryClient({
defaultOptions: {
queries: {
refetchOnWindowFocus: false,
retry: 1,
},
},
});
// Loading screen component
function LoadingScreen() {
return (
<div className="h-screen w-screen bg-background flex items-center justify-center">
<div className="text-center">
<div className="inline-block animate-spin rounded-full h-12 w-12 border-b-2 border-primary mb-4"></div>
<p className="text-lg text-muted-foreground">Loading PolyNote...</p>
</div>
</div>
);
}
function App() {
const [isAuthenticated, setIsAuthenticated] = useState<boolean | null>(null);
const [isLoading, setIsLoading] = useState(true);
useEffect(() => {
// Check authentication status on app startup
const checkAuth = async () => {
try {
const authenticated = await window.electronAPI.isAuthenticated();
setIsAuthenticated(authenticated);
} catch (error) {
console.error('Failed to check authentication status:', error);
// Default to unauthenticated if check fails
setIsAuthenticated(false);
} finally {
setIsLoading(false);
}
};
void checkAuth();
}, []);
const handleLoginSuccess = () => {
setIsAuthenticated(true);
};
const handleContinueAsGuest = () => {
setIsAuthenticated(true); // Allow guest access
};
// Show loading screen while checking auth
if (isLoading) {
return <LoadingScreen />;
}
// Show login screen if not authenticated
if (!isAuthenticated) {
return (
<ErrorBoundary>
<LoginScreen
onLoginSuccess={handleLoginSuccess}
onContinueAsGuest={handleContinueAsGuest}
/>
</ErrorBoundary>
);
}
// Show main app if authenticated
return (
<ErrorBoundary>
<QueryClientProvider client={queryClient}>
<Router>
<Layout>
<Routes>
<Route path="/" element={<Dashboard />} />
<Route path="/notes" element={<NotesPage />} />
<Route path="/notes/:noteId" element={<NotesPage />} />
<Route path="/graph" element={<GraphPage />} />
<Route path="/rules" element={<RulesPage />} />
<Route path="/share" element={<SharePage />} />
<Route path="/settings" element={<SettingsPage />} />
</Routes>
</Layout>
</Router>
</QueryClientProvider>
</ErrorBoundary>
);
}
export default App;