fix delete with timeout & restore
This commit is contained in:
parent
60632625ba
commit
16eb2c7d6b
@ -11,7 +11,7 @@ import {
|
|||||||
useMediaQuery,
|
useMediaQuery,
|
||||||
useTheme,
|
useTheme,
|
||||||
} from "@mui/material";
|
} from "@mui/material";
|
||||||
import { copyQuestion, deleteQuestion, updateOpenBranchingPanel, updateDesireToOpenABranchingModal } from "@root/questions/actions";
|
import { copyQuestion, deleteQuestion, updateOpenBranchingPanel, updateDesireToOpenABranchingModal, deleteQuestionWithTimeout } from "@root/questions/actions";
|
||||||
import MiniButtonSetting from "@ui_kit/MiniButtonSetting";
|
import MiniButtonSetting from "@ui_kit/MiniButtonSetting";
|
||||||
import { CopyIcon } from "../../assets/icons/questionsPage/CopyIcon";
|
import { CopyIcon } from "../../assets/icons/questionsPage/CopyIcon";
|
||||||
import Branching from "../../assets/icons/questionsPage/branching";
|
import Branching from "../../assets/icons/questionsPage/branching";
|
||||||
@ -40,10 +40,10 @@ export default function ButtonsOptions({
|
|||||||
const isMobile = useMediaQuery(theme.breakpoints.down(790));
|
const isMobile = useMediaQuery(theme.breakpoints.down(790));
|
||||||
const isWrappMiniButtonSetting = useMediaQuery(theme.breakpoints.down(920));
|
const isWrappMiniButtonSetting = useMediaQuery(theme.breakpoints.down(920));
|
||||||
const quiz = useCurrentQuiz();
|
const quiz = useCurrentQuiz();
|
||||||
const { openBranchingPanel } = useQuestionsStore.getState()
|
const { openBranchingPanel } = useQuestionsStore.getState();
|
||||||
|
|
||||||
const openedModal = () => {
|
const openedModal = () => {
|
||||||
updateOpenedModalSettingsId(question.id)
|
updateOpenedModalSettingsId(question.id);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -84,8 +84,8 @@ export default function ButtonsOptions({
|
|||||||
title: "Ветвление",
|
title: "Ветвление",
|
||||||
value: "branching",
|
value: "branching",
|
||||||
myFunc: (question) => {
|
myFunc: (question) => {
|
||||||
updateOpenBranchingPanel(true)
|
updateOpenBranchingPanel(true);
|
||||||
updateDesireToOpenABranchingModal(question.content.id)
|
updateDesireToOpenABranchingModal(question.content.id);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
@ -161,7 +161,7 @@ export default function ButtonsOptions({
|
|||||||
<MiniButtonSetting
|
<MiniButtonSetting
|
||||||
key={title}
|
key={title}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
openedModal()
|
openedModal();
|
||||||
// SSHC(value);
|
// SSHC(value);
|
||||||
// myFunc(question);
|
// myFunc(question);
|
||||||
}}
|
}}
|
||||||
@ -269,76 +269,64 @@ export default function ButtonsOptions({
|
|||||||
</IconButton>
|
</IconButton>
|
||||||
<IconButton
|
<IconButton
|
||||||
sx={{ borderRadius: "6px", padding: "2px" }}
|
sx={{ borderRadius: "6px", padding: "2px" }}
|
||||||
onClick={() => { // TODO
|
onClick={() => {
|
||||||
// const removedId = question.id;
|
const deleteFn = () => {
|
||||||
// if (question.deleteTimeoutId) {
|
if (question.type !== null) {
|
||||||
// clearTimeout(question.deleteTimeoutId);
|
if (question.content.rule.parentId === "root") { //удалить из стора root и очистить rule всем вопросам
|
||||||
// }
|
updateRootContentId(quiz.id, "");
|
||||||
|
clearRuleForAll();
|
||||||
// removeQuestion(quizId, totalIndex);
|
questions.forEach(q => {
|
||||||
|
if (q.type === "result") {
|
||||||
// const newTimeoutId = window.setTimeout(() => {
|
deleteQuestion(q.id);
|
||||||
// removeQuestionForce(quizId, removedId);
|
|
||||||
// }, 5000);
|
|
||||||
|
|
||||||
// updateQuestionsList<QuizQuestionBase>(quizId, totalIndex, {
|
|
||||||
// ...question,
|
|
||||||
// deleteTimeoutId: newTimeoutId,
|
|
||||||
// });
|
|
||||||
|
|
||||||
if (question.type !== null) {
|
|
||||||
if (question.content.rule.parentId === "root") { //удалить из стора root и очистить rule всем вопросам
|
|
||||||
updateRootContentId(quiz.id, "")
|
|
||||||
clearRuleForAll()
|
|
||||||
questions.forEach(q => {
|
|
||||||
if (q.type === "result") {
|
|
||||||
deleteQuestion(q.id);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
deleteQuestion(question.id);
|
|
||||||
} else if (question.content.rule.parentId.length > 0) { //удалить из стора вопрос из дерева и очистить его потомков
|
|
||||||
const clearQuestions = [] as string[]
|
|
||||||
|
|
||||||
//записываем потомков , а их результаты удаляем
|
|
||||||
const getChildren = (parentQuestion: AnyTypedQuizQuestion) => {
|
|
||||||
questions.forEach((targetQuestion) => {
|
|
||||||
if (targetQuestion.content.rule.parentId === parentQuestion.content.id) {//если у вопроса совпал родитель с родителем => он потомок, в кучу его
|
|
||||||
if (targetQuestion.type === "result") {
|
|
||||||
deleteQuestion(targetQuestion.id);
|
|
||||||
} else {
|
|
||||||
if (!clearQuestions.includes(targetQuestion.content.id)) clearQuestions.push(targetQuestion.content.id)
|
|
||||||
getChildren(targetQuestion) //и ищем его потомков
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
|
deleteQuestion(question.id);
|
||||||
|
} else if (question.content.rule.parentId.length > 0) { //удалить из стора вопрос из дерева и очистить его потомков
|
||||||
|
const clearQuestions = [] as string[];
|
||||||
|
|
||||||
|
//записываем потомков , а их результаты удаляем
|
||||||
|
const getChildren = (parentQuestion: AnyTypedQuizQuestion) => {
|
||||||
|
questions.forEach((targetQuestion) => {
|
||||||
|
if (targetQuestion.content.rule.parentId === parentQuestion.content.id) {//если у вопроса совпал родитель с родителем => он потомок, в кучу его
|
||||||
|
if (targetQuestion.type === "result") {
|
||||||
|
deleteQuestion(targetQuestion.id);
|
||||||
|
} else {
|
||||||
|
if (!clearQuestions.includes(targetQuestion.content.id)) clearQuestions.push(targetQuestion.content.id);
|
||||||
|
getChildren(targetQuestion); //и ищем его потомков
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
getChildren(question);
|
||||||
|
//чистим потомков от инфы ветвления
|
||||||
|
clearQuestions.forEach((id) => {
|
||||||
|
updateQuestion(id, question => {
|
||||||
|
question.content.rule.parentId = "";
|
||||||
|
question.content.rule.main = [];
|
||||||
|
question.content.rule.default = "";
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
//чистим rule родителя
|
||||||
|
const parentQuestion = getQuestionByContentId(question.content.rule.parentId);
|
||||||
|
const newRule = {};
|
||||||
|
newRule.main = parentQuestion.content.rule.main.filter((data) => data.next !== question.content.id); //удаляем условия перехода от родителя к этому вопросу
|
||||||
|
newRule.parentId = parentQuestion.content.rule.parentId;
|
||||||
|
newRule.default = parentQuestion.content.rule.parentId === question.content.id ? "" : parentQuestion.content.rule.parentId;
|
||||||
|
newRule.children = [...parentQuestion.content.rule.children].splice(parentQuestion.content.rule.children.indexOf(question.content.id), 1);
|
||||||
|
|
||||||
|
updateQuestion(question.content.rule.parentId, (PQ) => {
|
||||||
|
PQ.content.rule = newRule;
|
||||||
|
});
|
||||||
|
deleteQuestion(question.id);
|
||||||
}
|
}
|
||||||
getChildren(question)
|
|
||||||
//чистим потомков от инфы ветвления
|
|
||||||
clearQuestions.forEach((id) => {
|
|
||||||
updateQuestion(id, question => {
|
|
||||||
question.content.rule.parentId = ""
|
|
||||||
question.content.rule.main = []
|
|
||||||
question.content.rule.default = ""
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
//чистим rule родителя
|
deleteQuestion(question.id);
|
||||||
const parentQuestion = getQuestionByContentId(question.content.rule.parentId)
|
|
||||||
const newRule = {}
|
|
||||||
newRule.main = parentQuestion.content.rule.main.filter((data) => data.next !== question.content.id) //удаляем условия перехода от родителя к этому вопросу
|
|
||||||
newRule.parentId = parentQuestion.content.rule.parentId
|
|
||||||
newRule.default = parentQuestion.content.rule.parentId === question.content.id ? "" : parentQuestion.content.rule.parentId
|
|
||||||
newRule.children = [...parentQuestion.content.rule.children].splice(parentQuestion.content.rule.children.indexOf(question.content.id), 1);
|
|
||||||
|
|
||||||
updateQuestion(question.content.rule.parentId, (PQ) => {
|
|
||||||
PQ.content.rule = newRule
|
|
||||||
})
|
|
||||||
deleteQuestion(question.id)
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
deleteQuestion(question.id)
|
deleteQuestionWithTimeout(question.id, deleteFn);
|
||||||
|
|
||||||
}
|
|
||||||
}}
|
}}
|
||||||
data-cy="delete-question"
|
data-cy="delete-question"
|
||||||
>
|
>
|
||||||
|
@ -10,7 +10,7 @@ import {
|
|||||||
useMediaQuery,
|
useMediaQuery,
|
||||||
useTheme,
|
useTheme,
|
||||||
} from "@mui/material";
|
} from "@mui/material";
|
||||||
import { copyQuestion, deleteQuestion, updateQuestion, clearRuleForAll, getQuestionByContentId } from "@root/questions/actions";
|
import { copyQuestion, deleteQuestion, updateQuestion, clearRuleForAll, getQuestionByContentId, deleteQuestionWithTimeout } from "@root/questions/actions";
|
||||||
import MiniButtonSetting from "@ui_kit/MiniButtonSetting";
|
import MiniButtonSetting from "@ui_kit/MiniButtonSetting";
|
||||||
import { ReallyChangingModal } from "@ui_kit/Modal/ReallyChangingModal/ReallyChangingModal";
|
import { ReallyChangingModal } from "@ui_kit/Modal/ReallyChangingModal/ReallyChangingModal";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
@ -47,7 +47,7 @@ export default function ButtonsOptionsAndPict({
|
|||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const isMobile = useMediaQuery(theme.breakpoints.down(790));
|
const isMobile = useMediaQuery(theme.breakpoints.down(790));
|
||||||
const isIconMobile = useMediaQuery(theme.breakpoints.down(1050));
|
const isIconMobile = useMediaQuery(theme.breakpoints.down(1050));
|
||||||
const { questions } = useQuestionsStore.getState()
|
const { questions } = useQuestionsStore.getState();
|
||||||
const quiz = useCurrentQuiz();
|
const quiz = useCurrentQuiz();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -191,8 +191,8 @@ export default function ButtonsOptionsAndPict({
|
|||||||
onMouseEnter={() => setButtonHover("branching")}
|
onMouseEnter={() => setButtonHover("branching")}
|
||||||
onMouseLeave={() => setButtonHover("")}
|
onMouseLeave={() => setButtonHover("")}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
updateOpenBranchingPanel(true)
|
updateOpenBranchingPanel(true);
|
||||||
updateDesireToOpenABranchingModal(question.content.id)
|
updateDesireToOpenABranchingModal(question.content.id);
|
||||||
}}
|
}}
|
||||||
sx={{
|
sx={{
|
||||||
height: "30px",
|
height: "30px",
|
||||||
@ -307,76 +307,64 @@ export default function ButtonsOptionsAndPict({
|
|||||||
</IconButton>
|
</IconButton>
|
||||||
<IconButton
|
<IconButton
|
||||||
sx={{ borderRadius: "6px", padding: "2px" }}
|
sx={{ borderRadius: "6px", padding: "2px" }}
|
||||||
onClick={() => { // TODO
|
onClick={() => {
|
||||||
// const removedId = question.id;
|
const deleteFn = () => {
|
||||||
// if (question.deleteTimeoutId) {
|
if (question.type !== null) {
|
||||||
// clearTimeout(question.deleteTimeoutId);
|
if (question.content.rule.parentId === "root") { //удалить из стора root и очистить rule всем вопросам
|
||||||
// }
|
updateRootContentId(quiz.id, "");
|
||||||
|
clearRuleForAll();
|
||||||
// removeQuestion(quizId, totalIndex);
|
questions.forEach(q => {
|
||||||
|
if (q.type === "result") {
|
||||||
// const newTimeoutId = window.setTimeout(() => {
|
deleteQuestion(q.id);
|
||||||
// removeQuestionForce(quizId, removedId);
|
|
||||||
// }, 5000);
|
|
||||||
|
|
||||||
// updateQuestionsList<QuizQuestionBase>(quizId, totalIndex, {
|
|
||||||
// ...question,
|
|
||||||
// deleteTimeoutId: newTimeoutId,
|
|
||||||
// });
|
|
||||||
|
|
||||||
if (question.type !== null) {
|
|
||||||
if (question.content.rule.parentId === "root") { //удалить из стора root и очистить rule всем вопросам
|
|
||||||
updateRootContentId(quiz.id, "")
|
|
||||||
clearRuleForAll()
|
|
||||||
questions.forEach(q => {
|
|
||||||
if (q.type === "result") {
|
|
||||||
deleteQuestion(q.id);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
deleteQuestion(question.id);
|
|
||||||
} else if (question.content.rule.parentId.length > 0) { //удалить из стора вопрос из дерева и очистить его потомков
|
|
||||||
const clearQuestions = [] as string[]
|
|
||||||
|
|
||||||
//записываем потомков , а их результаты удаляем
|
|
||||||
const getChildren = (parentQuestion: AnyTypedQuizQuestion) => {
|
|
||||||
questions.forEach((targetQuestion) => {
|
|
||||||
if (targetQuestion.content.rule.parentId === parentQuestion.content.id) {//если у вопроса совпал родитель с родителем => он потомок, в кучу его
|
|
||||||
if (targetQuestion.type === "result") {
|
|
||||||
deleteQuestion(targetQuestion.id);
|
|
||||||
} else {
|
|
||||||
if (!clearQuestions.includes(targetQuestion.content.id)) clearQuestions.push(targetQuestion.content.id)
|
|
||||||
getChildren(targetQuestion) //и ищем его потомков
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
|
deleteQuestion(question.id);
|
||||||
|
} else if (question.content.rule.parentId.length > 0) { //удалить из стора вопрос из дерева и очистить его потомков
|
||||||
|
const clearQuestions = [] as string[];
|
||||||
|
|
||||||
|
//записываем потомков , а их результаты удаляем
|
||||||
|
const getChildren = (parentQuestion: AnyTypedQuizQuestion) => {
|
||||||
|
questions.forEach((targetQuestion) => {
|
||||||
|
if (targetQuestion.content.rule.parentId === parentQuestion.content.id) {//если у вопроса совпал родитель с родителем => он потомок, в кучу его
|
||||||
|
if (targetQuestion.type === "result") {
|
||||||
|
deleteQuestion(targetQuestion.id);
|
||||||
|
} else {
|
||||||
|
if (!clearQuestions.includes(targetQuestion.content.id)) clearQuestions.push(targetQuestion.content.id);
|
||||||
|
getChildren(targetQuestion); //и ищем его потомков
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
getChildren(question);
|
||||||
|
//чистим потомков от инфы ветвления
|
||||||
|
clearQuestions.forEach((id) => {
|
||||||
|
updateQuestion(id, question => {
|
||||||
|
question.content.rule.parentId = "";
|
||||||
|
question.content.rule.main = [];
|
||||||
|
question.content.rule.default = "";
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
//чистим rule родителя
|
||||||
|
const parentQuestion = getQuestionByContentId(question.content.rule.parentId);
|
||||||
|
const newRule = {};
|
||||||
|
newRule.main = parentQuestion.content.rule.main.filter((data) => data.next !== question.content.id); //удаляем условия перехода от родителя к этому вопросу
|
||||||
|
newRule.parentId = parentQuestion.content.rule.parentId;
|
||||||
|
newRule.default = parentQuestion.content.rule.parentId === question.content.id ? "" : parentQuestion.content.rule.parentId;
|
||||||
|
newRule.children = [...parentQuestion.content.rule.children].splice(parentQuestion.content.rule.children.indexOf(question.content.id), 1);
|
||||||
|
|
||||||
|
updateQuestion(question.content.rule.parentId, (PQ) => {
|
||||||
|
PQ.content.rule = newRule;
|
||||||
|
});
|
||||||
|
deleteQuestion(question.id);
|
||||||
}
|
}
|
||||||
getChildren(question)
|
|
||||||
//чистим потомков от инфы ветвления
|
|
||||||
clearQuestions.forEach((id) => {
|
|
||||||
updateQuestion(id, question => {
|
|
||||||
question.content.rule.parentId = ""
|
|
||||||
question.content.rule.main = []
|
|
||||||
question.content.rule.default = ""
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
//чистим rule родителя
|
deleteQuestion(question.id);
|
||||||
const parentQuestion = getQuestionByContentId(question.content.rule.parentId)
|
|
||||||
const newRule = {}
|
|
||||||
newRule.main = parentQuestion.content.rule.main.filter((data) => data.next !== question.content.id) //удаляем условия перехода от родителя к этому вопросу
|
|
||||||
newRule.parentId = parentQuestion.content.rule.parentId
|
|
||||||
newRule.default = parentQuestion.content.rule.parentId === question.content.id ? "" : parentQuestion.content.rule.parentId
|
|
||||||
newRule.children = [...parentQuestion.content.rule.children].splice(parentQuestion.content.rule.children.indexOf(question.content.id), 1);
|
|
||||||
|
|
||||||
updateQuestion(question.content.rule.parentId, (PQ) => {
|
|
||||||
PQ.content.rule = newRule
|
|
||||||
})
|
|
||||||
deleteQuestion(question.id)
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
deleteQuestion(question.id)
|
deleteQuestionWithTimeout(question.id, deleteFn);
|
||||||
|
|
||||||
}
|
|
||||||
}}
|
}}
|
||||||
data-cy="delete-question"
|
data-cy="delete-question"
|
||||||
>
|
>
|
||||||
|
@ -3,8 +3,8 @@ import { Box, ListItem, Typography, useTheme } from "@mui/material";
|
|||||||
import { memo, useEffect } from "react";
|
import { memo, useEffect } from "react";
|
||||||
import { Draggable } from "react-beautiful-dnd";
|
import { Draggable } from "react-beautiful-dnd";
|
||||||
import QuestionsPageCard from "./QuestionPageCard";
|
import QuestionsPageCard from "./QuestionPageCard";
|
||||||
import { updateEditSomeQuestion } from "@root/questions/actions"
|
import { cancelQuestionDeletion, updateEditSomeQuestion } from "@root/questions/actions";
|
||||||
import { useQuestionsStore } from "@root/questions/store"
|
import { useQuestionsStore } from "@root/questions/store";
|
||||||
|
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
@ -15,21 +15,21 @@ type Props = {
|
|||||||
|
|
||||||
function DraggableListItem({ question, isDragging, index }: Props) {
|
function DraggableListItem({ question, isDragging, index }: Props) {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const { editSomeQuestion } = useQuestionsStore()
|
const { editSomeQuestion } = useQuestionsStore();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (editSomeQuestion !== null) {
|
if (editSomeQuestion !== null) {
|
||||||
const setI = setInterval(() => {
|
const setI = setInterval(() => {
|
||||||
let comp = document.getElementById(editSomeQuestion)
|
let comp = document.getElementById(editSomeQuestion);
|
||||||
if(comp !== null) {
|
if (comp !== null) {
|
||||||
clearInterval(setI)
|
clearInterval(setI);
|
||||||
comp.scrollIntoView({behavior: 'instant'})
|
comp.scrollIntoView({ behavior: 'instant' });
|
||||||
updateEditSomeQuestion()
|
updateEditSomeQuestion();
|
||||||
}
|
}
|
||||||
}, 200)
|
}, 200);
|
||||||
|
|
||||||
}
|
}
|
||||||
}, [editSomeQuestion])
|
}, [editSomeQuestion]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Draggable draggableId={question.id.toString()} index={index}>
|
<Draggable draggableId={question.id.toString()} index={index}>
|
||||||
@ -60,11 +60,8 @@ function DraggableListItem({ question, isDragging, index }: Props) {
|
|||||||
Вопрос удалён.
|
Вопрос удалён.
|
||||||
</Typography>
|
</Typography>
|
||||||
<Typography
|
<Typography
|
||||||
onClick={() => { // TODO
|
onClick={() => {
|
||||||
// updateQuestionsList<QuizQuestionBase>(quizId, index, {
|
cancelQuestionDeletion(question.id);
|
||||||
// ...questionData,
|
|
||||||
// deleted: false,
|
|
||||||
// });
|
|
||||||
}}
|
}}
|
||||||
sx={{
|
sx={{
|
||||||
cursor: "pointer",
|
cursor: "pointer",
|
||||||
|
@ -29,7 +29,7 @@ import {
|
|||||||
useMediaQuery,
|
useMediaQuery,
|
||||||
useTheme,
|
useTheme,
|
||||||
} from "@mui/material";
|
} from "@mui/material";
|
||||||
import { copyQuestion, createUntypedQuestion, deleteQuestion, clearRuleForAll, toggleExpandQuestion, updateQuestion, updateUntypedQuestion, getQuestionByContentId } from "@root/questions/actions";
|
import { copyQuestion, createUntypedQuestion, deleteQuestion, clearRuleForAll, toggleExpandQuestion, updateQuestion, updateUntypedQuestion, getQuestionByContentId, deleteQuestionWithTimeout } from "@root/questions/actions";
|
||||||
import { updateRootContentId } from "@root/quizes/actions";
|
import { updateRootContentId } from "@root/quizes/actions";
|
||||||
import { useRef, useState } from "react";
|
import { useRef, useState } from "react";
|
||||||
import type { DraggableProvidedDragHandleProps } from "react-beautiful-dnd";
|
import type { DraggableProvidedDragHandleProps } from "react-beautiful-dnd";
|
||||||
@ -51,7 +51,7 @@ interface Props {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default function QuestionsPageCard({ question, draggableProps, isDragging, index }: Props) {
|
export default function QuestionsPageCard({ question, draggableProps, isDragging, index }: Props) {
|
||||||
const { questions } = useQuestionsStore()
|
const { questions } = useQuestionsStore();
|
||||||
const [plusVisible, setPlusVisible] = useState<boolean>(false);
|
const [plusVisible, setPlusVisible] = useState<boolean>(false);
|
||||||
const [open, setOpen] = useState<boolean>(false);
|
const [open, setOpen] = useState<boolean>(false);
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
@ -241,79 +241,67 @@ export default function QuestionsPageCard({ question, draggableProps, isDragging
|
|||||||
padding: "0",
|
padding: "0",
|
||||||
margin: "0 5px 0 10px",
|
margin: "0 5px 0 10px",
|
||||||
}}
|
}}
|
||||||
onClick={() => { // TODO
|
onClick={() => {
|
||||||
const removedId = question.id;
|
const deleteFn = () => {
|
||||||
// if (question.deleteTimeoutId) {
|
if (question.type !== null) {
|
||||||
// clearTimeout(question.deleteTimeoutId);
|
if (question.content.rule.parentId === "root") { //удалить из стора root и очистить rule всем вопросам
|
||||||
// }
|
updateRootContentId(quiz.id, "");
|
||||||
|
clearRuleForAll();
|
||||||
// removeQuestion(quizId, totalIndex);
|
deleteQuestion(question.id);
|
||||||
|
questions.forEach(q => {
|
||||||
// const newTimeoutId = window.setTimeout(() => {
|
if (q.type === "result") {
|
||||||
// removeQuestionForce(quizId, removedId);
|
deleteQuestion(q.id);
|
||||||
// }, 5000);
|
|
||||||
|
|
||||||
// updateQuestionsList<AnyTypedQuizQuestion>(quizId, totalIndex, {
|
|
||||||
// ...question,
|
|
||||||
// deleteTimeoutId: newTimeoutId,
|
|
||||||
// });
|
|
||||||
console.log(question.type)
|
|
||||||
if (question.type !== null) {
|
|
||||||
if (question.content.rule.parentId === "root") { //удалить из стора root и очистить rule всем вопросам
|
|
||||||
updateRootContentId(quiz.id, "")
|
|
||||||
clearRuleForAll()
|
|
||||||
deleteQuestion(question.id);
|
|
||||||
questions.forEach(q => {
|
|
||||||
if (q.type === "result") {
|
|
||||||
deleteQuestion(q.id);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else if (question.content.rule.parentId.length > 0) { //удалить из стора вопрос из дерева и очистить его потомков
|
|
||||||
const clearQuestions = [] as string[]
|
|
||||||
|
|
||||||
//записываем потомков , а их результаты удаляем
|
|
||||||
const getChildren = (parentQuestion: AnyTypedQuizQuestion) => {
|
|
||||||
questions.forEach((targetQuestion) => {
|
|
||||||
if (targetQuestion.content.rule.parentId === parentQuestion.content.id) {//если у вопроса совпал родитель с родителем => он потомок, в кучу его
|
|
||||||
if (targetQuestion.type === "result") {
|
|
||||||
deleteQuestion(targetQuestion.id);
|
|
||||||
} else {
|
|
||||||
if (!clearQuestions.includes(targetQuestion.content.id)) clearQuestions.push(targetQuestion.content.id)
|
|
||||||
getChildren(targetQuestion) //и ищем его потомков
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
|
} else if (question.content.rule.parentId.length > 0) { //удалить из стора вопрос из дерева и очистить его потомков
|
||||||
|
const clearQuestions = [] as string[];
|
||||||
|
|
||||||
|
//записываем потомков , а их результаты удаляем
|
||||||
|
const getChildren = (parentQuestion: AnyTypedQuizQuestion) => {
|
||||||
|
questions.forEach((targetQuestion) => {
|
||||||
|
if (targetQuestion.content.rule.parentId === parentQuestion.content.id) {//если у вопроса совпал родитель с родителем => он потомок, в кучу его
|
||||||
|
if (targetQuestion.type === "result") {
|
||||||
|
deleteQuestion(targetQuestion.id);
|
||||||
|
} else {
|
||||||
|
if (!clearQuestions.includes(targetQuestion.content.id)) clearQuestions.push(targetQuestion.content.id);
|
||||||
|
getChildren(targetQuestion); //и ищем его потомков
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
getChildren(question);
|
||||||
|
//чистим потомков от инфы ветвления
|
||||||
|
clearQuestions.forEach((id) => {
|
||||||
|
updateQuestion(id, question => {
|
||||||
|
question.content.rule.parentId = "";
|
||||||
|
question.content.rule.main = [];
|
||||||
|
question.content.rule.default = "";
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
//чистим rule родителя
|
||||||
|
const parentQuestion = getQuestionByContentId(question.content.rule.parentId);
|
||||||
|
const newRule = {};
|
||||||
|
newRule.main = parentQuestion.content.rule.main.filter((data) => data.next !== question.content.id); //удаляем условия перехода от родителя к этому вопросу
|
||||||
|
newRule.parentId = parentQuestion.content.rule.parentId;
|
||||||
|
newRule.default = parentQuestion.content.rule.parentId === question.content.id ? "" : parentQuestion.content.rule.parentId;
|
||||||
|
newRule.children = [...parentQuestion.content.rule.children].splice(parentQuestion.content.rule.children.indexOf(question.content.id), 1);
|
||||||
|
|
||||||
|
updateQuestion(question.content.rule.parentId, (PQ) => {
|
||||||
|
PQ.content.rule = newRule;
|
||||||
|
});
|
||||||
|
deleteQuestion(question.id);
|
||||||
}
|
}
|
||||||
getChildren(question)
|
|
||||||
//чистим потомков от инфы ветвления
|
|
||||||
clearQuestions.forEach((id) => {
|
|
||||||
updateQuestion(id, question => {
|
|
||||||
question.content.rule.parentId = ""
|
|
||||||
question.content.rule.main = []
|
|
||||||
question.content.rule.default = ""
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
//чистим rule родителя
|
|
||||||
const parentQuestion = getQuestionByContentId(question.content.rule.parentId)
|
|
||||||
const newRule = {}
|
|
||||||
newRule.main = parentQuestion.content.rule.main.filter((data) => data.next !== question.content.id) //удаляем условия перехода от родителя к этому вопросу
|
|
||||||
newRule.parentId = parentQuestion.content.rule.parentId
|
|
||||||
newRule.default = parentQuestion.content.rule.parentId === question.content.id ? "" : parentQuestion.content.rule.parentId
|
|
||||||
newRule.children = [...parentQuestion.content.rule.children].splice(parentQuestion.content.rule.children.indexOf(question.content.id), 1);
|
|
||||||
|
|
||||||
updateQuestion(question.content.rule.parentId, (PQ) => {
|
deleteQuestion(question.id);
|
||||||
PQ.content.rule = newRule
|
} else {
|
||||||
})
|
console.log("удаляю безтипогово");
|
||||||
deleteQuestion(question.id)
|
deleteQuestion(question.id);
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
deleteQuestionWithTimeout(question.id, deleteFn);
|
||||||
deleteQuestion(question.id)
|
|
||||||
} else {
|
|
||||||
console.log("удаляю безтипогово")
|
|
||||||
deleteQuestion(question.id)
|
|
||||||
}
|
|
||||||
}}
|
}}
|
||||||
data-cy="delete-question"
|
data-cy="delete-question"
|
||||||
>
|
>
|
||||||
|
@ -140,6 +140,37 @@ export const collapseAllQuestions = () => setProducedState(state => {
|
|||||||
state.questions.forEach(question => question.expanded = false);
|
state.questions.forEach(question => question.expanded = false);
|
||||||
}, "collapseAllQuestions");
|
}, "collapseAllQuestions");
|
||||||
|
|
||||||
|
const DELETE_TIMEOUT = 5000;
|
||||||
|
|
||||||
|
export const deleteQuestionWithTimeout = (questionId: string, deleteFn: (questionId: string) => void) => setProducedState(state => {
|
||||||
|
const question = state.questions.find(q => q.id === questionId);
|
||||||
|
if (!question) return;
|
||||||
|
if (question.type === null || question.type === "result") {
|
||||||
|
deleteFn(questionId);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
question.deleted = true;
|
||||||
|
clearTimeout(question.deleteTimeoutId);
|
||||||
|
question.deleteTimeoutId = window.setTimeout(() => {
|
||||||
|
deleteFn(questionId);
|
||||||
|
}, DELETE_TIMEOUT);
|
||||||
|
}, {
|
||||||
|
type: "deleteQuestionWithTimeout",
|
||||||
|
questionId,
|
||||||
|
});
|
||||||
|
|
||||||
|
export const cancelQuestionDeletion = (questionId: string) => setProducedState(state => {
|
||||||
|
const question = state.questions.find(q => q.id === questionId);
|
||||||
|
if (!question || question.type === null || question.type === "result") return;
|
||||||
|
|
||||||
|
question.deleted = false;
|
||||||
|
clearTimeout(question.deleteTimeoutId);
|
||||||
|
}, {
|
||||||
|
type: "cancelQuestionDeletion",
|
||||||
|
questionId,
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
const REQUEST_DEBOUNCE = 200;
|
const REQUEST_DEBOUNCE = 200;
|
||||||
const requestQueue = new RequestQueue();
|
const requestQueue = new RequestQueue();
|
||||||
|
Loading…
Reference in New Issue
Block a user