2023-01-16 09:45:12 +00:00
|
|
|
import useAppState from "@dashboard/hooks/useAppState";
|
2023-03-23 14:53:48 +00:00
|
|
|
import { DevModeQuery } from "@dashboard/orders/queries";
|
|
|
|
import { getFilterVariables } from "@dashboard/orders/views/OrderList/filters";
|
2023-02-20 15:21:28 +00:00
|
|
|
import { LinearProgress } from "@material-ui/core";
|
|
|
|
import { useActionBar } from "@saleor/macaw-ui";
|
|
|
|
import { Box } from "@saleor/macaw-ui/next";
|
2023-03-17 14:10:58 +00:00
|
|
|
import React, { useState } from "react";
|
2023-03-23 14:53:48 +00:00
|
|
|
import { useLocation } from "react-router";
|
2020-05-14 09:30:32 +00:00
|
|
|
|
2023-03-17 14:10:58 +00:00
|
|
|
import { DevModePanel } from "../DevModePanel/DevModePanel";
|
|
|
|
import { useDevModeContext } from "../DevModePanel/hooks";
|
|
|
|
import { useDevModeKeyTrigger } from "../DevModePanel/useDevModeKeyTrigger";
|
2020-08-08 12:59:09 +00:00
|
|
|
import Navigator from "../Navigator";
|
2023-02-20 15:21:28 +00:00
|
|
|
import { Sidebar } from "../Sidebar";
|
|
|
|
import { contentMaxWidth } from "./consts";
|
|
|
|
import { useStyles } from "./styles";
|
2023-03-23 14:53:48 +00:00
|
|
|
import { extractQueryParams } from "./util";
|
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
|
|
|
}
|
|
|
|
|
2023-02-20 15:21:28 +00:00
|
|
|
const AppLayout: React.FC<AppLayoutProps> = ({ children }) => {
|
2022-06-30 09:05:09 +00:00
|
|
|
const classes = useStyles();
|
2022-03-16 09:45:15 +00:00
|
|
|
const { anchor: appActionAnchor } = useActionBar();
|
2022-10-24 09:49:11 +00:00
|
|
|
const [appState] = useAppState();
|
2023-03-17 14:10:58 +00:00
|
|
|
const [isNavigatorVisible, setNavigatorVisibility] = useState(false);
|
|
|
|
|
2023-03-23 14:53:48 +00:00
|
|
|
const {
|
|
|
|
isDevModeVisible,
|
|
|
|
setDevModeVisibility,
|
|
|
|
setDevModeContent,
|
|
|
|
setVariables,
|
|
|
|
} = useDevModeContext();
|
2023-03-17 14:10:58 +00:00
|
|
|
|
2023-03-23 14:53:48 +00:00
|
|
|
const params = extractQueryParams(useLocation().search);
|
|
|
|
|
|
|
|
useDevModeKeyTrigger(({ shift }) => {
|
|
|
|
if (shift) {
|
|
|
|
setDevModeContent(DevModeQuery);
|
|
|
|
const variables = JSON.stringify(
|
|
|
|
{
|
|
|
|
filter: getFilterVariables(params),
|
|
|
|
},
|
|
|
|
null,
|
|
|
|
2,
|
|
|
|
);
|
|
|
|
setVariables(variables);
|
|
|
|
} else {
|
|
|
|
setDevModeContent("");
|
|
|
|
setVariables("");
|
|
|
|
}
|
|
|
|
setDevModeVisibility(!isDevModeVisible);
|
|
|
|
});
|
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
|
|
|
<>
|
2023-03-17 14:10:58 +00:00
|
|
|
<DevModePanel
|
|
|
|
isDevModeVisible={isDevModeVisible}
|
|
|
|
setDevModeVisibility={setDevModeVisibility}
|
|
|
|
/>
|
2020-08-08 12:59:09 +00:00
|
|
|
<Navigator
|
|
|
|
visible={isNavigatorVisible}
|
|
|
|
setVisibility={setNavigatorVisibility}
|
|
|
|
/>
|
2023-02-20 15:21:28 +00:00
|
|
|
<Box display="grid" __gridTemplateColumns="auto 1fr">
|
|
|
|
{appState.loading && (
|
|
|
|
<LinearProgress className={classes.appLoader} color="primary" />
|
2023-01-26 10:01:15 +00:00
|
|
|
)}
|
2023-02-20 15:21:28 +00:00
|
|
|
<Box
|
|
|
|
height="100vh"
|
|
|
|
borderColor="neutralPlain"
|
|
|
|
borderRightWidth={1}
|
|
|
|
backgroundColor="subdued"
|
|
|
|
borderStyle="solid"
|
|
|
|
position="sticky"
|
|
|
|
top={0}
|
|
|
|
borderLeftWidth={0}
|
|
|
|
borderTopWidth={0}
|
|
|
|
borderBottomWidth={0}
|
2023-01-10 14:24:24 +00:00
|
|
|
>
|
2023-02-20 15:21:28 +00:00
|
|
|
<Sidebar />
|
|
|
|
</Box>
|
|
|
|
<Box height="100%" width="100%">
|
|
|
|
<Box as="main" width="100%">
|
|
|
|
{children}
|
|
|
|
</Box>
|
|
|
|
<Box
|
|
|
|
ref={appActionAnchor}
|
|
|
|
position="sticky"
|
|
|
|
bottom={0}
|
|
|
|
left={0}
|
|
|
|
right={0}
|
|
|
|
backgroundColor="plain"
|
|
|
|
borderTopWidth={1}
|
|
|
|
borderTopStyle="solid"
|
|
|
|
borderColor="neutralPlain"
|
|
|
|
__maxWidth={contentMaxWidth}
|
|
|
|
margin="auto"
|
2023-02-22 13:00:03 +00:00
|
|
|
zIndex="3"
|
2023-02-20 15:21:28 +00:00
|
|
|
/>
|
|
|
|
</Box>
|
|
|
|
</Box>
|
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;
|