Link mobile layout

This commit is contained in:
N-Pex 2024-09-09 10:19:36 +02:00
parent 31faf22fd5
commit b621014178
4 changed files with 116 additions and 23 deletions

View file

@ -1,9 +1,29 @@
"use client"; "use client";
import { FC, PropsWithChildren, useState } from "react"; import { FC, PropsWithChildren, useEffect, useState } from "react";
import { Grid, Box } from "@mui/material";
import { Sidebar } from "./Sidebar";
import { SetupModeWarning } from "./SetupModeWarning"; import { SetupModeWarning } from "./SetupModeWarning";
import {
AppBar as MuiAppBar,
ToolbarProps,
Box,
Grid,
IconButton,
styled,
Toolbar,
Typography,
Menu,
useTheme,
useMediaQuery,
} from "@mui/material";
import { Sidebar } from "./Sidebar";
import {
ExpandCircleDown,
MenuBookTwoTone,
MenuSharp,
} from "@mui/icons-material";
import { fonts } from "@link-stack/ui";
import Image from "next/image";
import LinkLogo from "public/link-logo-small.png";
interface InternalLayoutProps extends PropsWithChildren { interface InternalLayoutProps extends PropsWithChildren {
setupModeActive: boolean; setupModeActive: boolean;
@ -15,20 +35,93 @@ export const InternalLayout: FC<InternalLayoutProps> = ({
setupModeActive, setupModeActive,
leafcutterEnabled, leafcutterEnabled,
}) => { }) => {
const [open, setOpen] = useState(true); const { poppins } = fonts;
const theme = useTheme();
const mobile = useMediaQuery(theme.breakpoints.down("sm"));
const [open, setOpen] = useState(false);
const [openWidth, setOpenWidth] = useState<number>(0);
const [closedWidth, setClosedWidth] = useState<number>(0);
useEffect(() => {
setClosedWidth(mobile ? 0 : 70);
setOpenWidth(270);
setOpen(!mobile);
}, [mobile]);
interface HeaderBarProps extends ToolbarProps {
open?: boolean;
}
const HeaderBar = styled(Toolbar, {
shouldForwardProp: (prop) => prop !== "open",
})<HeaderBarProps>(({ theme, open }) => ({
backgroundColor: "#25272A",
width: "100%",
height: "56px",
}));
return ( return (
<Box sx={{ position: "relative" }}> <Box sx={{ position: "relative" }}>
<SetupModeWarning setupModeActive={setupModeActive} /> <SetupModeWarning setupModeActive={setupModeActive} />
<Grid container direction="row"> <Grid container direction="row">
{mobile ? (<MuiAppBar>
<HeaderBar>
<IconButton
sx={{ color: "white" }}
aria-label="open drawer"
onClick={() => setOpen(true)}
>
<MenuSharp />
</IconButton>
<Typography
variant="h2"
sx={{
fontSize: 26,
color: "white",
fontWeight: 700,
fontFamily: poppins.style.fontFamily,
flexGrow: 1,
}}
>
CDR Link
</Typography>
<Box
sx={{
width: "40px",
height: "40px",
margin: open ? "0" : "0 auto",
}}
>
<Image
src={LinkLogo}
alt="Link logo"
width={40}
height={40}
style={{
objectFit: "cover",
filter: "grayscale(100) brightness(100)",
}}
/>
</Box>
</HeaderBar>
</MuiAppBar>) : (null)}
<Sidebar <Sidebar
open={open} open={open}
setOpen={setOpen} setOpen={setOpen}
leafcutterEnabled={leafcutterEnabled} openWidth={openWidth}
closedWidth={closedWidth}
/> />
<Grid <Grid
item item
sx={{ ml: open ? "270px" : "70px", width: "100%", height: "100vh" }} sx={{
mt: { xs: "56px", sm: "0" },
ml: { xs: open ? "270px" : "0px", sm: open ? "270px" : "70px" },
width: "100%",
height: { xs: "calc(100vh - 56px)", sm: "100vh" },
position: "relative",
}}
> >
{children as any} {children as any}
</Grid> </Grid>

View file

@ -12,6 +12,8 @@ import {
ListItemSecondaryAction, ListItemSecondaryAction,
Drawer, Drawer,
Collapse, Collapse,
useTheme,
useMediaQuery,
} from "@mui/material"; } from "@mui/material";
import { import {
FeaturedPlayList as FeaturedPlayListIcon, FeaturedPlayList as FeaturedPlayListIcon,
@ -35,9 +37,6 @@ import { getOverviewTicketCountsAction } from "app/_actions/overviews";
import { SearchBox } from "./SearchBox"; import { SearchBox } from "./SearchBox";
import { fonts } from "@link-stack/ui"; import { fonts } from "@link-stack/ui";
const openWidth = 270;
const closedWidth = 70;
const MenuItem = ({ const MenuItem = ({
name, name,
href, href,
@ -178,14 +177,12 @@ const MenuItem = ({
interface SidebarProps { interface SidebarProps {
open: boolean; open: boolean;
setOpen: (open: boolean) => void; setOpen: (open: boolean) => void;
openWidth: number;
closedWidth: number;
leafcutterEnabled?: boolean; leafcutterEnabled?: boolean;
} }
export const Sidebar: FC<SidebarProps> = ({ export const Sidebar: FC<SidebarProps> = ({ open, setOpen, openWidth, closedWidth, leafcutterEnabled = false }) => {
open,
setOpen,
leafcutterEnabled = false,
}) => {
const pathname = usePathname(); const pathname = usePathname();
const { data: session } = useSession(); const { data: session } = useSession();
const [overviewCounts, setOverviewCounts] = useState<any>(null); const [overviewCounts, setOverviewCounts] = useState<any>(null);
@ -207,6 +204,9 @@ export const Sidebar: FC<SidebarProps> = ({
return () => clearInterval(interval); return () => clearInterval(interval);
}, []); }, []);
const theme = useTheme();
const mobile = useMediaQuery(theme.breakpoints.down('sm'));
const logout = () => { const logout = () => {
signOut({ callbackUrl: "/login" }); signOut({ callbackUrl: "/login" });
}; };
@ -214,14 +214,15 @@ export const Sidebar: FC<SidebarProps> = ({
return ( return (
<Drawer <Drawer
sx={{ width: open ? openWidth : closedWidth, flexShrink: 0 }} sx={{ width: open ? openWidth : closedWidth, flexShrink: 0 }}
variant="permanent" variant={mobile ? "temporary" : "permanent"}
anchor="left" anchor="left"
open={open} open={open}
onClose={() => {if (mobile) setOpen(false)}}
PaperProps={{ PaperProps={{
sx: { sx: {
width: open ? openWidth : closedWidth, width: open ? openWidth : closedWidth,
border: 0, border: 0,
overflow: "visible", overflow: open ? "visible" : "hidden",
}, },
}} }}
> >

View file

@ -12,11 +12,11 @@ type LayoutProps = {
export default function Layout({ detail, edit, params: { id } }: LayoutProps) { export default function Layout({ detail, edit, params: { id } }: LayoutProps) {
return ( return (
<Grid container spacing={0} sx={{ height: "100vh" }} direction="row"> <Grid container spacing={0} sx={{ height: "100%" }} direction="row">
<Grid item sx={{ height: "100vh" }} xs={9}> <Grid item sx={{ height: "100%" }} xs={9}>
{detail} {detail}
</Grid> </Grid>
<Grid item xs={3} sx={{ height: "100vh" }}> <Grid item xs={3} sx={{ height: "100%" }}>
{edit} {edit}
</Grid> </Grid>
</Grid> </Grid>

View file

@ -36,8 +36,8 @@ export const List: FC<ListProps> = ({
}; };
return ( return (
<Box sx={{ height: "100vh", backgroundColor: lightGray, p: 3 }}> <Box sx={{ height: "100%", p: 3 }}>
<Grid container direction="column"> <Grid container direction="column" sx={{ height: "100%", flexWrap: "nowrap" }}>
<Grid <Grid
item item
container container
@ -52,14 +52,13 @@ export const List: FC<ListProps> = ({
{buttons} {buttons}
</Grid> </Grid>
</Grid> </Grid>
<Grid item> <Grid item sx={{flexGrow: 1}}>
<Box <Box
sx={{ sx={{
mt: 2, mt: 2,
backgroundColor: "transparent", backgroundColor: "transparent",
border: 0, border: 0,
width: "100%", width: "100%",
height: "calc(100vh - 100px)",
".MuiDataGrid-row": { ".MuiDataGrid-row": {
cursor: "pointer", cursor: "pointer",
"&:hover": { "&:hover": {