veza/apps/web/src/components/ui/LazyComponent.tsx

94 lines
3 KiB
TypeScript
Raw Normal View History

import { Suspense, lazy, type ComponentType } from 'react';
import { LoadingSpinner } from './loading-spinner';
interface LazyComponentProps {
fallback?: React.ReactNode;
}
export function createLazyComponent<T extends ComponentType<any>>(
importFunc: () => Promise<{ default: T }>,
2025-12-13 02:34:34 +00:00
fallback?: React.ReactNode,
) {
const LazyComponent = lazy(importFunc);
return function WrappedLazyComponent(
2025-12-13 02:34:34 +00:00
props: React.ComponentProps<T> & LazyComponentProps,
) {
return (
<Suspense fallback={fallback || <LoadingSpinner />}>
<LazyComponent {...props} />
</Suspense>
);
};
}
// Composants lazy communs
2025-12-13 02:34:34 +00:00
export const LazyDashboard = createLazyComponent(() =>
import('@/pages/DashboardPage').then((m) => ({ default: m.DashboardPage })),
);
2025-12-17 13:07:35 +00:00
export const LazyChat = createLazyComponent(() =>
import('@/features/chat/pages/ChatPage').then((m) => ({
default: m.ChatPage,
})),
);
export const LazyLibrary = createLazyComponent(
2025-12-13 02:34:34 +00:00
() => import('@/features/library/pages/LibraryPage'),
);
2025-12-13 02:34:34 +00:00
export const LazyProfile = createLazyComponent(() =>
import('@/pages/ProfilePage').then((m) => ({ default: m.ProfilePage })),
);
2025-12-17 13:07:35 +00:00
export const LazySettings = createLazyComponent(() =>
import('@/features/settings/pages/SettingsPage').then((m) => ({
default: m.SettingsPage,
})),
);
2025-12-13 02:34:34 +00:00
export const LazyLogin = createLazyComponent(() =>
import('@/pages/LoginPage').then((m) => ({ default: m.LoginPage })),
);
2025-12-13 02:34:34 +00:00
export const LazyRegister = createLazyComponent(() =>
import('@/pages/RegisterPage').then((m) => ({ default: m.RegisterPage })),
);
export const LazyForgotPassword = createLazyComponent(
2025-12-13 02:34:34 +00:00
() => import('@/features/auth/pages/ForgotPasswordPage'),
);
export const LazyVerifyEmail = createLazyComponent(
2025-12-13 02:34:34 +00:00
() => import('@/features/auth/pages/VerifyEmailPage'),
);
export const LazyResetPassword = createLazyComponent(
2025-12-13 02:34:34 +00:00
() => import('@/features/auth/pages/ResetPasswordPage'),
);
export const LazySessions = createLazyComponent(
2025-12-13 02:34:34 +00:00
() => import('@/features/auth/pages/SessionsPage'),
);
export const LazyNotFound = createLazyComponent(
2025-12-13 02:34:34 +00:00
() => import('@/features/error/pages/NotFoundPage'),
);
export const LazyServerError = createLazyComponent(
2025-12-13 02:34:34 +00:00
() => import('@/features/error/pages/ServerErrorPage'),
);
2025-12-13 02:34:34 +00:00
export const LazyUserProfile = createLazyComponent(() =>
import('@/features/profile/pages/UserProfilePage').then((m) => ({
default: m.UserProfilePage,
})),
);
2025-12-13 02:34:34 +00:00
export const LazyRoles = createLazyComponent(() =>
import('@/features/roles/pages/RolesPage').then((m) => ({
default: m.RolesPage,
})),
);
2025-12-13 02:34:34 +00:00
export const LazyTrackDetail = createLazyComponent(() =>
import('@/features/tracks/pages/TrackDetailPage').then((m) => ({
default: m.TrackDetailPage,
})),
);
2025-12-13 02:34:34 +00:00
export const LazyPlaylistRoutes = createLazyComponent(() =>
import('@/features/playlists/routes').then((m) => ({
default: m.PlaylistRoutes,
})),
);
2025-12-17 13:07:35 +00:00
export const LazyMarketplace = createLazyComponent(() =>
import('@/pages/marketplace/MarketplaceHome').then((m) => ({
default: m.MarketplaceHome,
})),
);