From f6104f6e7236666358a905fc593ba6a154045639 Mon Sep 17 00:00:00 2001 From: Pavel Kirilin Date: Fri, 29 Mar 2024 21:58:27 +0300 Subject: [PATCH] Use separate subheader for PageDetailHeader --- .../features/pages/ui/PageDetailHeader.tsx | 38 ++++---------- src/frontend/src/pages/ui/PageDetailPage.tsx | 3 +- src/frontend/src/shared/constants.ts | 3 +- src/frontend/src/shared/ui/AppShell.tsx | 50 ++++++++++++++++--- .../src/widgets/layout/ui/PrivateLayout.tsx | 24 +++++---- .../src/widgets/navbar/ui/MobileMenu.tsx | 9 +++- .../src/widgets/navbar/ui/NavigationBar.tsx | 11 ++-- 7 files changed, 81 insertions(+), 57 deletions(-) diff --git a/src/frontend/src/features/pages/ui/PageDetailHeader.tsx b/src/frontend/src/features/pages/ui/PageDetailHeader.tsx index 2435f7210..410f40aaf 100644 --- a/src/frontend/src/features/pages/ui/PageDetailHeader.tsx +++ b/src/frontend/src/features/pages/ui/PageDetailHeader.tsx @@ -1,16 +1,11 @@ import ArrowBackIcon from '@mui/icons-material/ArrowBack'; import { - AppBar, - Box, - Container, IconButton, Stack, - Toolbar, Tooltip, Typography, type TypographyProps, styled, - useScrollTrigger, } from '@mui/material'; import { useMemo, type FC } from 'react'; import { Link as RouterLink } from 'react-router-dom'; @@ -18,8 +13,6 @@ import { notesApi } from 'src/features/notes'; import { formatDate } from 'src/utils'; import { type Page } from '../models'; -const DIVIDER_VISIBLE_SCROLL_THRESHOLD = 16; - interface Props { page: Page; } @@ -35,26 +28,17 @@ export const PageDetailHeader: FC = ({ page }) => { const notes = useMemo(() => getNotesQuery.data ?? [], [getNotesQuery.data]); const totalCalories = useMemo(() => notes.reduce((sum, note) => sum + note.calories, 0), [notes]); - const pageScrolled = useScrollTrigger({ - threshold: DIVIDER_VISIBLE_SCROLL_THRESHOLD, - disableHysteresis: true, - }); - return ( - - - - - - - - - - {formatDate(new Date(page.date))} - {totalCalories} kcal - - - - + <> + + + + + + + {formatDate(new Date(page.date))} + {totalCalories} kcal + + ); }; diff --git a/src/frontend/src/pages/ui/PageDetailPage.tsx b/src/frontend/src/pages/ui/PageDetailPage.tsx index f122a85f2..37f661ad3 100644 --- a/src/frontend/src/pages/ui/PageDetailPage.tsx +++ b/src/frontend/src/pages/ui/PageDetailPage.tsx @@ -30,8 +30,7 @@ export const Component: FC = () => { return ( } > diff --git a/src/frontend/src/shared/constants.ts b/src/frontend/src/shared/constants.ts index 8005c819e..b04abaabb 100644 --- a/src/frontend/src/shared/constants.ts +++ b/src/frontend/src/shared/constants.ts @@ -1,3 +1,4 @@ -export const APP_BAR_HEIGHT = 66; +export const APP_BAR_HEIGHT_XS = 56; +export const APP_BAR_HEIGHT_SM = 64; export const SIDEBAR_DRAWER_WIDTH = 256; diff --git a/src/frontend/src/shared/ui/AppShell.tsx b/src/frontend/src/shared/ui/AppShell.tsx index d38413bea..26a1c49e6 100644 --- a/src/frontend/src/shared/ui/AppShell.tsx +++ b/src/frontend/src/shared/ui/AppShell.tsx @@ -1,41 +1,79 @@ import { AppBar, Box, Container, LinearProgress, Toolbar } from '@mui/material'; import { type PropsWithChildren, type FC, type ReactElement } from 'react'; -import { APP_BAR_HEIGHT, SIDEBAR_DRAWER_WIDTH } from '../constants'; +import { APP_BAR_HEIGHT_SM, APP_BAR_HEIGHT_XS, SIDEBAR_DRAWER_WIDTH } from '../constants'; interface Props extends PropsWithChildren { withNavigationProgress: boolean; - withAdditionalNavigation?: boolean; withSidebar?: boolean; header?: ReactElement; + subheader?: ReactElement; + subheaderElevation?: number; } export const AppShell: FC = ({ children, withNavigationProgress, - withAdditionalNavigation, withSidebar, header, + subheader, + subheaderElevation, }) => ( <> {header && ( - + {header} )} + {subheader && ( + + + + {subheader} + + + + )} {withNavigationProgress && ( )} = ({ children, header, withAdditionalNavigation }) => { +export const PrivateLayout: FC = ({ children, subheader }) => { const navigationProgressVisible = useNavigationProgress(); + const sm = useMediaQuery(theme => theme.breakpoints.down('sm')); const isMobile = useMediaQuery(theme => theme.breakpoints.down('md')); const [menuOpened, toggleMenu] = useToggle(!isMobile); + const pageScrolled = useScrollTrigger({ + threshold: (sm ? APP_BAR_HEIGHT_SM : APP_BAR_HEIGHT_XS) / 2, + disableHysteresis: true, + }); + useAuthStatusCheckEffect(); return ( - - {header} - - } + header={} + subheader={subheader} + subheaderElevation={pageScrolled ? 1 : 0} > {children} diff --git a/src/frontend/src/widgets/navbar/ui/MobileMenu.tsx b/src/frontend/src/widgets/navbar/ui/MobileMenu.tsx index 0a95324ba..e3ae79508 100644 --- a/src/frontend/src/widgets/navbar/ui/MobileMenu.tsx +++ b/src/frontend/src/widgets/navbar/ui/MobileMenu.tsx @@ -13,7 +13,7 @@ import { } from '@mui/material'; import { type FC, useState } from 'react'; import { Link } from 'react-router-dom'; -import { APP_BAR_HEIGHT } from '@/shared/constants'; +import { APP_BAR_HEIGHT_SM } from '@/shared/constants'; import { APP_NAME, NAV_LINKS } from '../lib'; export const MobileMenu: FC = () => { @@ -51,7 +51,12 @@ export const MobileMenu: FC = () => { - + ({ fontSize: theme.typography.h1.fontSize, diff --git a/src/frontend/src/widgets/navbar/ui/NavigationBar.tsx b/src/frontend/src/widgets/navbar/ui/NavigationBar.tsx index 0ea903a65..79f5ba76c 100644 --- a/src/frontend/src/widgets/navbar/ui/NavigationBar.tsx +++ b/src/frontend/src/widgets/navbar/ui/NavigationBar.tsx @@ -14,7 +14,7 @@ import { } from '@mui/material'; import { type FC } from 'react'; import { Form } from 'react-router-dom'; -import { APP_BAR_HEIGHT, SIDEBAR_DRAWER_WIDTH } from '@/shared/constants'; +import { APP_BAR_HEIGHT_SM, SIDEBAR_DRAWER_WIDTH } from '@/shared/constants'; import { APP_NAME } from '../lib'; import { MenuList } from './MenuList'; @@ -59,18 +59,13 @@ export const NavigationBar: FC = ({ menuOpened, toggleMenu }) => { ModalProps={{ keepMounted: isMobile }} PaperProps={{ sx: { - marginTop: { xs: 0, md: `${APP_BAR_HEIGHT}px` }, + marginTop: { xs: 0, md: `${APP_BAR_HEIGHT_SM}px` }, width: { xs: '75%', md: `${SIDEBAR_DRAWER_WIDTH}px` }, }, component: 'nav', }} > - +