frontPanel/src/pages/Questions/QuestionSwitchWindowTool.tsx

62 lines
1.7 KiB
TypeScript
Raw Normal View History

import { useEffect, useLayoutEffect } from "react";
2023-12-25 15:38:40 +00:00
import { Box, useMediaQuery, useTheme } from "@mui/material";
2023-11-29 15:45:15 +00:00
import { DraggableList } from "./DraggableList";
import { SwitchBranchingPanel } from "./SwitchBranchingPanel";
2023-11-29 15:45:15 +00:00
import { BranchingMap } from "./BranchingMap";
2023-12-25 15:38:40 +00:00
import { useQuestionsStore } from "@root/questions/store";
import { useUiTools } from "@root/uiTools/store";
2023-12-25 15:38:40 +00:00
import { useQuestions } from "@root/questions/hooks";
import { useCurrentQuiz } from "@root/quizes/hooks";
import { deleteTimeoutedQuestions } from "@utils/deleteTimeoutedQuestions";
2023-11-29 15:45:15 +00:00
interface Props {
openBranchingPage: boolean;
setOpenBranchingPage: (a: boolean) => void;
}
2023-12-31 02:53:25 +00:00
export const QuestionSwitchWindowTool = ({
openBranchingPage,
setOpenBranchingPage,
}: Props) => {
2023-12-25 15:38:40 +00:00
const { questions } = useQuestionsStore.getState();
const theme = useTheme();
const isMobile = useMediaQuery(theme.breakpoints.down(600));
const quiz = useCurrentQuiz();
const openBranchingPageHC = () => {
if (!openBranchingPage) {
deleteTimeoutedQuestions(questions, quiz);
2023-12-25 15:38:40 +00:00
}
setOpenBranchingPage(!openBranchingPage);
};
2023-12-25 15:38:40 +00:00
return (
<Box
sx={{
display: "flex",
gap: "20px",
flexWrap: "wrap",
marginBottom: isMobile ? "20px" : undefined,
}}
>
2023-12-31 02:53:25 +00:00
<Box sx={{ flexBasis: "796px" }}>
{openBranchingPage ? (
<BranchingMap />
) : (
<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}
/>
)}
2023-12-25 15:38:40 +00:00
</Box>
);
};