получение списка вопросов на странице редактирование. компонент плюса дерева очищает вопросы и рут квиза
This commit is contained in:
parent
23b8f58520
commit
4d25b72a17
@ -145,8 +145,9 @@ function CsComponent({
|
|||||||
}, [desireToOpenABranchingModal])
|
}, [desireToOpenABranchingModal])
|
||||||
useLayoutEffect(() => {
|
useLayoutEffect(() => {
|
||||||
updateOpenedModalSettingsId()
|
updateOpenedModalSettingsId()
|
||||||
// updateRootContentId(quiz.id, "")
|
console.log("first render CSComponent")
|
||||||
// clearRuleForAll()
|
// updateRootContentId(quiz.id, "")
|
||||||
|
// clearRuleForAll()
|
||||||
}, [])
|
}, [])
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (modalQuestionTargetContentId.length !== 0 && modalQuestionParentContentId.length !== 0) {
|
if (modalQuestionTargetContentId.length !== 0 && modalQuestionParentContentId.length !== 0) {
|
||||||
@ -224,6 +225,7 @@ function CsComponent({
|
|||||||
|
|
||||||
|
|
||||||
const removeNode = ({ targetNodeContentId }: { targetNodeContentId: string }) => {
|
const removeNode = ({ targetNodeContentId }: { targetNodeContentId: string }) => {
|
||||||
|
console.log("старт удаление")
|
||||||
const deleteNodes = [] as string[]
|
const deleteNodes = [] as string[]
|
||||||
const deleteEdges: any = []
|
const deleteEdges: any = []
|
||||||
const cy = cyRef?.current
|
const cy = cyRef?.current
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { Box } from "@mui/material"
|
import { Box } from "@mui/material"
|
||||||
import { useEffect, useRef, useState } from "react";
|
import { useEffect, useRef, useLayoutEffect } from "react";
|
||||||
import { deleteQuestion, updateDragQuestionContentId, updateQuestion } from "@root/questions/actions"
|
import { deleteQuestion, clearRuleForAll, updateQuestion, updateOpenedModalSettingsId } from "@root/questions/actions"
|
||||||
import { updateRootContentId } from "@root/quizes/actions"
|
import { updateRootContentId } from "@root/quizes/actions"
|
||||||
import { useCurrentQuiz } from "@root/quizes/hooks"
|
import { useCurrentQuiz } from "@root/quizes/hooks"
|
||||||
import { useQuestionsStore } from "@root/questions/store"
|
import { useQuestionsStore } from "@root/questions/store"
|
||||||
@ -11,8 +11,17 @@ interface Props {
|
|||||||
modalQuestionTargetContentId: string;
|
modalQuestionTargetContentId: string;
|
||||||
}
|
}
|
||||||
export const FirstNodeField = ({ setOpenedModalQuestions, modalQuestionTargetContentId }: Props) => {
|
export const FirstNodeField = ({ setOpenedModalQuestions, modalQuestionTargetContentId }: Props) => {
|
||||||
|
|
||||||
const quiz = useCurrentQuiz();
|
const quiz = useCurrentQuiz();
|
||||||
|
|
||||||
|
|
||||||
|
useLayoutEffect(() => {
|
||||||
|
updateOpenedModalSettingsId()
|
||||||
|
console.log("first render firstComponent")
|
||||||
|
updateRootContentId(quiz.id, "")
|
||||||
|
clearRuleForAll()
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
|
||||||
const { dragQuestionContentId, questions } = useQuestionsStore()
|
const { dragQuestionContentId, questions } = useQuestionsStore()
|
||||||
const Container = useRef<HTMLDivElement | null>(null);
|
const Container = useRef<HTMLDivElement | null>(null);
|
||||||
|
|
||||||
|
@ -1,13 +1,11 @@
|
|||||||
import { Box } from "@mui/material";
|
import { Box } from "@mui/material";
|
||||||
import { reorderQuestions } from "@root/questions/actions";
|
import { reorderQuestions } from "@root/questions/actions";
|
||||||
import { useQuestions } from "@root/questions/hooks";
|
|
||||||
import type { DropResult } from "react-beautiful-dnd";
|
import type { DropResult } from "react-beautiful-dnd";
|
||||||
import { DragDropContext, Droppable } from "react-beautiful-dnd";
|
import { DragDropContext, Droppable } from "react-beautiful-dnd";
|
||||||
import FormDraggableListItem from "./FormDraggableListItem";
|
import FormDraggableListItem from "./FormDraggableListItem";
|
||||||
|
|
||||||
|
|
||||||
export const FormDraggableList = () => {
|
export const FormDraggableList = () => {
|
||||||
const { questions } = useQuestions();
|
|
||||||
|
|
||||||
const onDragEnd = ({ destination, source }: DropResult) => {
|
const onDragEnd = ({ destination, source }: DropResult) => {
|
||||||
if (destination) reorderQuestions(source.index, destination.index);
|
if (destination) reorderQuestions(source.index, destination.index);
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
|
import { quizApi } from "@api/quiz";
|
||||||
|
import { devlog } from "@frontend/kitui";
|
||||||
import BackArrowIcon from "@icons/BackArrowIcon";
|
import BackArrowIcon from "@icons/BackArrowIcon";
|
||||||
import { Burger } from "@icons/Burger";
|
import { Burger } from "@icons/Burger";
|
||||||
|
import EyeIcon from "@icons/EyeIcon";
|
||||||
import { PenaLogoIcon } from "@icons/PenaLogoIcon";
|
import { PenaLogoIcon } from "@icons/PenaLogoIcon";
|
||||||
import {
|
import {
|
||||||
Box,
|
Box,
|
||||||
@ -11,9 +14,7 @@ import {
|
|||||||
useMediaQuery,
|
useMediaQuery,
|
||||||
useTheme,
|
useTheme,
|
||||||
} from "@mui/material";
|
} from "@mui/material";
|
||||||
import { cleanQuestions, updateOpenBranchingPanel } from "@root/questions/actions";
|
import { decrementCurrentStep, resetEditConfig, setQuizes } from "@root/quizes/actions";
|
||||||
import { useQuestionsStore } from "@root/questions/store";
|
|
||||||
import { decrementCurrentStep, resetEditConfig } from "@root/quizes/actions";
|
|
||||||
import { useCurrentQuiz } from "@root/quizes/hooks";
|
import { useCurrentQuiz } from "@root/quizes/hooks";
|
||||||
import { useQuizStore } from "@root/quizes/store";
|
import { useQuizStore } from "@root/quizes/store";
|
||||||
import CustomAvatar from "@ui_kit/Header/Avatar";
|
import CustomAvatar from "@ui_kit/Header/Avatar";
|
||||||
@ -22,22 +23,46 @@ import PenaLogo from "@ui_kit/PenaLogo";
|
|||||||
import Sidebar from "@ui_kit/Sidebar";
|
import Sidebar from "@ui_kit/Sidebar";
|
||||||
import Stepper from "@ui_kit/Stepper";
|
import Stepper from "@ui_kit/Stepper";
|
||||||
import SwitchStepPages from "@ui_kit/switchStepPages";
|
import SwitchStepPages from "@ui_kit/switchStepPages";
|
||||||
|
import { isAxiosError } from "axios";
|
||||||
|
import { enqueueSnackbar } from "notistack";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { Link, useNavigate } from "react-router-dom";
|
import { Link, useNavigate } from "react-router-dom";
|
||||||
|
import useSWR from "swr";
|
||||||
import { SidebarMobile } from "./Sidebar/SidebarMobile";
|
import { SidebarMobile } from "./Sidebar/SidebarMobile";
|
||||||
|
import {cleanQuestions, updateOpenBranchingPanel} from "@root/questions/actions";
|
||||||
|
import {BranchingPanel} from "../Questions/BranchingPanel";
|
||||||
|
import {setQuestions} from "@root/questions/actions";
|
||||||
|
import {useQuestionsStore} from "@root/questions/store";
|
||||||
|
import { useQuestions } from "@root/questions/hooks";
|
||||||
|
import { questionApi } from "@api/question";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
export default function EditPage() {
|
export default function EditPage() {
|
||||||
// if (isLoading && !questions) return <Box>Загрузка вопросов...</Box>;
|
const quiz = useCurrentQuiz();
|
||||||
|
|
||||||
|
console.log("get questions")
|
||||||
|
useSWR(["questions", quiz?.backendId], ([, id]) => questionApi.getList({ quiz_id: id }), {
|
||||||
|
onSuccess: setQuestions,
|
||||||
|
onError: error => {
|
||||||
|
const message = isAxiosError<string>(error) ? (error.response?.data ?? "") : "";
|
||||||
|
|
||||||
|
devlog("Error getting question list", error);
|
||||||
|
enqueueSnackbar(`Не удалось получить вопросы. ${message}`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
const {openBranchingPanel, questions} = useQuestionsStore.getState()
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const editQuizId = useQuizStore(state => state.editQuizId);
|
const editQuizId = useQuizStore(state => state.editQuizId);
|
||||||
const quiz = useCurrentQuiz();
|
|
||||||
const currentStep = useQuizStore(state => state.currentStep);
|
const currentStep = useQuizStore(state => state.currentStep);
|
||||||
const isTablet = useMediaQuery(theme.breakpoints.down(1000));
|
const isTablet = useMediaQuery(theme.breakpoints.down(1000));
|
||||||
const isMobile = useMediaQuery(theme.breakpoints.down(660));
|
const isMobile = useMediaQuery(theme.breakpoints.down(660));
|
||||||
const [mobileSidebar, setMobileSidebar] = useState<boolean>(false);
|
const [mobileSidebar, setMobileSidebar] = useState<boolean>(false);
|
||||||
const {openBranchingPanel} = useQuestionsStore.getState()
|
|
||||||
const quizConfig = quiz?.config;
|
const quizConfig = quiz?.config;
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
@ -485,6 +485,7 @@ export const updateDragQuestionContentId = (contentId?: string) => {
|
|||||||
|
|
||||||
export const clearRuleForAll = () => {
|
export const clearRuleForAll = () => {
|
||||||
const { questions } = useQuestionsStore.getState();
|
const { questions } = useQuestionsStore.getState();
|
||||||
|
console.log(questions)
|
||||||
questions.forEach(question => {
|
questions.forEach(question => {
|
||||||
if (question.type !== null && (question.content.rule.main.length > 0 || question.content.rule.default.length > 0 || question.content.rule.parentId.length > 0)) {
|
if (question.type !== null && (question.content.rule.main.length > 0 || question.content.rule.default.length > 0 || question.content.rule.parentId.length > 0)) {
|
||||||
updateQuestion(question.content.id, question => {
|
updateQuestion(question.content.id, question => {
|
||||||
|
@ -179,6 +179,7 @@ export const deleteQuiz = async (quizId: string) => requestQueue.enqueue(async (
|
|||||||
export const updateRootContentId = (quizId: string, id:string) => updateQuiz(
|
export const updateRootContentId = (quizId: string, id:string) => updateQuiz(
|
||||||
quizId,
|
quizId,
|
||||||
quiz => {
|
quiz => {
|
||||||
|
console.log("Я изменение статуса корня проекта дерева, меняю на ", id)
|
||||||
quiz.config.haveRoot = id
|
quiz.config.haveRoot = id
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user