refactor: branch store removed

This commit is contained in:
IlyaDoronin 2023-08-28 14:16:00 +03:00
parent 13f0e7fb55
commit a41342097a
3 changed files with 3 additions and 50 deletions

@ -10,7 +10,6 @@ import DeleteIcon from "../../assets/icons/questionsPage/deleteIcon";
import ImgIcon from "../../assets/icons/questionsPage/imgIcon";
import { useParams } from "react-router-dom";
import { questionStore, removeQuestion, resetSomeField } from "@root/questions";
import { branchStore } from "@root/branches";
import "./ButtonsOptionsAndPict.css";
@ -27,7 +26,6 @@ export default function ButtonsOptionsAndPict({
}: Props) {
const params = Number(useParams().quizId);
const { openedModalSettings } = questionStore();
const { branch } = branchStore();
const theme = useTheme();
const openedModal = () => {

@ -1,4 +1,3 @@
import { useEffect } from "react";
import {
Box,
Button,
@ -18,7 +17,6 @@ import {
resetSomeField,
updateQuestionsList,
} from "@root/questions";
import { branchStore, updateBranchState } from "@root/branches";
import { Select } from "./Select";
import DeleteIcon from "@icons/questionsPage/deleteIcon";
@ -42,20 +40,8 @@ export default function BranchingQuestions({
totalIndex,
}: BranchingQuestionsProps) {
const { openedModalSettings, listQuestions } = questionStore();
const { branch } = branchStore();
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 = () => {
resetSomeField({ openedModalSettings: "" });
};
@ -120,7 +106,6 @@ export default function BranchingQuestions({
const clonContent = listQuestions[totalIndex].content;
clonContent.rule.show = action === ACTIONS[0];
updateQuestionsList(totalIndex, { content: clonContent });
updateBranchState({ action });
}}
/>
<Typography sx={{ color: theme.palette.grey2.main }}>
@ -180,7 +165,6 @@ export default function BranchingQuestions({
};
updateQuestionsList(totalIndex, { content: clonContent });
updateBranchState({ stipulation });
}}
sx={{ marginBottom: "15px" }}
/>
@ -225,7 +209,6 @@ export default function BranchingQuestions({
updateQuestionsList(totalIndex, {
content: clonContent,
});
updateBranchState({ answer });
}}
sx={{
marginBottom: "10px",
@ -295,14 +278,13 @@ export default function BranchingQuestions({
<FormControl>
<RadioGroup
aria-labelledby="demo-controlled-radio-buttons-group"
defaultValue={branch.condition === CONDITIONS[0] ? 0 : 1}
defaultValue={
listQuestions[totalIndex].content.rule.or ? 0 : 1
}
onChange={({ target }) => {
const clonContent = listQuestions[totalIndex].content;
clonContent.rule.or = target.value === CONDITIONS[0];
updateQuestionsList(totalIndex, { content: clonContent });
updateBranchState({
condition: CONDITIONS[Number(target.value)],
});
}}
>
{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 } });
};