remove navigation context

This commit is contained in:
vchikalkin 2025-01-27 14:44:19 +03:00
parent 2a9470e4ce
commit 22022fb480
9 changed files with 17 additions and 53 deletions

View File

@ -1,12 +1,12 @@
import { ContactsList } from '@/components/contacts/contacts-list';
import { ContactsFilter } from '@/components/contacts/dropdown-filter';
import { NavigationMeta } from '@/components/navigation';
import { PageHeader } from '@/components/navigation';
import { ContactsFilterProvider } from '@/context/contacts-filter';
export default function ContactsPage() {
return (
<ContactsFilterProvider>
<NavigationMeta title="Контакты" />
<PageHeader title="Контакты" />
<div className="sticky top-0 z-50 flex flex-row items-center justify-between space-x-4 bg-background p-4">
<div />
<ContactsFilter />

View File

@ -1,13 +1,11 @@
import { BottomNav, PageHeader } from '@/components/navigation';
import { NavigationProvider } from '@/context/navigation';
import { BottomNav } from '@/components/navigation';
import { type PropsWithChildren } from 'react';
export default async function Layout({ children }: Readonly<PropsWithChildren>) {
return (
<NavigationProvider>
<PageHeader />
<>
<main>{children}</main>
<BottomNav />
</NavigationProvider>
</>
);
}

View File

@ -1,12 +1,9 @@
import { getProfile } from '@/actions/profile';
import { PageHeader } from '@/components/navigation';
import { ProfileCard } from '@/components/profile/profile-card';
import { dehydrate, HydrationBoundary, QueryClient } from '@tanstack/react-query';
type Props = {
params: Promise<{
telegramId: string;
}>;
};
type Props = { params: Promise<{ telegramId: string }> };
export default async function ProfilePage(props: Readonly<Props>) {
const parameters = await props.params;
@ -21,6 +18,7 @@ export default async function ProfilePage(props: Readonly<Props>) {
return (
<HydrationBoundary state={dehydrate(queryClient)}>
<PageHeader title="Профиль контакта" />
<ProfileCard telegramId={telegramId} />
</HydrationBoundary>
);

View File

@ -1,5 +1,5 @@
import { getProfile } from '@/actions/profile';
import { NavigationMeta } from '@/components/navigation/meta';
import { PageHeader } from '@/components/navigation';
import { ProfileCard } from '@/components/profile/profile-card';
import { dehydrate, HydrationBoundary, QueryClient } from '@tanstack/react-query';
@ -13,7 +13,7 @@ export default async function ProfilePage() {
return (
<HydrationBoundary state={dehydrate(queryClient)}>
<NavigationMeta title="Профиль" />
<PageHeader title="Профиль" />
<ProfileCard />
</HydrationBoundary>
);

View File

@ -2,11 +2,13 @@
import { BackButton } from './back-button';
import { PageTitle } from './page-title';
export function PageHeader() {
type Props = { title: string | undefined };
export function PageHeader(props: Readonly<Props>) {
return (
<div className="sticky top-0 z-50 flex items-center bg-background p-2">
<BackButton />
<PageTitle />
<PageTitle title={props.title} />
</div>
);
}

View File

@ -1,8 +1,5 @@
import { NavigationContext } from '@/context/navigation';
import { use } from 'react';
type Props = { readonly title: string | undefined };
export function PageTitle() {
const context = use(NavigationContext);
return <span className="h-8 text-lg font-bold tracking-wide">{context?.title}</span>;
export function PageTitle(props: Readonly<Props>) {
return <span className="h-8 text-lg font-bold tracking-wide">{props?.title}</span>;
}

View File

@ -1,3 +1,2 @@
export * from './header';
export * from './meta';
export * from './navbar';

View File

@ -1,13 +0,0 @@
'use client';
import { NavigationContext } from '@/context/navigation';
import { use, useEffect } from 'react';
export function NavigationMeta(props: Readonly<{ title: string }>) {
const navigation = use(NavigationContext);
useEffect(() => {
navigation?.setTitle(props.title);
}, [navigation, props.title]);
return false;
}

View File

@ -1,17 +0,0 @@
'use client';
import { createContext, type PropsWithChildren, useMemo, useState } from 'react';
type ContextType = {
setTitle: (title: null | string) => void;
title: null | string;
};
export const NavigationContext = createContext<ContextType | null>(null);
export function NavigationProvider({ children }: Readonly<PropsWithChildren>) {
const [title, setTitle] = useState<null | string>(null);
const value = useMemo(() => ({ setTitle, title }), [setTitle, title]);
return <NavigationContext value={value}>{children}</NavigationContext>;
}