-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.tsx
More file actions
123 lines (111 loc) · 3.72 KB
/
Copy pathApp.tsx
File metadata and controls
123 lines (111 loc) · 3.72 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
import React, { useEffect, useState } from 'react';
import { Analytics } from '@vercel/analytics/react';
import { SpeedInsights } from '@vercel/speed-insights/react';
import { Layout } from './components/Layout';
import { BottomNav } from './components/BottomNav';
import { LandingPage } from './pages/Landing';
import { ConnectionPage } from './pages/Connection';
import { TimelinePage } from './pages/Timeline';
import { FocusPage } from './pages/Focus';
import { AnniversaryPage } from './pages/Anniversary';
import { ProfilePage } from './pages/Profile';
import { AuthPage } from './pages/Auth';
import { EditProfilePage } from './pages/EditProfile';
import { View } from './types';
import { AppProvider } from './context';
import { AuthProvider } from './authContext';
import { ErrorBoundary } from './components/ErrorBoundary';
import { ToastProvider } from './components/Toast';
import { syncTime } from './utils/timeService';
import { cleanupLegacyLocalDataOnce } from './utils/cloudStorageCleanup';
const AppContent: React.FC = () => {
const [currentView, setCurrentView] = useState<View>(View.LANDING);
const [transitioning, setTransitioning] = useState(false);
const [displayView, setDisplayView] = useState<View>(View.LANDING);
const navigateTo = (view: View) => {
if (view === currentView) return;
setTransitioning(true);
setTimeout(() => {
setCurrentView(view);
setDisplayView(view);
setTransitioning(false);
}, 80);
};
const renderView = () => {
const viewToRender = displayView;
if (viewToRender === View.LANDING) {
return <LandingPage onEnter={() => navigateTo(View.TIMELINE)} />;
}
if (viewToRender === View.ACCOUNT_SECURITY) {
return <AuthPage onBack={() => navigateTo(View.PROFILE)} />;
}
if (viewToRender === View.EDIT_PROFILE) {
return <EditProfilePage onBack={() => navigateTo(View.PROFILE)} />;
}
switch (viewToRender) {
case View.CONNECTION:
return (
<ConnectionPage
onComplete={() => navigateTo(View.TIMELINE)}
onLogin={() => navigateTo(View.ACCOUNT_SECURITY)}
onBack={() => navigateTo(View.PROFILE)}
/>
);
case View.TIMELINE:
return <TimelinePage />;
case View.FOCUS:
return <FocusPage />;
case View.ANNIVERSARY:
return <AnniversaryPage />;
case View.PROFILE:
return (
<ProfilePage
onNavigateToAuth={() => navigateTo(View.ACCOUNT_SECURITY)}
onEditProfile={() => navigateTo(View.EDIT_PROFILE)}
onManageConnection={() => navigateTo(View.CONNECTION)}
/>
);
default:
return <TimelinePage />;
}
};
const showNav =
currentView !== View.LANDING &&
currentView !== View.CONNECTION &&
currentView !== View.ACCOUNT_SECURITY &&
currentView !== View.EDIT_PROFILE;
return (
<Layout fullScreen={!showNav}>
<div
key={displayView}
className={transitioning ? 'page-transition-exit' : 'page-transition-enter'}
style={{ display: 'contents' }}
>
{renderView()}
</div>
{showNav && <BottomNav currentView={currentView} onChangeView={navigateTo} />}
</Layout>
);
};
const App: React.FC = () => {
useEffect(() => {
cleanupLegacyLocalDataOnce();
syncTime();
const interval = setInterval(() => syncTime(), 10 * 60 * 1000);
return () => clearInterval(interval);
}, []);
return (
<ErrorBoundary>
<AppProvider>
<AuthProvider>
<ToastProvider>
<AppContent />
<Analytics />
<SpeedInsights />
</ToastProvider>
</AuthProvider>
</AppProvider>
</ErrorBoundary>
);
};
export default App;