minor changes
This commit is contained in:
parent
a2296190b6
commit
c673b5be9f
@ -1,24 +1,22 @@
|
|||||||
import { devlog } from "@frontend/kitui";
|
import { devlog } from "@frontend/kitui";
|
||||||
import { AnyTypedQuizQuestion } from "@model/questionTypes/shared";
|
import { AnyTypedQuizQuestion } from "@model/questionTypes/shared";
|
||||||
import { Box, Button } from "@mui/material";
|
import { Box, Button } from "@mui/material";
|
||||||
import {
|
import { clearRuleForAll } from "@root/questions/actions";
|
||||||
clearRuleForAll
|
|
||||||
} from "@root/questions/actions";
|
|
||||||
import { useQuestionsStore } from "@root/questions/store";
|
import { useQuestionsStore } from "@root/questions/store";
|
||||||
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 { cleardragQuestionContentId, setModalQuestionParentContentId, setModalQuestionTargetContentId, updateModalInfoWhyCantCreate, updateOpenedModalSettingsId } from "@root/uiTools/actions";
|
import { cleardragQuestionContentId, setModalQuestionParentContentId, setModalQuestionTargetContentId, updateModalInfoWhyCantCreate, updateOpenedModalSettingsId } from "@root/uiTools/actions";
|
||||||
import { useUiTools } from "@root/uiTools/store";
|
import { useUiTools } from "@root/uiTools/store";
|
||||||
import { ProblemIcon } from "@ui_kit/ProblemIcon";
|
import { ProblemIcon } from "@ui_kit/ProblemIcon";
|
||||||
import type { Core, PresetLayoutOptions, SingularData } from "cytoscape";
|
import type { Core } from "cytoscape";
|
||||||
import Cytoscape from "cytoscape";
|
import Cytoscape from "cytoscape";
|
||||||
import popper, { getPopperInstance } from "cytoscape-popper";
|
import popper from "cytoscape-popper";
|
||||||
import { enqueueSnackbar } from "notistack";
|
import { enqueueSnackbar } from "notistack";
|
||||||
import { useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
|
import { useEffect, useLayoutEffect, useMemo, useRef } from "react";
|
||||||
import CytoscapeComponent from "react-cytoscapejs";
|
import CytoscapeComponent from "react-cytoscapejs";
|
||||||
import { withErrorBoundary } from "react-error-boundary";
|
import { withErrorBoundary } from "react-error-boundary";
|
||||||
import { DeleteNodeModal } from "../DeleteNodeModal";
|
import { DeleteNodeModal } from "../DeleteNodeModal";
|
||||||
import { addNode, calcNodePosition, storeToNodes } from "./helper";
|
import { addNode, layoutOptions, storeToNodes } from "./helper";
|
||||||
import { usePopper } from "./hooks/usePopper";
|
import { usePopper } from "./hooks/usePopper";
|
||||||
import { useRemoveNode } from "./hooks/useRemoveNode";
|
import { useRemoveNode } from "./hooks/useRemoveNode";
|
||||||
import "./style/styles.css";
|
import "./style/styles.css";
|
||||||
@ -34,22 +32,16 @@ function CsComponent() {
|
|||||||
const modalQuestionTargetContentId = useUiTools(state => state.modalQuestionTargetContentId);
|
const modalQuestionTargetContentId = useUiTools(state => state.modalQuestionTargetContentId);
|
||||||
const trashQuestions = useQuestionsStore(state => state.questions);
|
const trashQuestions = useQuestionsStore(state => state.questions);
|
||||||
const cyRef = useRef<Core | null>(null);
|
const cyRef = useRef<Core | null>(null);
|
||||||
|
const { recreatePoppers, removeAllPoppers } = usePopper({ cyRef });
|
||||||
const questions = useMemo(() => trashQuestions.filter(
|
const { removeNode } = useRemoveNode({ cyRef });
|
||||||
(question) => question.type !== "result" && question.type !== null
|
|
||||||
), [trashQuestions]);
|
|
||||||
|
|
||||||
const cyElements = useMemo(() => {
|
const cyElements = useMemo(() => {
|
||||||
const q = questions.filter(
|
const questions = trashQuestions.filter(
|
||||||
(question): question is AnyTypedQuizQuestion => question.type !== null && question.type !== "result"
|
(question): question is AnyTypedQuizQuestion => question.type !== null && question.type !== "result"
|
||||||
);
|
);
|
||||||
|
|
||||||
return storeToNodes(q);
|
return storeToNodes(questions);
|
||||||
}, [questions]);
|
}, [trashQuestions]);
|
||||||
|
|
||||||
const { recreatePoppers, removeAllPoppers } = usePopper({ cyRef });
|
|
||||||
|
|
||||||
const { removeNode } = useRemoveNode({ cyRef });
|
|
||||||
|
|
||||||
useLayoutEffect(() => {
|
useLayoutEffect(() => {
|
||||||
const cy = cyRef?.current;
|
const cy = cyRef?.current;
|
||||||
@ -77,10 +69,10 @@ function CsComponent() {
|
|||||||
|
|
||||||
useEffect(function onMount() {
|
useEffect(function onMount() {
|
||||||
updateOpenedModalSettingsId();
|
updateOpenedModalSettingsId();
|
||||||
document.querySelector("#root")?.addEventListener("mouseup", cleardragQuestionContentId);
|
document.addEventListener("pointerup", cleardragQuestionContentId);
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
document.querySelector("#root")?.removeEventListener("mouseup", cleardragQuestionContentId);
|
document.removeEventListener("pointerup", cleardragQuestionContentId);
|
||||||
removeAllPoppers();
|
removeAllPoppers();
|
||||||
};
|
};
|
||||||
}, []);
|
}, []);
|
||||||
@ -179,25 +171,3 @@ export default withErrorBoundary(CsComponent, {
|
|||||||
devlog(error);
|
devlog(error);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const layoutOptions: PresetLayoutOptions = {
|
|
||||||
name: "preset",
|
|
||||||
positions: calcNodePosition,
|
|
||||||
zoom: undefined,
|
|
||||||
pan: 1,
|
|
||||||
fit: false,
|
|
||||||
padding: 30,
|
|
||||||
animate: false,
|
|
||||||
animationDuration: 500,
|
|
||||||
animationEasing: undefined,
|
|
||||||
animateFilter: () => false,
|
|
||||||
ready: event => {
|
|
||||||
if (event.cy.data("firstNode") === "nonroot") {
|
|
||||||
event.cy.data("firstNode", "root");
|
|
||||||
event.cy.nodes().sort((a, b) => (a.data("root") ? 1 : -1));
|
|
||||||
} else {
|
|
||||||
event.cy.removeData("firstNode");
|
|
||||||
}
|
|
||||||
},
|
|
||||||
transform: (_, p) => p,
|
|
||||||
};
|
|
||||||
|
@ -1,14 +1,13 @@
|
|||||||
import { devlog } from "@frontend/kitui";
|
|
||||||
import { QuizQuestionResult } from "@model/questionTypes/result";
|
import { QuizQuestionResult } from "@model/questionTypes/result";
|
||||||
import { AnyTypedQuizQuestion, QuestionBranchingRule, QuestionBranchingRuleMain, UntypedQuizQuestion } from "@model/questionTypes/shared";
|
import { AnyTypedQuizQuestion, QuestionBranchingRule, QuestionBranchingRuleMain, UntypedQuizQuestion } from "@model/questionTypes/shared";
|
||||||
import { Quiz } from "@model/quiz/quiz";
|
|
||||||
import { createResult, getQuestionByContentId, updateQuestion } from "@root/questions/actions";
|
import { createResult, getQuestionByContentId, updateQuestion } from "@root/questions/actions";
|
||||||
import { useQuestionsStore } from "@root/questions/store";
|
import { useQuestionsStore } from "@root/questions/store";
|
||||||
import { updateOpenedModalSettingsId } from "@root/uiTools/actions";
|
import { updateOpenedModalSettingsId } from "@root/uiTools/actions";
|
||||||
import { useUiTools } from "@root/uiTools/store";
|
import { useUiTools } from "@root/uiTools/store";
|
||||||
import { Core } from "cytoscape";
|
import { PresetLayoutOptions } from "cytoscape";
|
||||||
import { enqueueSnackbar } from "notistack";
|
import { enqueueSnackbar } from "notistack";
|
||||||
|
|
||||||
|
|
||||||
interface Nodes {
|
interface Nodes {
|
||||||
data: {
|
data: {
|
||||||
id: string;
|
id: string;
|
||||||
@ -16,6 +15,7 @@ interface Nodes {
|
|||||||
parent?: string;
|
parent?: string;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Edges {
|
interface Edges {
|
||||||
data: {
|
data: {
|
||||||
source: string;
|
source: string;
|
||||||
@ -52,6 +52,28 @@ export const storeToNodes = (questions: AnyTypedQuizQuestion[]) => {
|
|||||||
return [...nodes, ...edges];
|
return [...nodes, ...edges];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const layoutOptions: PresetLayoutOptions = {
|
||||||
|
name: "preset",
|
||||||
|
positions: calcNodePosition,
|
||||||
|
zoom: undefined,
|
||||||
|
pan: 1,
|
||||||
|
fit: false,
|
||||||
|
padding: 30,
|
||||||
|
animate: false,
|
||||||
|
animationDuration: 500,
|
||||||
|
animationEasing: undefined,
|
||||||
|
animateFilter: () => false,
|
||||||
|
ready: event => {
|
||||||
|
if (event.cy.data("firstNode") === "nonroot") {
|
||||||
|
event.cy.data("firstNode", "root");
|
||||||
|
event.cy.nodes().sort((a, b) => (a.data("root") ? 1 : -1));
|
||||||
|
} else {
|
||||||
|
event.cy.removeData("firstNode");
|
||||||
|
}
|
||||||
|
},
|
||||||
|
transform: (_, p) => p,
|
||||||
|
};
|
||||||
|
|
||||||
export function clearDataAfterAddNode({
|
export function clearDataAfterAddNode({
|
||||||
parentNodeContentId,
|
parentNodeContentId,
|
||||||
targetQuestion,
|
targetQuestion,
|
||||||
|
Loading…
Reference in New Issue
Block a user