Simplify dashboard code
This commit is contained in:
@@ -11,7 +11,7 @@ export default function BaseAuthenticatedPage(): React.ReactElement {
|
|||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
|
|
||||||
const [isDesktopNavigationExpanded, setIsDesktopNavigationExpanded] =
|
const [isDesktopNavigationExpanded, setIsDesktopNavigationExpanded] =
|
||||||
React.useState(true);
|
React.useState(false);
|
||||||
const [isMobileNavigationExpanded, setIsMobileNavigationExpanded] =
|
const [isMobileNavigationExpanded, setIsMobileNavigationExpanded] =
|
||||||
React.useState(false);
|
React.useState(false);
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import BarChartIcon from "@mui/icons-material/BarChart";
|
import { mdiBug, mdiForum, mdiKeyVariant, mdiLinkLock } from "@mdi/js";
|
||||||
import LayersIcon from "@mui/icons-material/Layers";
|
import Icon from "@mdi/react";
|
||||||
import PersonIcon from "@mui/icons-material/Person";
|
|
||||||
import Box from "@mui/material/Box";
|
import Box from "@mui/material/Box";
|
||||||
import Drawer from "@mui/material/Drawer";
|
import Drawer from "@mui/material/Drawer";
|
||||||
import List from "@mui/material/List";
|
import List from "@mui/material/List";
|
||||||
@@ -9,7 +8,6 @@ import { useTheme } from "@mui/material/styles";
|
|||||||
import type {} from "@mui/material/themeCssVarsAugmentation";
|
import type {} from "@mui/material/themeCssVarsAugmentation";
|
||||||
import useMediaQuery from "@mui/material/useMediaQuery";
|
import useMediaQuery from "@mui/material/useMediaQuery";
|
||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import { useLocation } from "react-router";
|
|
||||||
import DashboardSidebarContext from "./DashboardSidebarContext";
|
import DashboardSidebarContext from "./DashboardSidebarContext";
|
||||||
import DashboardSidebarDividerItem from "./DashboardSidebarDividerItem";
|
import DashboardSidebarDividerItem from "./DashboardSidebarDividerItem";
|
||||||
import DashboardSidebarPageItem from "./DashboardSidebarPageItem";
|
import DashboardSidebarPageItem from "./DashboardSidebarPageItem";
|
||||||
@@ -38,7 +36,6 @@ export default function DashboardSidebar({
|
|||||||
const isOverMdViewport = useMediaQuery(theme.breakpoints.up("md"));
|
const isOverMdViewport = useMediaQuery(theme.breakpoints.up("md"));
|
||||||
|
|
||||||
const [isFullyExpanded, setIsFullyExpanded] = React.useState(expanded);
|
const [isFullyExpanded, setIsFullyExpanded] = React.useState(expanded);
|
||||||
const [isFullyCollapsed, setIsFullyCollapsed] = React.useState(!expanded);
|
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
if (expanded) {
|
if (expanded) {
|
||||||
@@ -54,20 +51,6 @@ export default function DashboardSidebar({
|
|||||||
return () => {};
|
return () => {};
|
||||||
}, [expanded, theme.transitions.duration.enteringScreen]);
|
}, [expanded, theme.transitions.duration.enteringScreen]);
|
||||||
|
|
||||||
React.useEffect(() => {
|
|
||||||
if (!expanded) {
|
|
||||||
const drawerWidthTransitionTimeout = setTimeout(() => {
|
|
||||||
setIsFullyCollapsed(true);
|
|
||||||
}, theme.transitions.duration.leavingScreen);
|
|
||||||
|
|
||||||
return () => clearTimeout(drawerWidthTransitionTimeout);
|
|
||||||
}
|
|
||||||
|
|
||||||
setIsFullyCollapsed(false);
|
|
||||||
|
|
||||||
return () => {};
|
|
||||||
}, [expanded, theme.transitions.duration.leavingScreen]);
|
|
||||||
|
|
||||||
const mini = !disableCollapsibleSidebar && !expanded;
|
const mini = !disableCollapsibleSidebar && !expanded;
|
||||||
|
|
||||||
const handleSetSidebarExpanded = React.useCallback(
|
const handleSetSidebarExpanded = React.useCallback(
|
||||||
@@ -116,23 +99,25 @@ export default function DashboardSidebar({
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<DashboardSidebarPageItem
|
<DashboardSidebarPageItem
|
||||||
id="employees"
|
title="Messages"
|
||||||
title="Employees"
|
icon={<Icon path={mdiForum} size={"1.5em"} />}
|
||||||
icon={<PersonIcon />}
|
href="/"
|
||||||
href="/employees"
|
|
||||||
/>
|
/>
|
||||||
<DashboardSidebarDividerItem />
|
<DashboardSidebarDividerItem />
|
||||||
<DashboardSidebarPageItem
|
<DashboardSidebarPageItem
|
||||||
id="reports"
|
title="Matrix link"
|
||||||
title="Reports"
|
icon={<Icon path={mdiLinkLock} size={"1.5em"} />}
|
||||||
icon={<BarChartIcon />}
|
href="/matrixlink"
|
||||||
href="/reports"
|
|
||||||
/>
|
/>
|
||||||
<DashboardSidebarPageItem
|
<DashboardSidebarPageItem
|
||||||
id="integrations"
|
title="API tokens"
|
||||||
title="Integrations"
|
icon={<Icon path={mdiKeyVariant} size={"1.5em"} />}
|
||||||
icon={<LayersIcon />}
|
href="/tokens"
|
||||||
href="/integrations"
|
/>
|
||||||
|
<DashboardSidebarPageItem
|
||||||
|
title="WS Debug"
|
||||||
|
icon={<Icon path={mdiBug} size={"1.5em"} />}
|
||||||
|
href="/wsdebug"
|
||||||
/>
|
/>
|
||||||
</List>
|
</List>
|
||||||
</Box>
|
</Box>
|
||||||
@@ -168,16 +153,9 @@ export default function DashboardSidebar({
|
|||||||
onPageItemClick: handlePageItemClick,
|
onPageItemClick: handlePageItemClick,
|
||||||
mini,
|
mini,
|
||||||
fullyExpanded: isFullyExpanded,
|
fullyExpanded: isFullyExpanded,
|
||||||
fullyCollapsed: isFullyCollapsed,
|
|
||||||
hasDrawerTransitions,
|
hasDrawerTransitions,
|
||||||
};
|
};
|
||||||
}, [
|
}, [handlePageItemClick, mini, isFullyExpanded, hasDrawerTransitions]);
|
||||||
handlePageItemClick,
|
|
||||||
mini,
|
|
||||||
isFullyExpanded,
|
|
||||||
isFullyCollapsed,
|
|
||||||
hasDrawerTransitions,
|
|
||||||
]);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DashboardSidebarContext.Provider value={sidebarContextValue}>
|
<DashboardSidebarContext.Provider value={sidebarContextValue}>
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ const DashboardSidebarContext = React.createContext<{
|
|||||||
onPageItemClick: () => void;
|
onPageItemClick: () => void;
|
||||||
mini: boolean;
|
mini: boolean;
|
||||||
fullyExpanded: boolean;
|
fullyExpanded: boolean;
|
||||||
fullyCollapsed: boolean;
|
|
||||||
hasDrawerTransitions: boolean;
|
hasDrawerTransitions: boolean;
|
||||||
} | null>(null);
|
} | null>(null);
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ import DashboardSidebarContext from "./DashboardSidebarContext";
|
|||||||
import { MINI_DRAWER_WIDTH } from "./constants";
|
import { MINI_DRAWER_WIDTH } from "./constants";
|
||||||
|
|
||||||
export interface DashboardSidebarPageItemProps {
|
export interface DashboardSidebarPageItemProps {
|
||||||
id: string;
|
|
||||||
title: string;
|
title: string;
|
||||||
icon?: React.ReactNode;
|
icon?: React.ReactNode;
|
||||||
href: string;
|
href: string;
|
||||||
@@ -21,7 +20,6 @@ export interface DashboardSidebarPageItemProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default function DashboardSidebarPageItem({
|
export default function DashboardSidebarPageItem({
|
||||||
id,
|
|
||||||
title,
|
title,
|
||||||
icon,
|
icon,
|
||||||
href,
|
href,
|
||||||
@@ -40,12 +38,6 @@ export default function DashboardSidebarPageItem({
|
|||||||
fullyExpanded = true,
|
fullyExpanded = true,
|
||||||
} = sidebarContext;
|
} = sidebarContext;
|
||||||
|
|
||||||
const handleClick = React.useCallback(() => {
|
|
||||||
if (onPageItemClick) {
|
|
||||||
onPageItemClick();
|
|
||||||
}
|
|
||||||
}, [onPageItemClick, id]);
|
|
||||||
|
|
||||||
const hasExternalHref = href
|
const hasExternalHref = href
|
||||||
? href.startsWith("http://") || href.startsWith("https://")
|
? href.startsWith("http://") || href.startsWith("https://")
|
||||||
: false;
|
: false;
|
||||||
@@ -56,7 +48,7 @@ export default function DashboardSidebarPageItem({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<React.Fragment>
|
<React.Fragment>
|
||||||
<ListItem disablePadding>
|
<ListItem disablePadding style={{ padding: "5px" }}>
|
||||||
<ListItemButton
|
<ListItemButton
|
||||||
selected={selected}
|
selected={selected}
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
@@ -72,7 +64,7 @@ export default function DashboardSidebarPageItem({
|
|||||||
}
|
}
|
||||||
: {}),
|
: {}),
|
||||||
to: href,
|
to: href,
|
||||||
onClick: handleClick,
|
onClick: onPageItemClick,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{icon || mini ? (
|
{icon || mini ? (
|
||||||
|
|||||||
Reference in New Issue
Block a user