frontPanel/src/pages/Questions/QuestionSwitchWindowTool.tsx

73 lines
2.0 KiB
TypeScript
Raw Normal View History

2024-05-17 09:13:02 +00:00
import { Box, Skeleton, useMediaQuery, useTheme } from "@mui/material";
import { deleteTimeoutedQuestions } from "@utils/deleteTimeoutedQuestions";
2024-05-17 09:13:02 +00:00
import { lazy, Suspense, useCallback } from "react";
2023-11-29 15:45:15 +00:00
import { DraggableList } from "./DraggableList";
import { SwitchBranchingPanel } from "./SwitchBranchingPanel";
2023-11-29 15:45:15 +00:00
2024-05-17 09:13:02 +00:00
const BranchingMap = lazy(() =>
import("./BranchingMap").then((module) => ({ default: module.BranchingMap })),
);
interface Props {
openBranchingPage: boolean;
setOpenBranchingPage: (a: boolean) => void;
widthMain: number;
}
2023-12-31 02:53:25 +00:00
export const QuestionSwitchWindowTool = ({
openBranchingPage,
setOpenBranchingPage,
widthMain,
2023-12-31 02:53:25 +00:00
}: Props) => {
2023-12-25 15:38:40 +00:00
const theme = useTheme();
const isMobile = useMediaQuery(theme.breakpoints.down(600));
const isTablet = useMediaQuery(theme.breakpoints.down(1000));
2023-12-25 15:38:40 +00:00
const openBranchingPageHC = useCallback(() => {
if (!openBranchingPage) {
deleteTimeoutedQuestions();
2023-12-25 15:38:40 +00:00
}
setOpenBranchingPage(!openBranchingPage);
}, [openBranchingPage, setOpenBranchingPage]);
2023-12-25 15:38:40 +00:00
return (
<Box
sx={{
display: "flex",
2024-05-17 09:13:02 +00:00
flexWrap: "wrap",
marginBottom: isMobile ? "25px" : "30px",
2023-12-25 15:38:40 +00:00
}}
>
<Box sx={{ width: isTablet ? "100%" : "796px" }}>
{openBranchingPage ? (
2024-05-17 09:13:02 +00:00
<Suspense
fallback={
<Skeleton
sx={{
maxWidth: "796px",
width: "100%",
height: isMobile ? "357px" : "521px",
transform: "none",
}}
/>
}
>
<BranchingMap />
</Suspense>
) : (
<DraggableList
openBranchingPage={openBranchingPage}
setOpenBranchingPage={openBranchingPageHC}
/>
)}
2023-12-31 02:53:25 +00:00
</Box>
{openBranchingPage && (
2023-12-31 02:53:25 +00:00
<SwitchBranchingPanel
openBranchingPage={openBranchingPage}
setOpenBranchingPage={openBranchingPageHC}
widthMain={widthMain}
2023-12-31 02:53:25 +00:00
/>
)}
2023-12-25 15:38:40 +00:00
</Box>
);
};