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 { UpdateProfile } from '@/components/auth';
import { BottomNav } from '@/components/navigation'; import { BottomNav } from '@/components/navigation';
import { EmptyProvider } from '@/providers/empty';
import { TelegramProvider } from '@/providers/telegram'; import { TelegramProvider } from '@/providers/telegram';
import { isTMA } from '@telegram-apps/sdk-react';
import { type PropsWithChildren } from '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 ( return (
<TelegramProvider> <Provider>
<UpdateProfile /> <UpdateProfile />
<main className="grow">{children}</main> <main className="grow">{children}</main>
<BottomNav /> <BottomNav />
</TelegramProvider> </Provider>
); );
} }

View File

@ -1,11 +1,21 @@
'use client'; '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 }; type Props = { title: string | undefined };
export function PageHeader(props: Readonly<Props>) { export function PageHeader(props: Readonly<Props>) {
const isTG = isTMA('simple');
return ( 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"> <div
{/* <BackButton /> */} 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} {props.title}
</div> </div>
); );

View File

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

View File

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