-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.tsx
More file actions
179 lines (156 loc) · 5.49 KB
/
Copy pathApp.tsx
File metadata and controls
179 lines (156 loc) · 5.49 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
import React, { useEffect, useState } from 'react';
import { Analytics } from '@vercel/analytics/react';
import { SpeedInsights } from '@vercel/speed-insights/react';
import { Heart } from 'lucide-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';
type BootSplashState = 'visible' | 'hiding' | 'hidden';
const BOOT_SPLASH_VISIBLE_MS = 880;
const BOOT_SPLASH_FADE_MS = 360;
const StartupTransition: React.FC<{ state: Exclude<BootSplashState, 'hidden'> }> = ({ state }) => (
<div
className={`startup-overlay ${state === 'hiding' ? 'startup-overlay-exit' : 'startup-overlay-enter'}`}
aria-hidden="true"
>
<div className="startup-bloom startup-bloom-left" />
<div className="startup-bloom startup-bloom-right" />
<div className="startup-content">
<div className="startup-emblem-wrap">
<div className="startup-emblem-ring" />
<div className="startup-emblem-core">
<Heart className="startup-heart-icon" />
</div>
</div>
<p className="startup-title">GIFTS</p>
<p className="startup-subtitle">正在进入你们的小世界...</p>
<div className="startup-progress" aria-hidden="true">
<span />
<span />
<span />
</div>
</div>
</div>
);
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 = () => {
const [bootSplashState, setBootSplashState] = useState<BootSplashState>('visible');
useEffect(() => {
cleanupLegacyLocalDataOnce();
syncTime();
const interval = setInterval(() => syncTime(), 10 * 60 * 1000);
return () => clearInterval(interval);
}, []);
useEffect(() => {
const prefersReducedMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
const visibleMs = prefersReducedMotion ? 280 : BOOT_SPLASH_VISIBLE_MS;
const fadeMs = prefersReducedMotion ? 140 : BOOT_SPLASH_FADE_MS;
const fadeTimer = window.setTimeout(() => {
setBootSplashState('hiding');
}, visibleMs);
const hideTimer = window.setTimeout(() => {
setBootSplashState('hidden');
}, visibleMs + fadeMs);
return () => {
window.clearTimeout(fadeTimer);
window.clearTimeout(hideTimer);
};
}, []);
return (
<ErrorBoundary>
<AppProvider>
<AuthProvider>
<ToastProvider>
<AppContent />
{bootSplashState !== 'hidden' && <StartupTransition state={bootSplashState} />}
<Analytics />
<SpeedInsights />
</ToastProvider>
</AuthProvider>
</AppProvider>
</ErrorBoundary>
);
};
export default App;