Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Simplified the page header on mobile #20

Merged
merged 1 commit into from
Nov 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 45 additions & 19 deletions src/components/PageHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.

'use client';

import { AppBar, Box, Stack, Toolbar, Typography } from '@mui/material';
import { AppBar, Stack, Toolbar, Typography, useMediaQuery, useTheme } from '@mui/material';
import { useFormatter } from 'next-intl';

interface PageHeaderProps {
Expand All @@ -29,27 +29,53 @@ interface PageHeaderProps {
}

export default function PageHeader(props: PageHeaderProps) {
const format = useFormatter();
const theme = useTheme();
const isMobile = useMediaQuery(theme.breakpoints.down('sm'));

return (
<AppBar>
<Toolbar>
<Stack>
<Typography variant="h6" component="div">
{props.stationLocationName}
</Typography>
<Typography variant="caption">{props.stationCoordinates}</Typography>
</Stack>

<Box flexGrow={1} />

<Stack textAlign="end">
<Typography variant="h6">{props.pageTitle}</Typography>
<Typography variant="caption">
{format.dateTime(props.observationDate, { dateStyle: 'medium', timeStyle: 'medium' })}
</Typography>
</Stack>
</Toolbar>
<Toolbar>{isMobile ? <CompactPageHeader {...props} /> : <RegularPageHeader {...props} />}</Toolbar>
</AppBar>
);
}

function CompactPageHeader(props: PageHeaderProps) {
const format = useFormatter();

return (
<Stack textAlign="center" sx={{ minWidth: 0, flex: 1 }}>
<Typography variant="h6" component="div" noWrap sx={{ textOverflow: 'ellipsis', overflow: 'hidden' }}>
{props.stationLocationName}
</Typography>
<Typography variant="caption" component="div" noWrap sx={{ textOverflow: 'ellipsis', overflow: 'hidden' }}>
{format.dateTime(props.observationDate, { dateStyle: 'medium', timeStyle: 'medium' })}
</Typography>
</Stack>
);
}

function RegularPageHeader(props: PageHeaderProps) {
const format = useFormatter();

return (
<>
<Stack sx={{ minWidth: 0, flex: 1.25 }}>
<Typography variant="h6" component="div" noWrap sx={{ textOverflow: 'ellipsis', overflow: 'hidden' }}>
{props.stationLocationName}
</Typography>
<Typography variant="caption" component="div" noWrap sx={{ textOverflow: 'ellipsis', overflow: 'hidden' }}>
{props.stationCoordinates}
</Typography>
</Stack>

<Stack textAlign="end" sx={{ minWidth: 0, flex: 1 }}>
<Typography variant="h6" component="div" noWrap sx={{ textOverflow: 'ellipsis', overflow: 'hidden' }}>
{props.pageTitle}
</Typography>
<Typography variant="caption" component="div" noWrap sx={{ textOverflow: 'ellipsis', overflow: 'hidden' }}>
{format.dateTime(props.observationDate, { dateStyle: 'medium', timeStyle: 'medium' })}
</Typography>
</Stack>
</>
);
}