функция переключения на графы по нажатию на кнопку ветвление
This commit is contained in:
parent
6d3865d4ec
commit
be79f2fc21
@ -1,7 +1,7 @@
|
|||||||
import { MessageIcon } from "@icons/messagIcon";
|
import { MessageIcon } from "@icons/messagIcon";
|
||||||
import { PointsIcon } from "@icons/questionsPage/PointsIcon";
|
import { PointsIcon } from "@icons/questionsPage/PointsIcon";
|
||||||
import { DeleteIcon } from "@icons/questionsPage/deleteIcon";
|
import { DeleteIcon } from "@icons/questionsPage/deleteIcon";
|
||||||
import { TextareaAutosize } from "@mui/base/TextareaAutosize";
|
import TextareaAutosize from "@mui/base/TextareaAutosize";
|
||||||
import {
|
import {
|
||||||
Box,
|
Box,
|
||||||
FormControl,
|
FormControl,
|
||||||
|
@ -1,15 +1,13 @@
|
|||||||
import { Box, Typography, Switch, useTheme } from "@mui/material";
|
import { Box, Typography, Switch, useTheme } from "@mui/material";
|
||||||
|
|
||||||
import { QuestionsList } from "./QuestionsList";
|
import { QuestionsList } from "./QuestionsList";
|
||||||
|
import { updateOpenBranchingPanel } from "@root/questions/actions";
|
||||||
|
import {useQuestionsStore} from "@root/questions/store";
|
||||||
|
|
||||||
type BranchingPanelProps = {
|
|
||||||
active: boolean;
|
|
||||||
setActive: (active: boolean) => void;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const BranchingPanel = ({ active, setActive }: BranchingPanelProps) => {
|
export const BranchingPanel = () => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
|
const {openBranchingPanel} = useQuestionsStore.getState()
|
||||||
return (
|
return (
|
||||||
<Box sx={{ userSelect: "none", maxWidth: "350px", width: "100%" }}>
|
<Box sx={{ userSelect: "none", maxWidth: "350px", width: "100%" }}>
|
||||||
<Box
|
<Box
|
||||||
@ -24,8 +22,11 @@ export const BranchingPanel = ({ active, setActive }: BranchingPanelProps) => {
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Switch
|
<Switch
|
||||||
value={active}
|
value={openBranchingPanel}
|
||||||
onChange={(_, value) => setTimeout(() => setActive(value), 10)}
|
onChange={(_, value) => {
|
||||||
|
setTimeout(() => updateOpenBranchingPanel(!value), 10)
|
||||||
|
console.log(openBranchingPanel)
|
||||||
|
}}
|
||||||
sx={{
|
sx={{
|
||||||
width: 50,
|
width: 50,
|
||||||
height: 30,
|
height: 30,
|
||||||
@ -79,7 +80,7 @@ export const BranchingPanel = ({ active, setActive }: BranchingPanelProps) => {
|
|||||||
</Typography>
|
</Typography>
|
||||||
</Box>
|
</Box>
|
||||||
</Box>
|
</Box>
|
||||||
{ active && <QuestionsList /> }
|
{ openBranchingPanel === true && <QuestionsList /> }
|
||||||
</Box>
|
</Box>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -11,7 +11,7 @@ import {
|
|||||||
useMediaQuery,
|
useMediaQuery,
|
||||||
useTheme,
|
useTheme,
|
||||||
} from "@mui/material";
|
} from "@mui/material";
|
||||||
import { copyQuestion, deleteQuestion, updateQuestion } from "@root/questions/actions";
|
import {copyQuestion, deleteQuestion, updateOpenBranchingPanel, updateQuestion} 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";
|
||||||
@ -20,6 +20,7 @@ import { HideIcon } from "../../assets/icons/questionsPage/hideIcon";
|
|||||||
import SettingIcon from "../../assets/icons/questionsPage/settingIcon";
|
import SettingIcon from "../../assets/icons/questionsPage/settingIcon";
|
||||||
import type { AnyTypedQuizQuestion } from "../../model/questionTypes/shared";
|
import type { AnyTypedQuizQuestion } from "../../model/questionTypes/shared";
|
||||||
import { updateOpenedModalSettingsId } from "@root/questions/actions";
|
import { updateOpenedModalSettingsId } from "@root/questions/actions";
|
||||||
|
import {enqueueSnackbar} from "notistack";
|
||||||
|
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
@ -42,6 +43,19 @@ export default function ButtonsOptions({
|
|||||||
updateOpenedModalSettingsId(question.id)
|
updateOpenedModalSettingsId(question.id)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleClickBranching = (_, value) => {
|
||||||
|
const parentId = question.content.rule.parentId
|
||||||
|
console.log(parentId)
|
||||||
|
if (parentId.length !== 0) {
|
||||||
|
setTimeout(() => updateOpenBranchingPanel(!value), 10)
|
||||||
|
} else {
|
||||||
|
return enqueueSnackbar("Вопрос не учавствует в ветвлении")
|
||||||
|
}
|
||||||
|
|
||||||
|
if (parentId === "root")
|
||||||
|
return enqueueSnackbar("У корня нет условий ветвления")
|
||||||
|
}
|
||||||
|
|
||||||
const buttonSetting: {
|
const buttonSetting: {
|
||||||
icon: JSX.Element;
|
icon: JSX.Element;
|
||||||
title: string;
|
title: string;
|
||||||
@ -78,7 +92,7 @@ export default function ButtonsOptions({
|
|||||||
),
|
),
|
||||||
title: "Ветвление",
|
title: "Ветвление",
|
||||||
value: "branching",
|
value: "branching",
|
||||||
myFunc: openedModal,
|
myFunc: openedModal, handleClickBranching
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -23,6 +23,9 @@ import ImgIcon from "../../assets/icons/questionsPage/imgIcon";
|
|||||||
import SettingIcon from "../../assets/icons/questionsPage/settingIcon";
|
import SettingIcon from "../../assets/icons/questionsPage/settingIcon";
|
||||||
import { QuizQuestionVariant } from "@model/questionTypes/variant";
|
import { QuizQuestionVariant } from "@model/questionTypes/variant";
|
||||||
import { updateOpenedModalSettingsId } from "@root/questions/actions";
|
import { updateOpenedModalSettingsId } from "@root/questions/actions";
|
||||||
|
import { updateOpenBranchingPanel } from "@root/questions/actions";
|
||||||
|
import {useQuestionsStore} from "@root/questions/store";
|
||||||
|
import { enqueueSnackbar } from "notistack";
|
||||||
|
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
@ -42,6 +45,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 {openBranchingPanel} = useQuestionsStore.getState()
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (question.deleteTimeoutId) {
|
if (question.deleteTimeoutId) {
|
||||||
@ -49,6 +53,19 @@ export default function ButtonsOptionsAndPict({
|
|||||||
}
|
}
|
||||||
}, [question]);
|
}, [question]);
|
||||||
|
|
||||||
|
const handleClickBranching = (_, value) => {
|
||||||
|
const parentId = question.content.rule.parentId
|
||||||
|
console.log(parentId)
|
||||||
|
if (parentId.length !== 0) {
|
||||||
|
setTimeout(() => updateOpenBranchingPanel(!value), 10)
|
||||||
|
} else {
|
||||||
|
return enqueueSnackbar("Вопрос не учавствует в ветвлении")
|
||||||
|
}
|
||||||
|
|
||||||
|
if (parentId === "root")
|
||||||
|
return enqueueSnackbar("У корня нет условий ветвления")
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box
|
<Box
|
||||||
sx={{
|
sx={{
|
||||||
@ -185,6 +202,7 @@ export default function ButtonsOptionsAndPict({
|
|||||||
onMouseLeave={() => setButtonHover("")}
|
onMouseLeave={() => setButtonHover("")}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
updateOpenedModalSettingsId(question.id)
|
updateOpenedModalSettingsId(question.id)
|
||||||
|
handleClickBranching(question.id, openBranchingPanel)
|
||||||
}}
|
}}
|
||||||
sx={{
|
sx={{
|
||||||
height: "30px",
|
height: "30px",
|
||||||
|
@ -5,22 +5,19 @@ import {
|
|||||||
import { DraggableList } from "./DraggableList";
|
import { DraggableList } from "./DraggableList";
|
||||||
import { BranchingPanel } from "./BranchingPanel";
|
import { BranchingPanel } from "./BranchingPanel";
|
||||||
import { BranchingMap } from "./BranchingMap";
|
import { BranchingMap } from "./BranchingMap";
|
||||||
|
import { updateOpenBranchingPanel } from "@root/questions/actions";
|
||||||
|
import {useQuestionsStore} from "@root/questions/store";
|
||||||
|
|
||||||
interface Props {
|
|
||||||
settingBranching: boolean;
|
|
||||||
setSettingBranching: (active: boolean) => void
|
|
||||||
}
|
|
||||||
|
|
||||||
export const QuestionSwitchWindowTool = ({settingBranching, setSettingBranching}:Props) => {
|
|
||||||
|
|
||||||
|
export const QuestionSwitchWindowTool = () => {
|
||||||
|
const {openBranchingPanel} = useQuestionsStore.getState()
|
||||||
return (
|
return (
|
||||||
<Box sx={{ display: "flex", gap: "20px", flexWrap: "wrap" }}>
|
<Box sx={{ display: "flex", gap: "20px", flexWrap: "wrap" }}>
|
||||||
<Box sx={{ flexBasis: "796px" }}>
|
<Box sx={{ flexBasis: "796px" }}>
|
||||||
{settingBranching ? <BranchingMap /> : <DraggableList />}
|
{openBranchingPanel? <BranchingMap /> : <DraggableList />}
|
||||||
</Box>
|
</Box>
|
||||||
<BranchingPanel
|
<BranchingPanel
|
||||||
active={settingBranching}
|
|
||||||
setActive={setSettingBranching}
|
|
||||||
/>
|
/>
|
||||||
</Box>
|
</Box>
|
||||||
)
|
)
|
||||||
|
@ -24,8 +24,7 @@ export default function QuestionsPage() {
|
|||||||
const { openedModalSettingsId } = useQuestionsStore();
|
const { openedModalSettingsId } = useQuestionsStore();
|
||||||
const isMobile = useMediaQuery(theme.breakpoints.down(660));
|
const isMobile = useMediaQuery(theme.breakpoints.down(660));
|
||||||
const quiz = useCurrentQuiz();
|
const quiz = useCurrentQuiz();
|
||||||
|
const openBranchingPanel = useQuestionsStore.getState()
|
||||||
const [settingBranching, setSettingBranching] = useState<boolean>(false);
|
|
||||||
if (!quiz) return null;
|
if (!quiz) return null;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -42,7 +41,7 @@ export default function QuestionsPage() {
|
|||||||
<Typography variant={"h5"}>Заголовок квиза</Typography>
|
<Typography variant={"h5"}>Заголовок квиза</Typography>
|
||||||
<Button
|
<Button
|
||||||
sx={{
|
sx={{
|
||||||
display: settingBranching ? "none" : "flex",
|
display: openBranchingPanel ? "none" : "flex",
|
||||||
fontSize: "16px",
|
fontSize: "16px",
|
||||||
lineHeight: "19px",
|
lineHeight: "19px",
|
||||||
padding: 0,
|
padding: 0,
|
||||||
@ -55,7 +54,7 @@ export default function QuestionsPage() {
|
|||||||
Свернуть всё
|
Свернуть всё
|
||||||
</Button>
|
</Button>
|
||||||
</Box>
|
</Box>
|
||||||
<QuestionSwitchWindowTool settingBranching={settingBranching} setSettingBranching={setSettingBranching} />
|
<QuestionSwitchWindowTool/>
|
||||||
<Box
|
<Box
|
||||||
sx={{
|
sx={{
|
||||||
display: "flex",
|
display: "flex",
|
||||||
|
@ -389,4 +389,5 @@ export const updateOpenedModalSettingsId = (id?: string) => useQuestionsStore.se
|
|||||||
export const updateDragQuestionContentId = (contentId?: string) => {
|
export const updateDragQuestionContentId = (contentId?: string) => {
|
||||||
console.log("contentId " + contentId)
|
console.log("contentId " + contentId)
|
||||||
useQuestionsStore.setState({dragQuestionContentId: contentId ? contentId : null});
|
useQuestionsStore.setState({dragQuestionContentId: contentId ? contentId : null});
|
||||||
}
|
};
|
||||||
|
export const updateOpenBranchingPanel = (value: boolean) => useQuestionsStore.setState({openBranchingPanel: !value});
|
||||||
|
@ -7,12 +7,14 @@ export type QuestionsStore = {
|
|||||||
questions: (AnyTypedQuizQuestion | UntypedQuizQuestion);
|
questions: (AnyTypedQuizQuestion | UntypedQuizQuestion);
|
||||||
openedModalSettingsId: string | null;
|
openedModalSettingsId: string | null;
|
||||||
dragQuestionContentId: string | null;
|
dragQuestionContentId: string | null;
|
||||||
|
openBranchingPanel: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
const initialState: QuestionsStore = {
|
const initialState: QuestionsStore = {
|
||||||
questions: [],
|
questions: [],
|
||||||
openedModalSettingsId: null as null,
|
openedModalSettingsId: null as null,
|
||||||
dragQuestionContentId: null,
|
dragQuestionContentId: null,
|
||||||
|
openBranchingPanel: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useQuestionsStore = create<QuestionsStore>()(
|
export const useQuestionsStore = create<QuestionsStore>()(
|
||||||
|
Loading…
Reference in New Issue
Block a user