Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 290 291 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 2x 2x 2x 6x 6x 6x 6x 1x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 1x | import { CacheInitializer } from '@common/components/CacheInitializer';
import { Layout } from '@common/components/layout';
import { ProtectedRoute } from '@common/components/ProtectedRoute';
import { useAuth } from '@common/contexts/AuthContext';
import { FilterProvider } from '@common/contexts/FilterContext';
import { ToastProvider } from '@common/contexts/ToastContext';
import { useLogger, useLoggerStatic } from '@common/utils/logger/useLogger';
import { ExclamationTriangleIcon } from '@heroicons/react/24/outline';
import ErrorBoundary from '@web/components/ErrorBoundary';
import React, { Suspense, lazy, useEffect } from 'react';
import { Toaster } from 'react-hot-toast';
import { Navigate, Route, Routes, useLocation, useNavigate } from 'react-router-dom';
// Lazy load page components
const InboxPage = lazy(() => import('@web/pages/Inbox'));
const NewsletterDetailPage = lazy(() => import('@web/pages/NewsletterDetail'));
const NewsletterGroupsPage = lazy(() => import('@web/pages/NewsletterGroupsPage'));
const TrendingTopicsPage = lazy(() => import('@web/pages/TrendingTopics'));
const SearchPage = lazy(() => import('@web/pages/Search'));
const TagsPage = lazy(() => import('@web/pages/TagsPage'));
const ReadingQueuePage = lazy(() => import('@web/pages/ReadingQueuePage'));
const SettingsPage = lazy(() => import('@web/pages/Settings'));
const ProfilePage = lazy(() => import('@web/pages/ProfilePage'));
const LoginPage = lazy(() => import('@web/pages/Login'));
const ForgotPasswordPage = lazy(() => import('@web/pages/ForgotPassword'));
const ResetPasswordPage = lazy(() => import('@web/pages/ResetPassword'));
const DailySummary = lazy(() => import('@web/pages/DailySummary'));
// Loading component
const LoadingFallback = () => (
<div className="flex items-center justify-center min-h-screen bg-gray-50">
<div className="animate-spin rounded-full h-12 w-12 border-t-2 border-b-2 border-blue-500"></div>
</div>
);
// A custom hook that builds on useLocation to parse the query string
function useQuery() {
const { search } = useLocation();
return React.useMemo(() => new URLSearchParams(search), [search]);
}
const App: React.FC = () => {
const { user, loading } = useAuth();
const location = useLocation();
const navigate = useNavigate();
const query = useQuery();
const redirectTo = query.get('redirectTo');
const log = useLogger('App');
const staticLog = useLoggerStatic();
// Log navigation changes
useEffect(() => {
staticLog.logNavigation(
document.referrer ? new URL(document.referrer).pathname : 'external',
location.pathname,
{
metadata: {
search: location.search,
hash: location.hash,
timestamp: new Date().toISOString(),
},
}
);
}, [location, staticLog]);
// Handle redirect after login
React.useEffect(() => {
if (user && (location.pathname === '/login' || location.pathname === '/')) {
const destination = redirectTo || '/inbox';
log.info('Redirecting authenticated user', {
action: 'auth_redirect',
metadata: {
from: location.pathname,
to: destination,
userId: user.id,
},
});
navigate(destination, { replace: true });
}
}, [user, location, navigate, redirectTo, log]);
// Log app initialization
useEffect(() => {
log.info('App initialized', {
action: 'app_init',
metadata: {
pathname: location.pathname,
userAgent: navigator.userAgent,
viewport: `${window.innerWidth}x${window.innerHeight}`,
authenticated: !!user,
},
});
}, []);
if (loading) {
log.debug('App loading - showing loading fallback', {
action: 'app_loading',
});
return <LoadingFallback />;
}
// Custom error fallback component
const errorFallback = (
<div className="min-h-screen flex items-center justify-center bg-gray-50 px-4">
<div className="text-center">
<ExclamationTriangleIcon className="mx-auto h-12 w-12 text-red-500" />
<h3 className="mt-2 text-lg font-medium text-gray-900">Oops! Something went wrong</h3>
<p className="mt-1 text-sm text-gray-500">
We're having trouble loading the application. Please try refreshing the page.
</p>
<div className="mt-6">
<button
onClick={() => {
log.logUserAction('app_error_refresh', {
metadata: {
pathname: location.pathname,
timestamp: new Date().toISOString(),
},
});
window.location.reload();
}}
className="inline-flex items-center px-4 py-2 border border-transparent text-sm font-medium rounded-md shadow-sm text-white bg-blue-600 hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500"
>
Refresh Page
</button>
</div>
</div>
</div>
);
return (
<ErrorBoundary fallback={errorFallback}>
<ToastProvider>
<FilterProvider useLocalTagFiltering={false}>
<CacheInitializer>
<div className="min-h-screen bg-gray-50">
{import.meta.env.MODE !== 'production' && (
<Toaster
position="bottom-right"
toastOptions={{
duration: 5000,
style: {
background: '#fff',
color: '#1f2937',
boxShadow:
'0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06)',
borderRadius: '0.5rem',
padding: '0.75rem 1rem',
fontSize: '0.875rem',
},
success: {
iconTheme: {
primary: '#10B981',
secondary: '#fff',
},
},
error: {
iconTheme: {
primary: '#EF4444',
secondary: '#fff',
},
},
}}
/>
)}
<Layout>
<Suspense fallback={<LoadingFallback />}>
<Routes>
{/* Redirect root to login or inbox based on auth status */}
<Route
path="/"
element={
user ? (
<Navigate to="/inbox" replace />
) : (
<Navigate to="/login" state={{ from: location }} replace />
)
}
/>
{/* Public routes */}
<Route path="/login" element={<LoginPage />} />
<Route path="/forgot-password" element={<ForgotPasswordPage />} />
<Route path="/reset-password" element={<ResetPasswordPage />} />
{/* Protected routes */}
<Route
path="/inbox"
element={
<ProtectedRoute>
<InboxPage />
</ProtectedRoute>
}
/>
<Route
path="/newsletters"
element={
<ProtectedRoute>
<NewsletterGroupsPage />
</ProtectedRoute>
}
/>
<Route
path="/newsletters/:id"
element={
<ProtectedRoute>
<NewsletterDetailPage />
</ProtectedRoute>
}
/>
<Route
path="/trending"
element={
<ProtectedRoute>
<TrendingTopicsPage />
</ProtectedRoute>
}
/>
<Route
path="/search"
element={
<ProtectedRoute>
<SearchPage />
</ProtectedRoute>
}
/>
<Route
path="/tags"
element={
<ProtectedRoute>
<TagsPage />
</ProtectedRoute>
}
/>
<Route
path="/queue"
element={
<ProtectedRoute>
<ReadingQueuePage />
</ProtectedRoute>
}
/>
<Route
path="/settings"
element={
<ProtectedRoute>
<SettingsPage />
</ProtectedRoute>
}
/>
<Route
path="/profile"
element={
<ProtectedRoute>
<ProfilePage />
</ProtectedRoute>
}
/>
<Route
path="/daily"
element={
<ProtectedRoute>
<DailySummary />
</ProtectedRoute>
}
/>
{/* 404 route - keep this last */}
<Route
path="*"
element={
<Navigate
to={user ? '/inbox' : '/login'}
state={{ from: location }}
replace
/>
}
/>
</Routes>
</Suspense>
</Layout>
</div>
</CacheInitializer>
</FilterProvider>
</ToastProvider>
</ErrorBoundary>
);
};
export default App;
|