vchikalkin 458a06a620 Refactor async components to synchronous functions for improved performance
- Converted several async components to synchronous functions, including `Layout`, `AddOrdersPage`, `ProfilePage`, `SlotPage`, and `ServicePage`, enhancing rendering efficiency.
- Removed unnecessary prefetching logic and hydration boundaries, simplifying component structure and improving maintainability.
- Updated the `TelegramProvider` to return null during the initial mount instead of a loading message, streamlining the loading state handling.
- Enhanced loading state management in order-related components by adding loading spinners and data not found alerts, improving user experience during data fetching.
2025-10-07 13:28:40 +03:00

43 lines
1.2 KiB
TypeScript

/* eslint-disable sonarjs/function-return-type */
'use client';
import { useBackButton, useClientOnce, useDidMount, useViewport } from '@/hooks/telegram';
import { setLocale } from '@/utils/i18n/locale';
import { init } from '@/utils/telegram/init';
import { initData, useSignal } from '@telegram-apps/sdk-react';
import { type PropsWithChildren, useEffect } from 'react';
export function TelegramProvider(props: Readonly<PropsWithChildren>) {
// Unfortunately, Telegram Mini Apps does not allow us to use all features of
// the Server Side Rendering. That's why we are showing loader on the server
// side.
const didMount = useDidMount();
if (!didMount) return null;
return <RootInner {...props} />;
}
function RootInner({ children }: PropsWithChildren) {
const isDevelopment = process.env.NODE_ENV === 'development';
const debug = isDevelopment;
// Initialize the library.
useClientOnce(() => {
init(debug);
});
useViewport();
useBackButton();
const initDataUser = useSignal(initData.user);
// Set the user locale.
useEffect(() => {
if (initDataUser) setLocale(initDataUser.languageCode);
}, [initDataUser]);
return children;
}