-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.tsx
More file actions
289 lines (255 loc) · 11 KB
/
App.tsx
File metadata and controls
289 lines (255 loc) · 11 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
import React, { useState, useEffect, useCallback } from 'react';
import Sidebar from './components/Sidebar';
import Editor from './components/Editor';
import Settings from './components/Settings';
import Templates from './components/Templates';
import SearchModal from './components/SearchModal';
import Login from './components/Login';
import Dashboard from './components/Dashboard';
import Trash from './components/Trash';
import Notifications from './components/Notifications';
import ErrorPage from './components/ErrorPage';
// New Imports
import ThinkingCanvas from './components/ThinkingCanvas';
import DecisionLog from './components/DecisionLog';
import StudyMode from './components/StudyMode';
import KnowledgeMap from './components/KnowledgeMap';
import Analytics from './components/Analytics';
import ReviewMode from './components/ReviewMode';
import Assistant from './components/Assistant';
import Timeline from './components/Timeline';
import DataControl from './components/DataControl';
import { Workspace, Document, User, Block } from './types';
import { AuthProvider, useAuth } from './hooks/useAuth';
import { useDocuments } from './hooks/useDocuments';
import { getDocumentCollaborators } from './services/profileService';
import { moveToTrash } from './services/documentService';
import { useTour } from './hooks/useTour';
import { DialogProvider, useDialog } from './contexts/DialogContext';
type ViewType =
| 'editor'
| 'settings'
| 'templates'
| 'dashboard'
| 'trash'
| 'notifications'
| 'error'
| 'thinking'
| 'decisions'
| 'study'
| 'knowledge-map'
| 'analytics'
| 'review'
| 'assistant'
| 'timeline'
| 'data';
// Main App Content (inside AuthProvider)
const AppContent: React.FC = () => {
const { user, isLoading: authLoading, signOut } = useAuth();
const {
workspaces,
isLoading: docsLoading,
createDocument: createDoc,
updateDocument: updateDoc,
duplicateDocument: duplicateDoc,
deleteDocument: deleteDoc,
error: docsError,
refreshDocuments: refreshDocs
} = useDocuments();
const { showError } = useDialog();
useEffect(() => {
if (user) {
refreshDocs();
}
}, [user, refreshDocs]);
useEffect(() => {
// Only show document errors if user is authenticated and the error is not 'Not authenticated'
// 'Not authenticated' might happen during initial load before auth state settles
if (docsError && user && !docsError.includes('Not authenticated')) {
showError(docsError);
}
}, [docsError, showError, user]);
const [deletedDocs, setDeletedDocs] = useState<Document[]>([]);
const [activeDocId, setActiveDocId] = useState<string>('');
const [currentView, setCurrentView] = useState<ViewType>('dashboard');
const [isSearchOpen, setIsSearchOpen] = useState(false);
const [errorCode, setErrorCode] = useState<404 | 403 | 500>(404);
const [collaborators, setCollaborators] = useState<User[]>([]);
const { startTour, checkAndStartTour } = useTour();
useEffect(() => {
const handleKeyDown = (e: KeyboardEvent) => {
if ((e.metaKey || e.ctrlKey) && e.key === 'k') {
e.preventDefault();
setIsSearchOpen(prev => !prev);
}
};
window.addEventListener('keydown', handleKeyDown);
return () => window.removeEventListener('keydown', handleKeyDown);
}, []);
// Load collaborators when document changes
useEffect(() => {
const loadCollaborators = async () => {
if (activeDocId) {
const collabs = await getDocumentCollaborators(activeDocId);
// Include current user as well
const allUsers = user ? [user, ...collabs.filter(c => c.id !== user.id)] : collabs;
setCollaborators(allUsers);
}
};
loadCollaborators();
}, [activeDocId, user]);
const getActiveDocument = useCallback((): Document | undefined => {
for (const ws of workspaces) {
for (const folder of ws.folders) {
const doc = folder.documents.find(d => d.id === activeDocId);
if (doc) return doc;
}
}
return undefined;
}, [workspaces, activeDocId]);
const handleUpdateDocument = useCallback((updatedDoc: Document) => {
updateDoc(updatedDoc);
}, [updateDoc]);
const handleCreateDocument = useCallback(async (folderId?: string, initialBlocks?: Block[], initialTitle?: string) => {
const newDoc = await createDoc(folderId, initialTitle, initialBlocks);
if (newDoc) {
setActiveDocId(newDoc.id);
setCurrentView('editor');
}
}, [createDoc]);
const handleSelectDoc = useCallback((docId: string) => {
setActiveDocId(docId);
setCurrentView('editor');
}, []);
const handleUseTemplate = useCallback((blocks: Block[], title: string) => {
handleCreateDocument(undefined, blocks, title);
}, [handleCreateDocument]);
const handleRestoreDoc = (doc: Document) => {
// TODO: Implement restore from trash with Supabase
setDeletedDocs(prev => prev.filter(d => d.id !== doc.id));
};
const handleDeleteForever = (docId: string) => {
setDeletedDocs(prev => prev.filter(d => d.id !== docId));
deleteDoc(docId);
};
const handleDuplicateDoc = useCallback(async (docId: string) => {
const doc = workspaces.flatMap(w => w.folders).flatMap(f => f.documents).find(d => d.id === docId);
if (doc) {
await duplicateDoc(docId, `${doc.title} (Copy)`);
}
}, [workspaces, duplicateDoc]);
const handleRenameDoc = useCallback(async (docId: string, newTitle: string) => {
const doc = workspaces.flatMap(w => w.folders).flatMap(f => f.documents).find(d => d.id === docId);
if (doc) {
await updateDoc({ ...doc, title: newTitle });
}
}, [workspaces, updateDoc]);
const getAllRecentDocs = useCallback(() => {
const docs: Document[] = [];
workspaces.forEach(ws => ws.folders.forEach(f => docs.push(...f.documents)));
return docs.sort((a, b) => new Date(b.lastEdited).getTime() - new Date(a.lastEdited).getTime());
}, [workspaces]);
// Check for onboarding tour when user is loaded
useEffect(() => {
if (user && !docsLoading) {
checkAndStartTour();
}
}, [user, docsLoading]);
// Show loading while checking auth and loading docs
if (authLoading || (user && docsLoading)) {
return (
<div className="min-h-screen w-full bg-slate-950 flex items-center justify-center">
<div className="flex flex-col items-center gap-4">
<div className="w-10 h-10 border-2 border-white/30 border-t-white rounded-full animate-spin"></div>
<p className="text-white/60 text-sm">Loading your workspace...</p>
</div>
</div>
);
}
// Show login if not authenticated
if (!user) {
return <Login onLogin={() => { }} />;
}
const activeDoc = getActiveDocument();
const renderContent = () => {
switch (currentView) {
case 'settings': return <Settings />;
case 'templates': return <Templates onUseTemplate={handleUseTemplate} />;
case 'dashboard': return <Dashboard recentDocs={getAllRecentDocs()} onSelectDoc={handleSelectDoc} user={user} onCreateDoc={() => handleCreateDocument()} />;
case 'notifications': return <Notifications />;
case 'trash': return <Trash deletedDocs={deletedDocs} onRestore={handleRestoreDoc} onDeleteForever={handleDeleteForever} />;
case 'error': return <ErrorPage code={errorCode} onGoHome={() => setCurrentView('dashboard')} />;
// New Unique Pages
case 'thinking': return <ThinkingCanvas />;
case 'decisions': return <DecisionLog />;
case 'study': return <StudyMode />;
case 'knowledge-map': return <KnowledgeMap onSelectDocument={handleSelectDoc} />;
case 'analytics': return <Analytics />;
case 'review': return <ReviewMode documentId={activeDocId || undefined} onSelectDocument={handleSelectDoc} />;
case 'assistant': return <Assistant />;
case 'timeline': return <Timeline onSelectDocument={handleSelectDoc} />;
case 'data': return <DataControl />;
case 'editor':
default:
return activeDoc ? (
<Editor
key={activeDoc.id}
document={activeDoc}
updateDocument={handleUpdateDocument}
users={collaborators}
/>
) : (
<ErrorPage code={404} onGoHome={() => setCurrentView('dashboard')} />
);
}
};
return (
<div className="flex w-full h-screen bg-slate-950 p-3 gap-3 relative overflow-hidden">
{/* Ambient Background Mesh - Monochrome Smoke */}
<div className="absolute top-0 left-0 w-full h-full bg-[#09090b]">
<div className="absolute top-[-20%] left-[-10%] w-[50%] h-[50%] bg-slate-500/10 rounded-full blur-[120px] opacity-40 animate-pulse"></div>
<div className="absolute bottom-[-10%] right-[-5%] w-[40%] h-[40%] bg-white/5 rounded-full blur-[100px] opacity-30"></div>
<div className="absolute top-[30%] right-[20%] w-[30%] h-[30%] bg-gray-500/10 rounded-full blur-[80px] opacity-20"></div>
</div>
<Sidebar
workspaces={workspaces}
activeDocId={activeDocId}
onSelectDoc={handleSelectDoc}
onCreateDoc={(folderId) => handleCreateDocument(folderId)}
onDeleteDoc={async (docId) => {
await moveToTrash(docId);
if (activeDocId === docId) {
setActiveDocId('');
setCurrentView('dashboard');
}
}}
onNavigate={(view) => setCurrentView(view as ViewType)}
onOpenSearch={() => setIsSearchOpen(true)}
currentView={currentView}
onStartTour={startTour}
onDuplicateDoc={handleDuplicateDoc}
onRenameDoc={handleRenameDoc}
/>
<main className="flex-1 bg-white rounded-2xl shadow-xl overflow-hidden relative border border-slate-800/50">
{renderContent()}
</main>
<SearchModal
isOpen={isSearchOpen}
onClose={() => setIsSearchOpen(false)}
workspaces={workspaces}
onSelect={handleSelectDoc}
/>
</div>
);
};
// Wrap with AuthProvider
const App: React.FC = () => {
return (
<AuthProvider>
<DialogProvider>
<AppContent />
</DialogProvider>
</AuthProvider>
);
};
export default App;