Files
bedolaga-cabinet/src/platform/PlatformProvider.tsx
c0mrade edb5be09ae feat: migrate to @tma.js/sdk-react for Telegram Mini App
- Add useTelegramSDK hook with reactive signals for viewport, safe area, fullscreen
- Migrate TelegramAdapter to use SDK components (backButton, mainButton, hapticFeedback, cloudStorage, themeParams, popup)
- Update Login, TelegramRedirect to use SDK helpers
- Update PlatformProvider, api/client to use centralized SDK functions
- Simplify useTelegramWebApp as backward-compatible wrapper
- Add automatic CSS variable binding for theme and viewport
2026-02-01 20:13:50 +03:00

36 lines
1.1 KiB
TypeScript

import { useMemo, type ReactNode } from 'react';
import { PlatformContext } from '@/platform/PlatformContext';
import { createTelegramAdapter } from '@/platform/adapters/TelegramAdapter';
import { createWebAdapter } from '@/platform/adapters/WebAdapter';
import { isInTelegramWebApp } from '@/hooks/useTelegramSDK';
import type { PlatformContext as PlatformContextType } from '@/platform/types';
interface PlatformProviderProps {
children: ReactNode;
}
function detectPlatform(): 'telegram' | 'web' {
return isInTelegramWebApp() ? 'telegram' : 'web';
}
function createAdapter(): PlatformContextType {
const platform = detectPlatform();
if (platform === 'telegram') {
return createTelegramAdapter();
}
return createWebAdapter();
}
export function PlatformProvider({ children }: PlatformProviderProps) {
// Create adapter once on mount
// Using useMemo to ensure stable reference
const platformContext = useMemo(() => createAdapter(), []);
return <PlatformContext.Provider value={platformContext}>{children}</PlatformContext.Provider>;
}
// Re-export types for convenience
export type { PlatformContextType as PlatformContext };