diff --git a/src/pages/Questions/BranchingMap/CsComponent.tsx b/src/pages/Questions/BranchingMap/CsComponent.tsx index 6d4acac4..84e90793 100644 --- a/src/pages/Questions/BranchingMap/CsComponent.tsx +++ b/src/pages/Questions/BranchingMap/CsComponent.tsx @@ -216,6 +216,7 @@ function CsComponent({ } } + const removeNode = ({ targetNodeContentId }: { targetNodeContentId: string }) => { const deleteNodes = [] as string[] const deleteEdges: any = [] @@ -331,6 +332,7 @@ function CsComponent({ } + useEffect(() => { if (startCreate) { addNode({ parentNodeContentId: startCreate }); @@ -348,7 +350,6 @@ function CsComponent({ const readyLO = (e) => { - console.log('REAdy') if (e.cy.data('firstNode') === 'nonroot') { e.cy.data('firstNode', 'root') e.cy.nodes().sort((a, b) => (a.data('root') ? 1 : -1)).layout(lyopts).run() @@ -433,7 +434,6 @@ function CsComponent({ task.task.forEach(n => { const width = n.data('subtreeWidth') - console.log('ORORORORO', n.data(), yoffset, width, oldPos, task.parent.data('subtreeWidth')) n.data('oldPos', { x: 250 * n.data('layer'), y: yoffset + width / 2 }) yoffset += width queue.push({ task: n.cy().edges(`[source="${n.id()}"]`).targets(), parent: n }) @@ -462,7 +462,6 @@ function CsComponent({ } useEffect(() => { - console.log('KEKEKE') document.querySelector("#root")?.addEventListener("mouseup", cleardragQuestionContentId); const cy = cyRef.current; const eles = cy?.add(storeToNodes(questions.filter((question: AnyTypedQuizQuestion) => (question.type !== "result" && question.type !== null)))) @@ -510,7 +509,6 @@ function CsComponent({ if (!container) { return; } - console.log('POP') container.style.overflow = "hidden"; @@ -540,7 +538,6 @@ function CsComponent({ const bb = n.boundingBox() return bb.x2 > ext.x1 && bb.x1 < ext.x2 && bb.y2 > ext.y1 && bb.y1 < ext.y2 }) - console.log('POPE') nodesInView .toArray() @@ -553,7 +550,6 @@ function CsComponent({ modifiers: [{ name: "flip", options: { boundary: node } }], }, content: ([item]) => { - console.log('POPPER', item.id()) const itemId = item.id(); const itemElement = layoutsContainer.current?.querySelector( `.popper-layout[data-id='${itemId}']` @@ -583,7 +579,6 @@ function CsComponent({ modifiers: [{ name: "flip", options: { boundary: node } }], }, content: ([item]) => { - console.log('POPPER+', item.id()) const itemId = item.id(); const itemElement = plusesContainer.current?.querySelector( `.popper-plus[data-id='${itemId}']` @@ -612,7 +607,6 @@ function CsComponent({ modifiers: [{ name: "flip", options: { boundary: node } }], }, content: ([item]) => { - console.log('POPPERx', item.id()) const itemId = item.id(); const itemElement = crossesContainer.current?.querySelector( `.popper-cross[data-id='${itemId}']` @@ -643,11 +637,7 @@ function CsComponent({ modifiers: [{ name: "flip", options: { boundary: node } }], }, content: ([item]) => { - console.log('POPPERg', item.id()) const itemId = item.id(); - if (item.cy().edges(`[target="${itemId}"]`).sources().length === 0) { - return; - } const itemElement = gearsContainer.current?.querySelector( `.popper-gear[data-id='${itemId}']` @@ -670,7 +660,6 @@ function CsComponent({ }); const update = async () => { - console.log('POPPERi=u', item.id()) await plusesPopper.update(); await crossesPopper.update(); await gearsPopper.update(); @@ -696,6 +685,18 @@ function CsComponent({ { name: "offset", options: { offset: [0, -130 * zoom] } }, ], }); + plusesPopper.setOptions({ + modifiers: [ + { name: "flip", options: { boundary: node } }, + { name: "offset", options: { offset: [0, 0 * zoom] } }, + ], + }); + gearsPopper.setOptions({ + modifiers: [ + { name: "flip", options: { boundary: node } }, + { name: "offset", options: { offset: [0, 0] } }, + ], + }); layoutsContainer.current ?.querySelectorAll("#popper-layouts > .popper-layout") @@ -735,13 +736,13 @@ function CsComponent({ }; //node?.on("position", update); -let pressed = false + let pressed = false let hide = false - cy?.on('mousedown',() => {pressed = true}) - cy?.on('mouseup',() => { + cy?.on('mousedown', () => { pressed = true }) + cy?.on('mouseup', () => { pressed = false hide = false - + const gc = gearsContainer.current if (gc) gc.style.display = 'block' @@ -751,23 +752,23 @@ let pressed = false if (pc) pc.style.display = 'block' if (xc) xc.style.display = 'block' if (lc) lc.style.display = 'block' - update() + update() }) - cy?.on('mousemove',() => { + cy?.on('mousemove', () => { if (pressed && !hide) { hide = true const gc = gearsContainer.current if (gc) gc.style.display = 'none' - const pc = plusesContainer.current - const xc = crossesContainer.current - const lc = layoutsContainer.current - if (pc) pc.style.display = 'none' - if (xc) xc.style.display = 'none' - if (lc) lc.style.display = 'block' + const pc = plusesContainer.current + const xc = crossesContainer.current + const lc = layoutsContainer.current + if (pc) pc.style.display = 'none' + if (xc) xc.style.display = 'none' + if (lc) lc.style.display = 'block' } - }); - + }); + cy?.on("zoom render", onZoom); }); }; @@ -785,7 +786,7 @@ let pressed = false variant="text" onClick={() => { - //код сюда + cyRef.current?.fit() }} > diff --git a/src/pages/Questions/BranchingMap/FirstNodeField.tsx b/src/pages/Questions/BranchingMap/FirstNodeField.tsx index a72ed3c2..4526510a 100644 --- a/src/pages/Questions/BranchingMap/FirstNodeField.tsx +++ b/src/pages/Questions/BranchingMap/FirstNodeField.tsx @@ -1,6 +1,6 @@ import { Box } from "@mui/material" import { useEffect, useRef, useState } from "react"; -import { updateDragQuestionContentId, updateQuestion } from "@root/questions/actions" +import { deleteQuestion, updateDragQuestionContentId, updateQuestion } from "@root/questions/actions" import { updateRootContentId } from "@root/quizes/actions" import { useCurrentQuiz } from "@root/quizes/hooks" import { useQuestionsStore } from "@root/questions/store" @@ -11,8 +11,9 @@ interface Props { modalQuestionTargetContentId: string; } export const FirstNodeField = ({ setOpenedModalQuestions, modalQuestionTargetContentId }: Props) => { + const quiz = useCurrentQuiz(); - const { dragQuestionContentId } = useQuestionsStore() + const { dragQuestionContentId, questions } = useQuestionsStore() const Container = useRef(null); const modalOpen = () => setOpenedModalQuestions(true) @@ -22,6 +23,11 @@ export const FirstNodeField = ({ setOpenedModalQuestions, modalQuestionTargetCon if (dragQuestionContentId) { updateRootContentId(quiz?.id, dragQuestionContentId) updateQuestion(dragQuestionContentId, (question) => question.content.rule.parentId = "root") + //если были результаты - удалить + questions.forEach((q) => { + if (q.type === 'result') deleteQuestion(q.id) + }) + } } else { enqueueSnackbar("Нет информации о взятом опроснике") @@ -44,6 +50,10 @@ export const FirstNodeField = ({ setOpenedModalQuestions, modalQuestionTargetCon if (modalQuestionTargetContentId) { updateRootContentId(quiz?.id, modalQuestionTargetContentId) updateQuestion(modalQuestionTargetContentId, (question) => question.content.rule.parentId = "root") + //если были результаты - удалить + questions.forEach((q) => { + if (q.type === 'result') deleteQuestion(q.id) + }) } } else { enqueueSnackbar("Нет информации о взятом опроснике") diff --git a/src/pages/Questions/ButtonsOptions.tsx b/src/pages/Questions/ButtonsOptions.tsx index 62a776e4..3906d7cb 100644 --- a/src/pages/Questions/ButtonsOptions.tsx +++ b/src/pages/Questions/ButtonsOptions.tsx @@ -11,7 +11,7 @@ import { useMediaQuery, useTheme, } from "@mui/material"; -import { copyQuestion, deleteQuestion, updateOpenBranchingPanel, updateDesireToOpenABranchingModal } from "@root/questions/actions"; +import { copyQuestion, deleteQuestion, updateOpenBranchingPanel, updateDesireToOpenABranchingModal, updateOpenedModalSettingsId, clearRuleForAll } from "@root/questions/actions"; import MiniButtonSetting from "@ui_kit/MiniButtonSetting"; import { CopyIcon } from "../../assets/icons/questionsPage/CopyIcon"; import Branching from "../../assets/icons/questionsPage/branching"; @@ -22,7 +22,7 @@ import type { AnyTypedQuizQuestion } from "../../model/questionTypes/shared"; import { useCurrentQuiz } from "@root/quizes/hooks"; import { enqueueSnackbar } from "notistack"; import { useQuestionsStore } from "@root/questions/store"; -import { updateOpenedModalSettingsId } from "@root/questions/actions"; +import { updateRootContentId } from "@root/quizes/actions"; interface Props { switchState: string; @@ -40,7 +40,7 @@ export default function ButtonsOptions({ const isMobile = useMediaQuery(theme.breakpoints.down(790)); const isWrappMiniButtonSetting = useMediaQuery(theme.breakpoints.down(920)); const quiz = useCurrentQuiz(); - const { openBranchingPanel } = useQuestionsStore.getState() + const { questions } = useQuestionsStore.getState() const openedModal = () => { updateOpenedModalSettingsId(question.id) diff --git a/src/pages/ResultPage/ResultSettings.tsx b/src/pages/ResultPage/ResultSettings.tsx index cc98f79b..1f393426 100644 --- a/src/pages/ResultPage/ResultSettings.tsx +++ b/src/pages/ResultPage/ResultSettings.tsx @@ -33,7 +33,6 @@ export const ResultSettings = () => { isReadyToLeave = false; } }); - console.log(`setting isReadyToLeaveRef to ${isReadyToLeave}`); isReadyToLeaveRef.current = isReadyToLeave; }, [results]) diff --git a/src/pages/ViewPublicationPage/questions/Date.tsx b/src/pages/ViewPublicationPage/questions/Date.tsx index 961a4daa..030621f7 100644 --- a/src/pages/ViewPublicationPage/questions/Date.tsx +++ b/src/pages/ViewPublicationPage/questions/Date.tsx @@ -1,3 +1,4 @@ +import dayjs from "dayjs"; import { DatePicker } from "@mui/x-date-pickers"; import { Box, Typography } from "@mui/material"; @@ -14,10 +15,9 @@ type DateProps = { export const Date = ({ currentQuestion }: DateProps) => { const { answers } = useQuizViewStore(); - const { answer } = - answers.find( - ({ questionId }) => questionId === currentQuestion.content.id - ) ?? {}; + const answer = answers.find( + ({ questionId }) => questionId === currentQuestion.content.id + )?.answer as string; const [day, month, year] = answer?.split(".") || []; return ( @@ -32,50 +32,54 @@ export const Date = ({ currentQuestion }: DateProps) => { }} > , - }} - selected={ + slots={{ + openPickerIcon: () => , + }} + value={dayjs( answer ? new window.Date(`${month}.${day}.${year}`) : new window.Date() - } - onChange={(date) => + )} + onChange={(date) => { + if (!date) { + return; + } + updateAnswer( currentQuestion.content.id, String( - date?.toLocaleDateString("ru-RU", { + new window.Date(date.toDate()).toLocaleDateString("ru-RU", { year: "numeric", month: "2-digit", day: "2-digit", }) ) - ) - } - slotProps={{ - openPickerButton: { - sx: { - p: 0, - }, - "data-cy": "open-datepicker", - }, - }} - sx={{ - "& .MuiInputBase-root": { - backgroundColor: "#F2F3F7", - borderRadius: "10px", - maxWidth: "250px", - pr: "22px", - "& input": { - py: "11px", - pl: "20px", - lineHeight: "19px", - }, - "& fieldset": { - borderColor: "#9A9AAF", - }, - }, - }} + ); + }} + slotProps={{ + openPickerButton: { + sx: { + p: 0, + }, + "data-cy": "open-datepicker", + }, + }} + sx={{ + "& .MuiInputBase-root": { + backgroundColor: "#F2F3F7", + borderRadius: "10px", + maxWidth: "250px", + pr: "22px", + "& input": { + py: "11px", + pl: "20px", + lineHeight: "19px", + }, + "& fieldset": { + borderColor: "#9A9AAF", + }, + }, + }} /> diff --git a/src/pages/ViewPublicationPage/questions/File.tsx b/src/pages/ViewPublicationPage/questions/File.tsx index 82342bc7..bc8a0d0a 100644 --- a/src/pages/ViewPublicationPage/questions/File.tsx +++ b/src/pages/ViewPublicationPage/questions/File.tsx @@ -16,13 +16,18 @@ type FileProps = { export const File = ({ currentQuestion }: FileProps) => { const { answers } = useQuizViewStore(); - const { answer } = answers.find(({ questionId }) => questionId === currentQuestion.content.id) ?? {}; + const answer = answers.find( + ({ questionId }) => questionId === currentQuestion.content.id + )?.answer as string; const uploadFile = ({ target }: ChangeEvent) => { const file = target.files?.[0]; if (file) { - updateAnswer(currentQuestion.content.id, `${file.name}|${URL.createObjectURL(file)}`); + updateAnswer( + currentQuestion.content.id, + `${file.name}|${URL.createObjectURL(file)}` + ); } }; @@ -47,6 +52,28 @@ export const File = ({ currentQuestion }: FileProps) => { /> } text="5 MB максимум" /> + {answer && currentQuestion.content.type === "picture" && ( + + )} + {answer && currentQuestion.content.type === "video" && ( +