use ui back button for non tma mode

This commit is contained in:
vchikalkin 2025-08-02 15:40:39 +03:00
parent 12686f0712
commit 0bc83446b5
4 changed files with 34 additions and 9 deletions

View File

@ -1,14 +1,22 @@
'use client';
import { UpdateProfile } from '@/components/auth';
import { BottomNav } from '@/components/navigation';
import { EmptyProvider } from '@/providers/empty';
import { TelegramProvider } from '@/providers/telegram';
import { isTMA } from '@telegram-apps/sdk-react';
import { type PropsWithChildren } from 'react';
export default async function Layout({ children }: Readonly<PropsWithChildren>) {
export default function Layout({ children }: Readonly<PropsWithChildren>) {
const isTG = isTMA('simple');
const Provider = isTG ? TelegramProvider : EmptyProvider;
return (
<TelegramProvider>
<Provider>
<UpdateProfile />
<main className="grow">{children}</main>
<BottomNav />
</TelegramProvider>
</Provider>
);
}

View File

@ -1,11 +1,21 @@
'use client';
import { BackButton } from './back-button';
import { cn } from '@repo/ui/lib/utils';
import { isTMA } from '@telegram-apps/sdk-react';
type Props = { title: string | undefined };
export function PageHeader(props: Readonly<Props>) {
const isTG = isTMA('simple');
return (
<div className="sticky top-0 z-50 flex h-12 items-center rounded-b-lg bg-transparent px-4 font-bold tracking-wide backdrop-blur-md">
{/* <BackButton /> */}
<div
className={cn(
'sticky top-0 z-50 flex h-12 items-center rounded-b-lg bg-transparent font-bold tracking-wide backdrop-blur-md',
isTG ? 'px-4' : 'px-2',
)}
>
{!isTG && <BackButton />}
{props.title}
</div>
);

View File

@ -21,10 +21,12 @@ export function useBackButton() {
}, [onBackClick]);
useEffect(() => {
if (isRootLevelPage(pathname)) {
backButton.hide();
} else {
backButton.show();
if (backButton.isMounted()) {
if (isRootLevelPage(pathname)) {
backButton.hide();
} else {
backButton.show();
}
}
}, [pathname]);
}

View File

@ -0,0 +1,5 @@
import { type PropsWithChildren } from 'react';
export function EmptyProvider({ children }: Readonly<PropsWithChildren>) {
return <>{children}</>;
}