2023-01-16 09:45:12 +00:00
|
|
|
import { useUser } from "@dashboard/auth";
|
|
|
|
import useAppState from "@dashboard/hooks/useAppState";
|
|
|
|
import { isDarkTheme } from "@dashboard/misc";
|
2023-01-23 11:16:02 +00:00
|
|
|
import { LinearProgress } from "@material-ui/core";
|
|
|
|
import { useActionBar, useBacklink, useTheme } from "@saleor/macaw-ui";
|
2022-12-02 10:45:19 +00:00
|
|
|
import clsx from "clsx";
|
2020-05-14 09:30:32 +00:00
|
|
|
import React from "react";
|
|
|
|
|
2019-06-19 14:40:52 +00:00
|
|
|
import Container from "../Container";
|
2020-08-08 12:59:09 +00:00
|
|
|
import Navigator from "../Navigator";
|
2020-08-10 12:43:24 +00:00
|
|
|
import NavigatorButton from "../NavigatorButton/NavigatorButton";
|
2023-01-23 11:16:02 +00:00
|
|
|
import { Sidebar, SidebarDrawer } from "../Sidebar";
|
2020-11-18 15:11:15 +00:00
|
|
|
import UserChip from "../UserChip";
|
2020-11-23 09:39:24 +00:00
|
|
|
import useAppChannel from "./AppChannelContext";
|
|
|
|
import AppChannelSelect from "./AppChannelSelect";
|
2023-01-10 14:24:24 +00:00
|
|
|
import { useFullSizeStyles, useStyles } from "./styles";
|
2019-06-19 14:40:52 +00:00
|
|
|
|
|
|
|
interface AppLayoutProps {
|
|
|
|
children: React.ReactNode;
|
2022-06-30 09:05:09 +00:00
|
|
|
fullSize?: boolean;
|
2019-06-19 14:40:52 +00:00
|
|
|
}
|
|
|
|
|
2022-06-30 09:05:09 +00:00
|
|
|
const AppLayout: React.FC<AppLayoutProps> = ({
|
|
|
|
children,
|
|
|
|
fullSize = false,
|
|
|
|
}) => {
|
|
|
|
const classes = useStyles();
|
2023-01-10 14:24:24 +00:00
|
|
|
const fullSizeClasses = useFullSizeStyles();
|
2021-07-21 08:59:52 +00:00
|
|
|
const { themeType, setTheme } = useTheme();
|
2022-03-16 09:45:15 +00:00
|
|
|
const { anchor: appActionAnchor } = useActionBar();
|
2021-07-21 08:59:52 +00:00
|
|
|
const appHeaderAnchor = useBacklink();
|
2019-11-14 14:10:52 +00:00
|
|
|
const { logout, user } = useUser();
|
2022-10-24 09:49:11 +00:00
|
|
|
const [appState] = useAppState();
|
2020-08-08 12:59:09 +00:00
|
|
|
const [isNavigatorVisible, setNavigatorVisibility] = React.useState(false);
|
2023-01-23 11:16:02 +00:00
|
|
|
|
2023-01-25 12:32:30 +00:00
|
|
|
const { availableChannels, channel, isPickerActive, setChannel } =
|
|
|
|
useAppChannel(false);
|
2019-08-29 10:55:56 +00:00
|
|
|
|
2021-08-16 13:44:00 +00:00
|
|
|
const toggleTheme = () => setTheme(isDarkTheme(themeType) ? "light" : "dark");
|
2021-07-21 08:59:52 +00:00
|
|
|
|
2019-11-14 14:10:52 +00:00
|
|
|
return (
|
2020-08-08 12:59:09 +00:00
|
|
|
<>
|
|
|
|
<Navigator
|
|
|
|
visible={isNavigatorVisible}
|
|
|
|
setVisibility={setNavigatorVisibility}
|
|
|
|
/>
|
2021-07-21 08:59:52 +00:00
|
|
|
<div className={classes.root}>
|
2023-01-23 11:16:02 +00:00
|
|
|
<Sidebar />
|
2023-01-10 14:24:24 +00:00
|
|
|
<div
|
|
|
|
className={clsx(classes.content, {
|
|
|
|
[fullSizeClasses.content]: fullSize,
|
|
|
|
})}
|
|
|
|
>
|
2021-07-21 08:59:52 +00:00
|
|
|
{appState.loading ? (
|
|
|
|
<LinearProgress className={classes.appLoader} color="primary" />
|
|
|
|
) : (
|
|
|
|
<div className={classes.appLoaderPlaceholder} />
|
|
|
|
)}
|
2023-01-10 14:24:24 +00:00
|
|
|
<div
|
|
|
|
className={clsx(classes.viewContainer, {
|
|
|
|
[fullSizeClasses.viewContainer]: fullSize,
|
|
|
|
})}
|
|
|
|
>
|
2021-07-21 08:59:52 +00:00
|
|
|
<div>
|
|
|
|
<Container>
|
|
|
|
<div className={classes.header}>
|
|
|
|
<div className={classes.headerAnchor} ref={appHeaderAnchor} />
|
|
|
|
<div className={classes.headerToolbar}>
|
2023-01-23 11:16:02 +00:00
|
|
|
<SidebarDrawer />
|
2021-07-21 08:59:52 +00:00
|
|
|
<div className={classes.spacer} />
|
|
|
|
<div className={classes.userBar}>
|
|
|
|
<NavigatorButton
|
|
|
|
isMac={navigator.platform.toLowerCase().includes("mac")}
|
|
|
|
onClick={() => setNavigatorVisibility(true)}
|
|
|
|
/>
|
2021-08-11 11:44:47 +00:00
|
|
|
{isPickerActive && (
|
2021-07-21 08:59:52 +00:00
|
|
|
<AppChannelSelect
|
|
|
|
channels={availableChannels}
|
2021-08-20 11:14:14 +00:00
|
|
|
selectedChannelId={channel?.id}
|
2021-07-21 08:59:52 +00:00
|
|
|
onChannelSelect={setChannel}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
<UserChip
|
2021-08-16 13:44:00 +00:00
|
|
|
isDarkThemeEnabled={isDarkTheme(themeType)}
|
2021-07-21 08:59:52 +00:00
|
|
|
user={user}
|
|
|
|
onLogout={logout}
|
|
|
|
onThemeToggle={toggleTheme}
|
2020-11-18 15:11:15 +00:00
|
|
|
/>
|
2019-06-19 14:40:52 +00:00
|
|
|
</div>
|
2021-07-21 08:59:52 +00:00
|
|
|
</div>
|
2020-08-08 12:59:09 +00:00
|
|
|
</div>
|
2021-07-21 08:59:52 +00:00
|
|
|
</Container>
|
2019-11-14 14:10:52 +00:00
|
|
|
</div>
|
2022-06-30 09:05:09 +00:00
|
|
|
<main
|
2022-12-02 10:45:19 +00:00
|
|
|
className={clsx(classes.view, {
|
2022-06-30 09:05:09 +00:00
|
|
|
[classes.viewMargins]: !fullSize,
|
2023-01-10 14:24:24 +00:00
|
|
|
[fullSizeClasses.view]: fullSize,
|
2022-06-30 09:05:09 +00:00
|
|
|
})}
|
|
|
|
>
|
2022-10-24 09:49:11 +00:00
|
|
|
{children}
|
2021-07-21 08:59:52 +00:00
|
|
|
</main>
|
2019-11-14 14:10:52 +00:00
|
|
|
</div>
|
2022-03-16 09:45:15 +00:00
|
|
|
<div className={classes.appAction} ref={appActionAnchor} />
|
2021-07-21 08:59:52 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2020-08-08 12:59:09 +00:00
|
|
|
</>
|
2019-11-14 14:10:52 +00:00
|
|
|
);
|
|
|
|
};
|
2019-06-19 14:40:52 +00:00
|
|
|
|
|
|
|
export default AppLayout;
|