2023-12-31 02:53:25 +00:00
|
|
|
|
import { Box } from "@mui/material";
|
|
|
|
|
import {
|
|
|
|
|
clearRuleForAll,
|
|
|
|
|
createResult,
|
2024-02-23 14:07:44 +00:00
|
|
|
|
updateQuestion,
|
2023-12-31 02:53:25 +00:00
|
|
|
|
} from "@root/questions/actions";
|
|
|
|
|
import { updateRootContentId } from "@root/quizes/actions";
|
|
|
|
|
import { useCurrentQuiz } from "@root/quizes/hooks";
|
2024-02-23 14:23:26 +00:00
|
|
|
|
import { useQuizStore } from "@root/quizes/store";
|
2024-02-23 14:07:44 +00:00
|
|
|
|
import {
|
|
|
|
|
setOpenedModalQuestions,
|
|
|
|
|
updateOpenedModalSettingsId,
|
|
|
|
|
} from "@root/uiTools/actions";
|
2023-12-14 09:40:53 +00:00
|
|
|
|
import { useUiTools } from "@root/uiTools/store";
|
2024-01-05 16:48:35 +00:00
|
|
|
|
import { enqueueSnackbar } from "notistack";
|
|
|
|
|
import { useEffect, useLayoutEffect, useRef } from "react";
|
2023-11-29 15:45:15 +00:00
|
|
|
|
|
2024-01-05 16:48:35 +00:00
|
|
|
|
export const FirstNodeField = () => {
|
2023-12-31 02:53:25 +00:00
|
|
|
|
const quiz = useCurrentQuiz();
|
2024-02-23 14:07:44 +00:00
|
|
|
|
const modalQuestionTargetContentId = useUiTools(
|
|
|
|
|
(state) => state.modalQuestionTargetContentId,
|
|
|
|
|
);
|
2023-12-13 23:34:34 +00:00
|
|
|
|
|
2023-12-31 02:53:25 +00:00
|
|
|
|
useLayoutEffect(() => {
|
2024-02-23 14:07:44 +00:00
|
|
|
|
if (!quiz) return;
|
2023-12-13 23:34:34 +00:00
|
|
|
|
|
2023-12-31 02:53:25 +00:00
|
|
|
|
updateOpenedModalSettingsId();
|
|
|
|
|
updateRootContentId(quiz.id, "");
|
|
|
|
|
clearRuleForAll();
|
|
|
|
|
}, []);
|
2023-12-13 23:34:34 +00:00
|
|
|
|
|
2023-12-31 02:53:25 +00:00
|
|
|
|
const { dragQuestionContentId } = useUiTools();
|
|
|
|
|
const Container = useRef<HTMLDivElement | null>(null);
|
2023-12-13 23:34:34 +00:00
|
|
|
|
|
2023-12-31 02:53:25 +00:00
|
|
|
|
const modalOpen = () => setOpenedModalQuestions(true);
|
2023-12-13 23:34:34 +00:00
|
|
|
|
|
2023-12-31 02:53:25 +00:00
|
|
|
|
const newRootNode = () => {
|
|
|
|
|
if (quiz) {
|
|
|
|
|
if (dragQuestionContentId) {
|
|
|
|
|
updateRootContentId(quiz?.id, dragQuestionContentId);
|
|
|
|
|
updateQuestion(
|
|
|
|
|
dragQuestionContentId,
|
|
|
|
|
(question) => (question.content.rule.parentId = "root"),
|
|
|
|
|
);
|
2024-02-23 14:23:26 +00:00
|
|
|
|
createResult(useQuizStore.getState().editQuizId, dragQuestionContentId);
|
2023-12-31 02:53:25 +00:00
|
|
|
|
}
|
|
|
|
|
} else {
|
2024-02-23 14:07:44 +00:00
|
|
|
|
enqueueSnackbar("Нет информации о взятом опроснике");
|
2023-11-29 15:45:15 +00:00
|
|
|
|
}
|
2023-12-31 02:53:25 +00:00
|
|
|
|
};
|
2023-11-29 15:45:15 +00:00
|
|
|
|
|
2023-12-31 02:53:25 +00:00
|
|
|
|
useEffect(() => {
|
2024-02-23 14:07:44 +00:00
|
|
|
|
Container.current?.addEventListener("pointerup", newRootNode);
|
2023-12-31 02:53:25 +00:00
|
|
|
|
Container.current?.addEventListener("click", modalOpen);
|
|
|
|
|
return () => {
|
2024-02-23 14:07:44 +00:00
|
|
|
|
Container.current?.removeEventListener("pointerup", newRootNode);
|
2023-12-31 02:53:25 +00:00
|
|
|
|
Container.current?.removeEventListener("click", modalOpen);
|
|
|
|
|
};
|
|
|
|
|
}, [dragQuestionContentId]);
|
2023-12-01 19:56:13 +00:00
|
|
|
|
|
2023-12-31 02:53:25 +00:00
|
|
|
|
useEffect(() => {
|
|
|
|
|
if (quiz) {
|
|
|
|
|
if (modalQuestionTargetContentId) {
|
|
|
|
|
updateRootContentId(quiz?.id, modalQuestionTargetContentId);
|
|
|
|
|
updateQuestion(
|
|
|
|
|
modalQuestionTargetContentId,
|
|
|
|
|
(question) => (question.content.rule.parentId = "root"),
|
|
|
|
|
);
|
2024-02-23 14:23:26 +00:00
|
|
|
|
createResult(
|
|
|
|
|
useQuizStore.getState().editQuizId,
|
|
|
|
|
modalQuestionTargetContentId,
|
|
|
|
|
);
|
2023-12-31 02:53:25 +00:00
|
|
|
|
}
|
|
|
|
|
} else {
|
2024-02-23 14:07:44 +00:00
|
|
|
|
enqueueSnackbar("Нет информации о взятом опроснике");
|
2023-12-31 02:53:25 +00:00
|
|
|
|
}
|
|
|
|
|
}, [modalQuestionTargetContentId]);
|
2023-12-04 13:33:43 +00:00
|
|
|
|
|
2023-12-31 02:53:25 +00:00
|
|
|
|
return (
|
|
|
|
|
<Box
|
|
|
|
|
ref={Container}
|
|
|
|
|
sx={{
|
|
|
|
|
height: "100%",
|
|
|
|
|
width: "100%",
|
|
|
|
|
backgroundColor: "#f2f3f7",
|
|
|
|
|
display: "flex",
|
|
|
|
|
alignItems: "center",
|
|
|
|
|
justifyContent: "center",
|
|
|
|
|
color: "#4d4d4d",
|
|
|
|
|
fontSize: "50px",
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
+
|
|
|
|
|
</Box>
|
|
|
|
|
);
|
|
|
|
|
};
|