refactor: branch store removed
This commit is contained in:
parent
13f0e7fb55
commit
a41342097a
@ -10,7 +10,6 @@ import DeleteIcon from "../../assets/icons/questionsPage/deleteIcon";
|
|||||||
import ImgIcon from "../../assets/icons/questionsPage/imgIcon";
|
import ImgIcon from "../../assets/icons/questionsPage/imgIcon";
|
||||||
import { useParams } from "react-router-dom";
|
import { useParams } from "react-router-dom";
|
||||||
import { questionStore, removeQuestion, resetSomeField } from "@root/questions";
|
import { questionStore, removeQuestion, resetSomeField } from "@root/questions";
|
||||||
import { branchStore } from "@root/branches";
|
|
||||||
|
|
||||||
import "./ButtonsOptionsAndPict.css";
|
import "./ButtonsOptionsAndPict.css";
|
||||||
|
|
||||||
@ -27,7 +26,6 @@ export default function ButtonsOptionsAndPict({
|
|||||||
}: Props) {
|
}: Props) {
|
||||||
const params = Number(useParams().quizId);
|
const params = Number(useParams().quizId);
|
||||||
const { openedModalSettings } = questionStore();
|
const { openedModalSettings } = questionStore();
|
||||||
const { branch } = branchStore();
|
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
|
|
||||||
const openedModal = () => {
|
const openedModal = () => {
|
||||||
|
|||||||
@ -1,4 +1,3 @@
|
|||||||
import { useEffect } from "react";
|
|
||||||
import {
|
import {
|
||||||
Box,
|
Box,
|
||||||
Button,
|
Button,
|
||||||
@ -18,7 +17,6 @@ import {
|
|||||||
resetSomeField,
|
resetSomeField,
|
||||||
updateQuestionsList,
|
updateQuestionsList,
|
||||||
} from "@root/questions";
|
} from "@root/questions";
|
||||||
import { branchStore, updateBranchState } from "@root/branches";
|
|
||||||
import { Select } from "./Select";
|
import { Select } from "./Select";
|
||||||
|
|
||||||
import DeleteIcon from "@icons/questionsPage/deleteIcon";
|
import DeleteIcon from "@icons/questionsPage/deleteIcon";
|
||||||
@ -42,20 +40,8 @@ export default function BranchingQuestions({
|
|||||||
totalIndex,
|
totalIndex,
|
||||||
}: BranchingQuestionsProps) {
|
}: BranchingQuestionsProps) {
|
||||||
const { openedModalSettings, listQuestions } = questionStore();
|
const { openedModalSettings, listQuestions } = questionStore();
|
||||||
const { branch } = branchStore();
|
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
updateBranchState({
|
|
||||||
action: listQuestions[totalIndex].content.rule.show
|
|
||||||
? ACTIONS[0]
|
|
||||||
: ACTIONS[1],
|
|
||||||
condition: listQuestions[totalIndex].content.rule.or
|
|
||||||
? CONDITIONS[0]
|
|
||||||
: CONDITIONS[1],
|
|
||||||
});
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
const handleClose = () => {
|
const handleClose = () => {
|
||||||
resetSomeField({ openedModalSettings: "" });
|
resetSomeField({ openedModalSettings: "" });
|
||||||
};
|
};
|
||||||
@ -120,7 +106,6 @@ export default function BranchingQuestions({
|
|||||||
const clonContent = listQuestions[totalIndex].content;
|
const clonContent = listQuestions[totalIndex].content;
|
||||||
clonContent.rule.show = action === ACTIONS[0];
|
clonContent.rule.show = action === ACTIONS[0];
|
||||||
updateQuestionsList(totalIndex, { content: clonContent });
|
updateQuestionsList(totalIndex, { content: clonContent });
|
||||||
updateBranchState({ action });
|
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<Typography sx={{ color: theme.palette.grey2.main }}>
|
<Typography sx={{ color: theme.palette.grey2.main }}>
|
||||||
@ -180,7 +165,6 @@ export default function BranchingQuestions({
|
|||||||
};
|
};
|
||||||
|
|
||||||
updateQuestionsList(totalIndex, { content: clonContent });
|
updateQuestionsList(totalIndex, { content: clonContent });
|
||||||
updateBranchState({ stipulation });
|
|
||||||
}}
|
}}
|
||||||
sx={{ marginBottom: "15px" }}
|
sx={{ marginBottom: "15px" }}
|
||||||
/>
|
/>
|
||||||
@ -225,7 +209,6 @@ export default function BranchingQuestions({
|
|||||||
updateQuestionsList(totalIndex, {
|
updateQuestionsList(totalIndex, {
|
||||||
content: clonContent,
|
content: clonContent,
|
||||||
});
|
});
|
||||||
updateBranchState({ answer });
|
|
||||||
}}
|
}}
|
||||||
sx={{
|
sx={{
|
||||||
marginBottom: "10px",
|
marginBottom: "10px",
|
||||||
@ -295,14 +278,13 @@ export default function BranchingQuestions({
|
|||||||
<FormControl>
|
<FormControl>
|
||||||
<RadioGroup
|
<RadioGroup
|
||||||
aria-labelledby="demo-controlled-radio-buttons-group"
|
aria-labelledby="demo-controlled-radio-buttons-group"
|
||||||
defaultValue={branch.condition === CONDITIONS[0] ? 0 : 1}
|
defaultValue={
|
||||||
|
listQuestions[totalIndex].content.rule.or ? 0 : 1
|
||||||
|
}
|
||||||
onChange={({ target }) => {
|
onChange={({ target }) => {
|
||||||
const clonContent = listQuestions[totalIndex].content;
|
const clonContent = listQuestions[totalIndex].content;
|
||||||
clonContent.rule.or = target.value === CONDITIONS[0];
|
clonContent.rule.or = target.value === CONDITIONS[0];
|
||||||
updateQuestionsList(totalIndex, { content: clonContent });
|
updateQuestionsList(totalIndex, { content: clonContent });
|
||||||
updateBranchState({
|
|
||||||
condition: CONDITIONS[Number(target.value)],
|
|
||||||
});
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{CONDITIONS.map((condition, index) => (
|
{CONDITIONS.map((condition, index) => (
|
||||||
|
|||||||
@ -1,27 +0,0 @@
|
|||||||
import { create } from "zustand";
|
|
||||||
|
|
||||||
export type Branch = {
|
|
||||||
action: string;
|
|
||||||
stipulation: string;
|
|
||||||
answer: string;
|
|
||||||
condition: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
interface BranchStore {
|
|
||||||
branch: Branch;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const branchStore = create<BranchStore>()(() => ({
|
|
||||||
branch: {
|
|
||||||
action: "",
|
|
||||||
stipulation: "",
|
|
||||||
answer: "",
|
|
||||||
condition: "",
|
|
||||||
},
|
|
||||||
}));
|
|
||||||
|
|
||||||
export const updateBranchState = (data: Partial<Branch>) => {
|
|
||||||
const state = { ...branchStore.getState().branch };
|
|
||||||
|
|
||||||
branchStore.setState({ branch: { ...state, ...data } });
|
|
||||||
};
|
|
||||||
Loading…
Reference in New Issue
Block a user