feat: Default questions
This commit is contained in:
parent
eed127a236
commit
fe641fabae
290
src/constants/questions.dummy.ts
Normal file
290
src/constants/questions.dummy.ts
Normal file
@ -0,0 +1,290 @@
|
||||
import type { AnyTypedQuizQuestion } from "../model/questionTypes/shared";
|
||||
|
||||
export const QUESTIONS_DUMMY: AnyTypedQuizQuestion[] = [
|
||||
{
|
||||
id: "1",
|
||||
title: "",
|
||||
type: "variant",
|
||||
expanded: true,
|
||||
required: false,
|
||||
deleted: false,
|
||||
deleteTimeoutId: 0,
|
||||
backendId: 1111,
|
||||
description: "",
|
||||
openedModalSettings: false,
|
||||
page: 1,
|
||||
quizId: 1,
|
||||
content: {
|
||||
hint: {
|
||||
text: "",
|
||||
video: "",
|
||||
},
|
||||
rule: {
|
||||
main: [],
|
||||
default: "1",
|
||||
},
|
||||
back: "",
|
||||
originalBack: "",
|
||||
autofill: false,
|
||||
largeCheck: false,
|
||||
multi: false,
|
||||
own: false,
|
||||
innerNameCheck: false,
|
||||
required: false,
|
||||
innerName: "",
|
||||
variants: [],
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "2",
|
||||
title: "Вы идёте в школу",
|
||||
type: "page",
|
||||
expanded: true,
|
||||
required: false,
|
||||
deleted: false,
|
||||
deleteTimeoutId: 0,
|
||||
backendId: 1112,
|
||||
description: "",
|
||||
openedModalSettings: false,
|
||||
page: 1,
|
||||
quizId: 1,
|
||||
content: {
|
||||
hint: {
|
||||
text: "",
|
||||
video: "",
|
||||
},
|
||||
rule: {
|
||||
main: [],
|
||||
default: "1",
|
||||
},
|
||||
back: "",
|
||||
originalBack: "",
|
||||
autofill: false,
|
||||
|
||||
innerNameCheck: false,
|
||||
innerName: "",
|
||||
text: "",
|
||||
picture: "",
|
||||
originalPicture: "",
|
||||
video: "",
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "3",
|
||||
title: "Вы немного опоздали, как поступите?",
|
||||
type: "variant",
|
||||
expanded: true,
|
||||
required: true,
|
||||
deleted: false,
|
||||
deleteTimeoutId: 0,
|
||||
backendId: 1113,
|
||||
description: "",
|
||||
openedModalSettings: false,
|
||||
page: 1,
|
||||
quizId: 1,
|
||||
content: {
|
||||
hint: {
|
||||
text: "",
|
||||
video: "",
|
||||
},
|
||||
rule: {
|
||||
main: [],
|
||||
default: "2",
|
||||
},
|
||||
back: "",
|
||||
originalBack: "",
|
||||
autofill: false,
|
||||
largeCheck: false,
|
||||
multi: false,
|
||||
own: false,
|
||||
innerNameCheck: false,
|
||||
required: false,
|
||||
innerName: "",
|
||||
variants: [
|
||||
{
|
||||
id: "answer1",
|
||||
answer: "Извинюсь за опоздание и займу своё место",
|
||||
extendedText: "",
|
||||
hints: "",
|
||||
},
|
||||
{
|
||||
id: "answer2",
|
||||
answer:
|
||||
"Вынесу дверь с ноги и распинав всех направлюсь к месту у розетки",
|
||||
extendedText: "",
|
||||
hints: "",
|
||||
},
|
||||
{
|
||||
id: "answer3",
|
||||
answer: "Влечу в кабинет, пробегу его и выпрыгну в окно",
|
||||
extendedText: "",
|
||||
hints: "",
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "4",
|
||||
title: "Вы открываете дверь кабинета, приготовившись исполнить задуманное",
|
||||
type: "page",
|
||||
expanded: true,
|
||||
required: false,
|
||||
deleted: false,
|
||||
deleteTimeoutId: 0,
|
||||
backendId: 1114,
|
||||
description: "",
|
||||
openedModalSettings: false,
|
||||
page: 1,
|
||||
quizId: 1,
|
||||
content: {
|
||||
hint: {
|
||||
text: "",
|
||||
video: "",
|
||||
},
|
||||
rule: {
|
||||
main: [
|
||||
//момент выбора куда мы пойдём
|
||||
{
|
||||
next: "7",
|
||||
or: true,
|
||||
rules: [
|
||||
{
|
||||
question: "2",
|
||||
answers: ["answer1"],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
next: "6",
|
||||
or: true,
|
||||
rules: [
|
||||
{
|
||||
question: "2",
|
||||
answers: ["answer2"],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
next: "5",
|
||||
or: true,
|
||||
rules: [
|
||||
{
|
||||
question: "2",
|
||||
answers: ["answer3"],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
default: "2",
|
||||
},
|
||||
back: "",
|
||||
originalBack: "",
|
||||
autofill: false,
|
||||
innerNameCheck: false,
|
||||
innerName: "",
|
||||
text: "",
|
||||
picture: "",
|
||||
originalPicture: "",
|
||||
video: "",
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "5",
|
||||
title: "Вы умерли",
|
||||
type: "page",
|
||||
expanded: true,
|
||||
required: false,
|
||||
deleted: false,
|
||||
deleteTimeoutId: 0,
|
||||
backendId: 1115,
|
||||
description: "",
|
||||
openedModalSettings: false,
|
||||
page: 1,
|
||||
quizId: 1,
|
||||
content: {
|
||||
hint: {
|
||||
text: "",
|
||||
video: "",
|
||||
},
|
||||
rule: {
|
||||
main: [],
|
||||
default: "",
|
||||
},
|
||||
back: "",
|
||||
originalBack: "",
|
||||
autofill: false,
|
||||
innerNameCheck: false,
|
||||
innerName: "",
|
||||
text: "",
|
||||
picture: "",
|
||||
originalPicture: "",
|
||||
video: "",
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "6",
|
||||
title: "Вас вызвали к директору",
|
||||
type: "page",
|
||||
expanded: true,
|
||||
required: false,
|
||||
deleted: false,
|
||||
deleteTimeoutId: 0,
|
||||
backendId: 1116,
|
||||
description: "",
|
||||
openedModalSettings: false,
|
||||
page: 1,
|
||||
quizId: 1,
|
||||
content: {
|
||||
hint: {
|
||||
text: "",
|
||||
video: "",
|
||||
},
|
||||
rule: {
|
||||
main: [],
|
||||
default: "",
|
||||
},
|
||||
back: "",
|
||||
originalBack: "",
|
||||
autofill: false,
|
||||
innerNameCheck: false,
|
||||
innerName: "",
|
||||
text: "",
|
||||
picture: "",
|
||||
originalPicture: "",
|
||||
video: "",
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "7",
|
||||
title: "Вы получили отлично",
|
||||
type: "page",
|
||||
expanded: true,
|
||||
required: false,
|
||||
deleted: false,
|
||||
deleteTimeoutId: 0,
|
||||
backendId: 1117,
|
||||
description: "",
|
||||
openedModalSettings: false,
|
||||
page: 1,
|
||||
quizId: 1,
|
||||
content: {
|
||||
hint: {
|
||||
text: "",
|
||||
video: "",
|
||||
},
|
||||
rule: {
|
||||
main: [],
|
||||
default: "",
|
||||
},
|
||||
back: "",
|
||||
originalBack: "",
|
||||
autofill: false,
|
||||
innerNameCheck: false,
|
||||
innerName: "",
|
||||
text: "",
|
||||
picture: "",
|
||||
originalPicture: "",
|
||||
video: "",
|
||||
},
|
||||
},
|
||||
];
|
@ -48,7 +48,7 @@ export type QuestionVariant = {
|
||||
/** Дополнительное поле для текста, emoji, ссылки на картинку */
|
||||
extendedText: string;
|
||||
/** Оригинал изображения (до кропа) */
|
||||
originalImageUrl: string;
|
||||
originalImageUrl?: string;
|
||||
};
|
||||
|
||||
export interface QuizQuestionBase {
|
||||
|
@ -77,7 +77,7 @@ export default function OptionsAndPicture({ question }: Props) {
|
||||
setSelectedVariantId(variant.id);
|
||||
if (variant.extendedText) return openCropModal(
|
||||
variant.extendedText,
|
||||
variant.originalImageUrl
|
||||
variant.originalImageUrl || ""
|
||||
);
|
||||
|
||||
openImageUploadModal();
|
||||
@ -102,7 +102,7 @@ export default function OptionsAndPicture({ question }: Props) {
|
||||
setSelectedVariantId(variant.id);
|
||||
if (variant.extendedText) return openCropModal(
|
||||
variant.extendedText,
|
||||
variant.originalImageUrl
|
||||
variant.originalImageUrl || ""
|
||||
);
|
||||
|
||||
openImageUploadModal();
|
||||
|
@ -68,7 +68,7 @@ export default function OptionsPicture({ question }: Props) {
|
||||
if (variant.extendedText) {
|
||||
return openCropModal(
|
||||
variant.extendedText,
|
||||
variant.originalImageUrl
|
||||
variant.originalImageUrl || ""
|
||||
);
|
||||
}
|
||||
|
||||
@ -95,7 +95,7 @@ export default function OptionsPicture({ question }: Props) {
|
||||
if (variant.extendedText) {
|
||||
return openCropModal(
|
||||
variant.extendedText,
|
||||
variant.originalImageUrl
|
||||
variant.originalImageUrl || ""
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -1,100 +1,121 @@
|
||||
import { useEffect } from "react";
|
||||
import {
|
||||
Box,
|
||||
Button,
|
||||
IconButton,
|
||||
Typography,
|
||||
useMediaQuery,
|
||||
useTheme,
|
||||
Box,
|
||||
Button,
|
||||
IconButton,
|
||||
Typography,
|
||||
useMediaQuery,
|
||||
useTheme,
|
||||
} from "@mui/material";
|
||||
import { collapseAllQuestions, createUntypedQuestion } from "@root/questions/actions";
|
||||
import { decrementCurrentStep, incrementCurrentStep } from "@root/quizes/actions";
|
||||
import {
|
||||
collapseAllQuestions,
|
||||
createUntypedQuestion,
|
||||
} from "@root/questions/actions";
|
||||
import {
|
||||
decrementCurrentStep,
|
||||
incrementCurrentStep,
|
||||
} from "@root/quizes/actions";
|
||||
import { useCurrentQuiz } from "@root/quizes/hooks";
|
||||
import QuizPreview from "@ui_kit/QuizPreview/QuizPreview";
|
||||
import { createPortal } from "react-dom";
|
||||
import AddPlus from "../../assets/icons/questionsPage/addPlus";
|
||||
import ArrowLeft from "../../assets/icons/questionsPage/arrowLeft";
|
||||
import { DraggableList } from "./DraggableList";
|
||||
|
||||
import { setDefaultState } from "@root/questions/actions";
|
||||
|
||||
export default function QuestionsPage() {
|
||||
const theme = useTheme();
|
||||
const isMobile = useMediaQuery(theme.breakpoints.down(660));
|
||||
const quiz = useCurrentQuiz();
|
||||
const theme = useTheme();
|
||||
const isMobile = useMediaQuery(theme.breakpoints.down(660));
|
||||
const quiz = useCurrentQuiz();
|
||||
|
||||
if (!quiz) return null;
|
||||
useEffect(() => {
|
||||
const setDefault = ({ code }: KeyboardEvent) => {
|
||||
if (code === "Backslash") {
|
||||
setDefaultState(Number(quiz?.id));
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<Box
|
||||
sx={{
|
||||
maxWidth: "796px",
|
||||
width: "100%",
|
||||
display: "flex",
|
||||
justifyContent: "space-between",
|
||||
margin: "60px 0 40px 0",
|
||||
}}
|
||||
>
|
||||
<Typography variant={"h5"}>Заголовок квиза</Typography>
|
||||
<Button
|
||||
sx={{
|
||||
fontSize: "16px",
|
||||
lineHeight: "19px",
|
||||
padding: 0,
|
||||
textDecoration: "underline",
|
||||
color: theme.palette.brightPurple.main,
|
||||
textDecorationColor: theme.palette.brightPurple.main,
|
||||
}}
|
||||
onClick={collapseAllQuestions}
|
||||
>
|
||||
Свернуть всё
|
||||
</Button>
|
||||
</Box>
|
||||
<DraggableList />
|
||||
<Box
|
||||
sx={{
|
||||
display: "flex",
|
||||
justifyContent: "space-between",
|
||||
maxWidth: "796px",
|
||||
}}
|
||||
>
|
||||
<IconButton
|
||||
onClick={() => {
|
||||
createUntypedQuestion(quiz.backendId);
|
||||
}}
|
||||
sx={{
|
||||
position: "fixed",
|
||||
left: isMobile ? "20px" : "250px",
|
||||
bottom: "20px",
|
||||
}}
|
||||
data-cy="create-question"
|
||||
>
|
||||
<AddPlus />
|
||||
</IconButton>
|
||||
<Box sx={{ display: "flex", gap: "8px", marginLeft: "auto" }}>
|
||||
<Button
|
||||
variant="outlined"
|
||||
sx={{ padding: "10px 20px", borderRadius: "8px", height: "44px" }}
|
||||
data-cy="back-button"
|
||||
onClick={decrementCurrentStep}
|
||||
>
|
||||
<ArrowLeft />
|
||||
</Button>
|
||||
<Button
|
||||
variant="contained"
|
||||
sx={{
|
||||
height: "44px",
|
||||
padding: "10px 20px",
|
||||
borderRadius: "8px",
|
||||
background: theme.palette.brightPurple.main,
|
||||
fontSize: "18px",
|
||||
}}
|
||||
onClick={incrementCurrentStep}
|
||||
>
|
||||
Следующий шаг
|
||||
</Button>
|
||||
</Box>
|
||||
</Box>
|
||||
{createPortal(<QuizPreview />, document.body)}
|
||||
</>
|
||||
);
|
||||
document.addEventListener("keydown", setDefault);
|
||||
|
||||
return () => {
|
||||
document.removeEventListener("keydown", setDefault);
|
||||
};
|
||||
}, []);
|
||||
|
||||
if (!quiz) return null;
|
||||
|
||||
return (
|
||||
<>
|
||||
<Box
|
||||
sx={{
|
||||
maxWidth: "796px",
|
||||
width: "100%",
|
||||
display: "flex",
|
||||
justifyContent: "space-between",
|
||||
margin: "60px 0 40px 0",
|
||||
}}
|
||||
>
|
||||
<Typography variant={"h5"}>Заголовок квиза</Typography>
|
||||
<Button
|
||||
sx={{
|
||||
fontSize: "16px",
|
||||
lineHeight: "19px",
|
||||
padding: 0,
|
||||
textDecoration: "underline",
|
||||
color: theme.palette.brightPurple.main,
|
||||
textDecorationColor: theme.palette.brightPurple.main,
|
||||
}}
|
||||
onClick={collapseAllQuestions}
|
||||
>
|
||||
Свернуть всё
|
||||
</Button>
|
||||
</Box>
|
||||
<DraggableList />
|
||||
<Box
|
||||
sx={{
|
||||
display: "flex",
|
||||
justifyContent: "space-between",
|
||||
maxWidth: "796px",
|
||||
}}
|
||||
>
|
||||
<IconButton
|
||||
onClick={() => {
|
||||
createUntypedQuestion(quiz.backendId);
|
||||
}}
|
||||
sx={{
|
||||
position: "fixed",
|
||||
left: isMobile ? "20px" : "250px",
|
||||
bottom: "20px",
|
||||
}}
|
||||
data-cy="create-question"
|
||||
>
|
||||
<AddPlus />
|
||||
</IconButton>
|
||||
<Box sx={{ display: "flex", gap: "8px", marginLeft: "auto" }}>
|
||||
<Button
|
||||
variant="outlined"
|
||||
sx={{ padding: "10px 20px", borderRadius: "8px", height: "44px" }}
|
||||
data-cy="back-button"
|
||||
onClick={decrementCurrentStep}
|
||||
>
|
||||
<ArrowLeft />
|
||||
</Button>
|
||||
<Button
|
||||
variant="contained"
|
||||
sx={{
|
||||
height: "44px",
|
||||
padding: "10px 20px",
|
||||
borderRadius: "8px",
|
||||
background: theme.palette.brightPurple.main,
|
||||
fontSize: "18px",
|
||||
}}
|
||||
onClick={incrementCurrentStep}
|
||||
>
|
||||
Следующий шаг
|
||||
</Button>
|
||||
</Box>
|
||||
</Box>
|
||||
{createPortal(<QuizPreview />, document.body)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
@ -1,4 +1,3 @@
|
||||
import { useState } from "react";
|
||||
import DatePicker from "react-datepicker";
|
||||
import { Box, Typography } from "@mui/material";
|
||||
|
||||
@ -14,7 +13,6 @@ type DateProps = {
|
||||
};
|
||||
|
||||
export const Date = ({ stepNumber, question }: DateProps) => {
|
||||
const [startDate, setStartDate] = useState<Date | null>(new window.Date());
|
||||
const { answers } = useQuizViewStore();
|
||||
const { answer } = answers.find(({ step }) => step === stepNumber) ?? {};
|
||||
|
||||
@ -30,8 +28,8 @@ export const Date = ({ stepNumber, question }: DateProps) => {
|
||||
}}
|
||||
>
|
||||
<DatePicker
|
||||
selected={startDate}
|
||||
onChange={(date) => setStartDate(date)}
|
||||
selected={answer ? new window.Date(answer) : new window.Date()}
|
||||
onChange={(date) => updateAnswer(stepNumber, String(date))}
|
||||
/>
|
||||
</Box>
|
||||
</Box>
|
||||
|
@ -79,7 +79,7 @@ export const questionStore = create<QuestionStore>()(
|
||||
if (variant.extendedText.startsWith("blob:")) {
|
||||
variant.extendedText = "";
|
||||
}
|
||||
if (variant.originalImageUrl.startsWith("blob:")) {
|
||||
if (variant.originalImageUrl?.startsWith("blob:")) {
|
||||
variant.originalImageUrl = "";
|
||||
}
|
||||
});
|
||||
@ -89,7 +89,7 @@ export const questionStore = create<QuestionStore>()(
|
||||
if (variant.extendedText.startsWith("blob:")) {
|
||||
variant.extendedText = "";
|
||||
}
|
||||
if (variant.originalImageUrl.startsWith("blob:")) {
|
||||
if (variant.originalImageUrl?.startsWith("blob:")) {
|
||||
variant.originalImageUrl = "";
|
||||
}
|
||||
});
|
||||
@ -181,7 +181,9 @@ export const setVariantOriginalImageUrl = (
|
||||
|
||||
if (variant.originalImageUrl === url) return;
|
||||
|
||||
URL.revokeObjectURL(variant.originalImageUrl);
|
||||
if (variant.originalImageUrl) {
|
||||
URL.revokeObjectURL(variant.originalImageUrl);
|
||||
}
|
||||
variant.originalImageUrl = url;
|
||||
}, {
|
||||
type: "setVariantOriginalImageUrl",
|
||||
|
@ -1,8 +1,17 @@
|
||||
import { questionApi } from "@api/question";
|
||||
import { devlog } from "@frontend/kitui";
|
||||
import { questionToEditQuestionRequest } from "@model/question/edit";
|
||||
import { QuestionType, RawQuestion, rawQuestionToQuestion } from "@model/question/question";
|
||||
import { AnyTypedQuizQuestion, QuestionVariant, UntypedQuizQuestion, createQuestionVariant } from "@model/questionTypes/shared";
|
||||
import {
|
||||
QuestionType,
|
||||
RawQuestion,
|
||||
rawQuestionToQuestion,
|
||||
} from "@model/question/question";
|
||||
import {
|
||||
AnyTypedQuizQuestion,
|
||||
QuestionVariant,
|
||||
UntypedQuizQuestion,
|
||||
createQuestionVariant,
|
||||
} from "@model/questionTypes/shared";
|
||||
import { defaultQuestionByType } from "../../constants/default";
|
||||
import { produce } from "immer";
|
||||
import { nanoid } from "nanoid";
|
||||
@ -10,20 +19,39 @@ import { enqueueSnackbar } from "notistack";
|
||||
import { isAxiosCanceledError } from "../../utils/isAxiosCanceledError";
|
||||
import { RequestQueue } from "../../utils/requestQueue";
|
||||
import { QuestionsStore, useQuestionsStore } from "./store";
|
||||
import { QUESTIONS_DUMMY } from "../../constants/questions.dummy";
|
||||
|
||||
export const setDefaultState = (quizId: number) =>
|
||||
setProducedState(
|
||||
(state) => {
|
||||
QUESTIONS_DUMMY.forEach((question) => {
|
||||
state.questions.push(question);
|
||||
});
|
||||
},
|
||||
{
|
||||
type: "setDefaultState",
|
||||
quizId,
|
||||
}
|
||||
);
|
||||
|
||||
export const setQuestions = (questions: RawQuestion[] | null) => setProducedState(state => {
|
||||
const untypedQuestions = state.questions.filter(q => q.type === null);
|
||||
export const setQuestions = (questions: RawQuestion[] | null) =>
|
||||
setProducedState(
|
||||
(state) => {
|
||||
const untypedQuestions = state.questions.filter((q) => q.type === null);
|
||||
|
||||
state.questions = questions?.map(rawQuestionToQuestion) ?? [];
|
||||
state.questions.push(...untypedQuestions);
|
||||
}, {
|
||||
type: "setQuestions",
|
||||
questions,
|
||||
});
|
||||
state.questions = questions?.map(rawQuestionToQuestion) ?? [];
|
||||
state.questions.push(...untypedQuestions);
|
||||
},
|
||||
{
|
||||
type: "setQuestions",
|
||||
questions,
|
||||
}
|
||||
);
|
||||
|
||||
export const createUntypedQuestion = (quizId: number) => setProducedState(state => {
|
||||
state.questions.push({
|
||||
export const createUntypedQuestion = (quizId: number) =>
|
||||
setProducedState(
|
||||
(state) => {
|
||||
state.questions.push({
|
||||
id: nanoid(),
|
||||
quizId,
|
||||
type: null,
|
||||
@ -31,396 +59,465 @@ export const createUntypedQuestion = (quizId: number) => setProducedState(state
|
||||
description: "",
|
||||
deleted: false,
|
||||
expanded: true,
|
||||
});
|
||||
}, {
|
||||
type: "createUntypedQuestion",
|
||||
quizId,
|
||||
});
|
||||
});
|
||||
},
|
||||
{
|
||||
type: "createUntypedQuestion",
|
||||
quizId,
|
||||
}
|
||||
);
|
||||
|
||||
const removeQuestion = (questionId: string) => setProducedState(state => {
|
||||
const index = state.questions.findIndex(q => q.id === questionId);
|
||||
if (index === -1) return;
|
||||
const removeQuestion = (questionId: string) =>
|
||||
setProducedState(
|
||||
(state) => {
|
||||
const index = state.questions.findIndex((q) => q.id === questionId);
|
||||
if (index === -1) return;
|
||||
|
||||
state.questions.splice(index, 1);
|
||||
}, {
|
||||
type: "removeQuestion",
|
||||
questionId,
|
||||
});
|
||||
state.questions.splice(index, 1);
|
||||
},
|
||||
{
|
||||
type: "removeQuestion",
|
||||
questionId,
|
||||
}
|
||||
);
|
||||
|
||||
export const updateUntypedQuestion = (
|
||||
questionId: string,
|
||||
updateFn: (question: UntypedQuizQuestion) => void,
|
||||
questionId: string,
|
||||
updateFn: (question: UntypedQuizQuestion) => void
|
||||
) => {
|
||||
setProducedState(state => {
|
||||
const question = state.questions.find(q => q.id === questionId);
|
||||
if (!question) return;
|
||||
if (question.type !== null) throw new Error("Cannot update typed question, use 'updateQuestion' instead");
|
||||
setProducedState(
|
||||
(state) => {
|
||||
const question = state.questions.find((q) => q.id === questionId);
|
||||
if (!question) return;
|
||||
if (question.type !== null)
|
||||
throw new Error(
|
||||
"Cannot update typed question, use 'updateQuestion' instead"
|
||||
);
|
||||
|
||||
updateFn(question);
|
||||
}, {
|
||||
type: "updateUntypedQuestion",
|
||||
questionId,
|
||||
updateFn: updateFn.toString(),
|
||||
});
|
||||
updateFn(question);
|
||||
},
|
||||
{
|
||||
type: "updateUntypedQuestion",
|
||||
questionId,
|
||||
updateFn: updateFn.toString(),
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
export const cleanQuestions = () => setProducedState(state => {
|
||||
state.questions = [];
|
||||
}, {
|
||||
type: "cleanQuestions",
|
||||
});
|
||||
export const cleanQuestions = () =>
|
||||
setProducedState(
|
||||
(state) => {
|
||||
state.questions = [];
|
||||
},
|
||||
{
|
||||
type: "cleanQuestions",
|
||||
}
|
||||
);
|
||||
|
||||
const setQuestionBackendId = (questionId: string, backendId: number) => setProducedState(state => {
|
||||
const question = state.questions.find(q => q.id === questionId);
|
||||
if (!question) return;
|
||||
if (question.type === null) throw new Error("Cannot set backend id for untyped question");
|
||||
const setQuestionBackendId = (questionId: string, backendId: number) =>
|
||||
setProducedState(
|
||||
(state) => {
|
||||
const question = state.questions.find((q) => q.id === questionId);
|
||||
if (!question) return;
|
||||
if (question.type === null)
|
||||
throw new Error("Cannot set backend id for untyped question");
|
||||
|
||||
question.backendId = backendId;
|
||||
}, {
|
||||
type: "setQuestionBackendId",
|
||||
questionId: questionId,
|
||||
backendId,
|
||||
});
|
||||
question.backendId = backendId;
|
||||
},
|
||||
{
|
||||
type: "setQuestionBackendId",
|
||||
questionId: questionId,
|
||||
backendId,
|
||||
}
|
||||
);
|
||||
|
||||
export const reorderQuestions = (
|
||||
sourceIndex: number,
|
||||
destinationIndex: number,
|
||||
sourceIndex: number,
|
||||
destinationIndex: number
|
||||
) => {
|
||||
if (sourceIndex === destinationIndex) return;
|
||||
if (sourceIndex === destinationIndex) return;
|
||||
|
||||
setProducedState(state => {
|
||||
const [removed] = state.questions.splice(sourceIndex, 1);
|
||||
state.questions.splice(destinationIndex, 0, removed);
|
||||
}, {
|
||||
type: "reorderQuestions",
|
||||
sourceIndex,
|
||||
destinationIndex,
|
||||
});
|
||||
setProducedState(
|
||||
(state) => {
|
||||
const [removed] = state.questions.splice(sourceIndex, 1);
|
||||
state.questions.splice(destinationIndex, 0, removed);
|
||||
},
|
||||
{
|
||||
type: "reorderQuestions",
|
||||
sourceIndex,
|
||||
destinationIndex,
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
export const toggleExpandQuestion = (questionId: string) => setProducedState(state => {
|
||||
const question = state.questions.find(q => q.id === questionId);
|
||||
if (!question) return;
|
||||
export const toggleExpandQuestion = (questionId: string) =>
|
||||
setProducedState(
|
||||
(state) => {
|
||||
const question = state.questions.find((q) => q.id === questionId);
|
||||
if (!question) return;
|
||||
|
||||
question.expanded = !question.expanded;
|
||||
}, {
|
||||
type: "toggleExpandQuestion",
|
||||
questionId,
|
||||
});
|
||||
|
||||
export const collapseAllQuestions = () => setProducedState(state => {
|
||||
state.questions.forEach(question => question.expanded = false);
|
||||
}, "collapseAllQuestions");
|
||||
question.expanded = !question.expanded;
|
||||
},
|
||||
{
|
||||
type: "toggleExpandQuestion",
|
||||
questionId,
|
||||
}
|
||||
);
|
||||
|
||||
export const collapseAllQuestions = () =>
|
||||
setProducedState((state) => {
|
||||
state.questions.forEach((question) => (question.expanded = false));
|
||||
}, "collapseAllQuestions");
|
||||
|
||||
const REQUEST_DEBOUNCE = 200;
|
||||
const requestQueue = new RequestQueue();
|
||||
let requestTimeoutId: ReturnType<typeof setTimeout>;
|
||||
|
||||
export const updateQuestion = (
|
||||
questionId: string,
|
||||
updateFn: (question: AnyTypedQuizQuestion) => void,
|
||||
questionId: string,
|
||||
updateFn: (question: AnyTypedQuizQuestion) => void
|
||||
) => {
|
||||
setProducedState(state => {
|
||||
const question = state.questions.find(q => q.id === questionId);
|
||||
if (!question) return;
|
||||
if (question.type === null) throw new Error("Cannot update untyped question, use 'updateUntypedQuestion' instead");
|
||||
setProducedState(
|
||||
(state) => {
|
||||
const question = state.questions.find((q) => q.id === questionId);
|
||||
if (!question) return;
|
||||
if (question.type === null)
|
||||
throw new Error(
|
||||
"Cannot update untyped question, use 'updateUntypedQuestion' instead"
|
||||
);
|
||||
|
||||
updateFn(question);
|
||||
}, {
|
||||
type: "updateQuestion",
|
||||
questionId,
|
||||
updateFn: updateFn.toString(),
|
||||
});
|
||||
updateFn(question);
|
||||
},
|
||||
{
|
||||
type: "updateQuestion",
|
||||
questionId,
|
||||
updateFn: updateFn.toString(),
|
||||
}
|
||||
);
|
||||
|
||||
clearTimeout(requestTimeoutId);
|
||||
requestTimeoutId = setTimeout(() => {
|
||||
requestQueue.enqueue(async () => {
|
||||
const q = useQuestionsStore.getState().questions.find(q => q.id === questionId);
|
||||
if (!q) return;
|
||||
if (q.type === null) throw new Error("Cannot send update request for untyped question");
|
||||
clearTimeout(requestTimeoutId);
|
||||
requestTimeoutId = setTimeout(() => {
|
||||
requestQueue
|
||||
.enqueue(async () => {
|
||||
const q = useQuestionsStore
|
||||
.getState()
|
||||
.questions.find((q) => q.id === questionId);
|
||||
if (!q) return;
|
||||
if (q.type === null)
|
||||
throw new Error("Cannot send update request for untyped question");
|
||||
|
||||
const response = await questionApi.edit(questionToEditQuestionRequest(q));
|
||||
const response = await questionApi.edit(
|
||||
questionToEditQuestionRequest(q)
|
||||
);
|
||||
|
||||
setQuestionBackendId(questionId, response.updated);
|
||||
}).catch(error => {
|
||||
if (isAxiosCanceledError(error)) return;
|
||||
setQuestionBackendId(questionId, response.updated);
|
||||
})
|
||||
.catch((error) => {
|
||||
if (isAxiosCanceledError(error)) return;
|
||||
|
||||
devlog("Error editing question", { error, questionId });
|
||||
enqueueSnackbar("Не удалось сохранить вопрос");
|
||||
});
|
||||
}, REQUEST_DEBOUNCE);
|
||||
devlog("Error editing question", { error, questionId });
|
||||
enqueueSnackbar("Не удалось сохранить вопрос");
|
||||
});
|
||||
}, REQUEST_DEBOUNCE);
|
||||
};
|
||||
|
||||
export const addQuestionVariant = (questionId: string) => {
|
||||
updateQuestion(questionId, question => {
|
||||
switch (question.type) {
|
||||
case "variant":
|
||||
case "emoji":
|
||||
case "select":
|
||||
case "images":
|
||||
case "varimg":
|
||||
question.content.variants.push(createQuestionVariant());
|
||||
break;
|
||||
default: throw new Error(`Cannot add variant to question of type "${question.type}"`);
|
||||
}
|
||||
});
|
||||
updateQuestion(questionId, (question) => {
|
||||
switch (question.type) {
|
||||
case "variant":
|
||||
case "emoji":
|
||||
case "select":
|
||||
case "images":
|
||||
case "varimg":
|
||||
question.content.variants.push(createQuestionVariant());
|
||||
break;
|
||||
default:
|
||||
throw new Error(
|
||||
`Cannot add variant to question of type "${question.type}"`
|
||||
);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
export const deleteQuestionVariant = (questionId: string, variantId: string) => {
|
||||
updateQuestion(questionId, question => {
|
||||
if (!("variants" in question.content)) return;
|
||||
export const deleteQuestionVariant = (
|
||||
questionId: string,
|
||||
variantId: string
|
||||
) => {
|
||||
updateQuestion(questionId, (question) => {
|
||||
if (!("variants" in question.content)) return;
|
||||
|
||||
const variantIndex = question.content.variants.findIndex(variant => variant.id === variantId);
|
||||
if (variantIndex === -1) return;
|
||||
const variantIndex = question.content.variants.findIndex(
|
||||
(variant) => variant.id === variantId
|
||||
);
|
||||
if (variantIndex === -1) return;
|
||||
|
||||
question.content.variants.splice(variantIndex, 1);
|
||||
});
|
||||
question.content.variants.splice(variantIndex, 1);
|
||||
});
|
||||
};
|
||||
|
||||
export const setQuestionVariantField = (
|
||||
questionId: string,
|
||||
variantId: string,
|
||||
field: keyof QuestionVariant,
|
||||
value: QuestionVariant[keyof QuestionVariant],
|
||||
questionId: string,
|
||||
variantId: string,
|
||||
field: keyof QuestionVariant,
|
||||
value: QuestionVariant[keyof QuestionVariant]
|
||||
) => {
|
||||
updateQuestion(questionId, question => {
|
||||
if (!("variants" in question.content)) return;
|
||||
updateQuestion(questionId, (question) => {
|
||||
if (!("variants" in question.content)) return;
|
||||
|
||||
const variantIndex = question.content.variants.findIndex(variant => variant.id === variantId);
|
||||
if (variantIndex === -1) return;
|
||||
const variantIndex = question.content.variants.findIndex(
|
||||
(variant) => variant.id === variantId
|
||||
);
|
||||
if (variantIndex === -1) return;
|
||||
|
||||
const variant = question.content.variants[variantIndex];
|
||||
variant[field] = value;
|
||||
});
|
||||
const variant = question.content.variants[variantIndex];
|
||||
|
||||
if (value) {
|
||||
variant[field] = value;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
export const reorderQuestionVariants = (
|
||||
questionId: string,
|
||||
sourceIndex: number,
|
||||
destinationIndex: number,
|
||||
questionId: string,
|
||||
sourceIndex: number,
|
||||
destinationIndex: number
|
||||
) => {
|
||||
if (sourceIndex === destinationIndex) return;
|
||||
if (sourceIndex === destinationIndex) return;
|
||||
|
||||
updateQuestion(questionId, question => {
|
||||
if (!("variants" in question.content)) return;
|
||||
updateQuestion(questionId, (question) => {
|
||||
if (!("variants" in question.content)) return;
|
||||
|
||||
const [removed] = question.content.variants.splice(sourceIndex, 1);
|
||||
question.content.variants.splice(destinationIndex, 0, removed);
|
||||
|
||||
});
|
||||
const [removed] = question.content.variants.splice(sourceIndex, 1);
|
||||
question.content.variants.splice(destinationIndex, 0, removed);
|
||||
});
|
||||
};
|
||||
|
||||
export const setQuestionBackgroundImage = (
|
||||
questionId: string,
|
||||
url: string,
|
||||
) => {
|
||||
updateQuestion(questionId, question => {
|
||||
if (question.content.back === url) return;
|
||||
export const setQuestionBackgroundImage = (questionId: string, url: string) => {
|
||||
updateQuestion(questionId, (question) => {
|
||||
if (question.content.back === url) return;
|
||||
|
||||
if (
|
||||
question.content.back !== question.content.originalBack
|
||||
) URL.revokeObjectURL(question.content.back);
|
||||
question.content.back = url;
|
||||
});
|
||||
if (question.content.back !== question.content.originalBack)
|
||||
URL.revokeObjectURL(question.content.back);
|
||||
question.content.back = url;
|
||||
});
|
||||
};
|
||||
|
||||
export const setQuestionOriginalBackgroundImage = (
|
||||
questionId: string,
|
||||
url: string,
|
||||
questionId: string,
|
||||
url: string
|
||||
) => {
|
||||
updateQuestion(questionId, question => {
|
||||
if (question.content.originalBack === url) return;
|
||||
updateQuestion(questionId, (question) => {
|
||||
if (question.content.originalBack === url) return;
|
||||
|
||||
URL.revokeObjectURL(question.content.originalBack);
|
||||
question.content.originalBack = url;
|
||||
});
|
||||
URL.revokeObjectURL(question.content.originalBack);
|
||||
question.content.originalBack = url;
|
||||
});
|
||||
};
|
||||
|
||||
export const setVariantImageUrl = (
|
||||
questionId: string,
|
||||
variantId: string,
|
||||
url: string,
|
||||
questionId: string,
|
||||
variantId: string,
|
||||
url: string
|
||||
) => {
|
||||
updateQuestion(questionId, question => {
|
||||
if (!("variants" in question.content)) return;
|
||||
updateQuestion(questionId, (question) => {
|
||||
if (!("variants" in question.content)) return;
|
||||
|
||||
const variant = question.content.variants.find(variant => variant.id === variantId);
|
||||
if (!variant) return;
|
||||
const variant = question.content.variants.find(
|
||||
(variant) => variant.id === variantId
|
||||
);
|
||||
if (!variant) return;
|
||||
|
||||
if (variant.extendedText === url) return;
|
||||
if (variant.extendedText === url) return;
|
||||
|
||||
if (variant.extendedText !== variant.originalImageUrl) URL.revokeObjectURL(variant.extendedText);
|
||||
variant.extendedText = url;
|
||||
});
|
||||
if (variant.extendedText !== variant.originalImageUrl)
|
||||
URL.revokeObjectURL(variant.extendedText);
|
||||
variant.extendedText = url;
|
||||
});
|
||||
};
|
||||
|
||||
export const setVariantOriginalImageUrl = (
|
||||
questionId: string,
|
||||
variantId: string,
|
||||
url: string,
|
||||
questionId: string,
|
||||
variantId: string,
|
||||
url: string
|
||||
) => {
|
||||
updateQuestion(questionId, question => {
|
||||
if (!("variants" in question.content)) return;
|
||||
updateQuestion(questionId, (question) => {
|
||||
if (!("variants" in question.content)) return;
|
||||
|
||||
const variant = question.content.variants.find(
|
||||
variant => variant.id === variantId
|
||||
) as QuestionVariant | undefined;
|
||||
if (!variant) return;
|
||||
const variant = question.content.variants.find(
|
||||
(variant) => variant.id === variantId
|
||||
) as QuestionVariant | undefined;
|
||||
if (!variant) return;
|
||||
|
||||
if (variant.originalImageUrl === url) return;
|
||||
if (variant.originalImageUrl === url) return;
|
||||
|
||||
URL.revokeObjectURL(variant.originalImageUrl);
|
||||
variant.originalImageUrl = url;
|
||||
});
|
||||
if (variant.originalImageUrl) {
|
||||
URL.revokeObjectURL(variant.originalImageUrl);
|
||||
}
|
||||
variant.originalImageUrl = url;
|
||||
});
|
||||
};
|
||||
|
||||
export const setPageQuestionPicture = (
|
||||
questionId: string,
|
||||
url: string,
|
||||
) => {
|
||||
updateQuestion(questionId, question => {
|
||||
if (question.type !== "page") return;
|
||||
export const setPageQuestionPicture = (questionId: string, url: string) => {
|
||||
updateQuestion(questionId, (question) => {
|
||||
if (question.type !== "page") return;
|
||||
|
||||
if (question.content.picture === url) return;
|
||||
if (question.content.picture === url) return;
|
||||
|
||||
if (
|
||||
question.content.picture !== question.content.originalPicture
|
||||
) URL.revokeObjectURL(question.content.picture);
|
||||
question.content.picture = url;
|
||||
});
|
||||
if (question.content.picture !== question.content.originalPicture)
|
||||
URL.revokeObjectURL(question.content.picture);
|
||||
question.content.picture = url;
|
||||
});
|
||||
};
|
||||
|
||||
export const setPageQuestionOriginalPicture = (
|
||||
questionId: string,
|
||||
url: string,
|
||||
questionId: string,
|
||||
url: string
|
||||
) => {
|
||||
updateQuestion(questionId, question => {
|
||||
if (question.type !== "page") return;
|
||||
updateQuestion(questionId, (question) => {
|
||||
if (question.type !== "page") return;
|
||||
|
||||
if (question.content.originalPicture === url) return;
|
||||
if (question.content.originalPicture === url) return;
|
||||
|
||||
URL.revokeObjectURL(question.content.originalPicture);
|
||||
question.content.originalPicture = url;
|
||||
});
|
||||
URL.revokeObjectURL(question.content.originalPicture);
|
||||
question.content.originalPicture = url;
|
||||
});
|
||||
};
|
||||
|
||||
export const setQuestionInnerName = (
|
||||
questionId: string,
|
||||
name: string,
|
||||
) => {
|
||||
updateQuestion(questionId, question => {
|
||||
question.content.innerName = name;
|
||||
});
|
||||
export const setQuestionInnerName = (questionId: string, name: string) => {
|
||||
updateQuestion(questionId, (question) => {
|
||||
question.content.innerName = name;
|
||||
});
|
||||
};
|
||||
|
||||
export const changeQuestionType = (
|
||||
questionId: string,
|
||||
type: QuestionType,
|
||||
) => {
|
||||
updateQuestion(questionId, question => {
|
||||
question.type = type;
|
||||
question.content = defaultQuestionByType[type].content;
|
||||
});
|
||||
export const changeQuestionType = (questionId: string, type: QuestionType) => {
|
||||
updateQuestion(questionId, (question) => {
|
||||
question.type = type;
|
||||
question.content = defaultQuestionByType[type].content;
|
||||
});
|
||||
};
|
||||
|
||||
export const createTypedQuestion = async (
|
||||
questionId: string,
|
||||
type: QuestionType,
|
||||
) => requestQueue.enqueue(async () => {
|
||||
const question = useQuestionsStore.getState().questions.find(q => q.id === questionId);
|
||||
questionId: string,
|
||||
type: QuestionType
|
||||
) =>
|
||||
requestQueue.enqueue(async () => {
|
||||
const question = useQuestionsStore
|
||||
.getState()
|
||||
.questions.find((q) => q.id === questionId);
|
||||
if (!question) return;
|
||||
if (question.type !== null) throw new Error("Cannot upgrade already typed question");
|
||||
if (question.type !== null)
|
||||
throw new Error("Cannot upgrade already typed question");
|
||||
|
||||
try {
|
||||
const createdQuestion = await questionApi.create({
|
||||
quiz_id: question.quizId,
|
||||
type,
|
||||
title: question.title,
|
||||
description: question.description,
|
||||
page: 0,
|
||||
required: true,
|
||||
content: JSON.stringify(defaultQuestionByType[type].content),
|
||||
});
|
||||
const createdQuestion = await questionApi.create({
|
||||
quiz_id: question.quizId,
|
||||
type,
|
||||
title: question.title,
|
||||
description: question.description,
|
||||
page: 0,
|
||||
required: true,
|
||||
content: JSON.stringify(defaultQuestionByType[type].content),
|
||||
});
|
||||
|
||||
setProducedState(state => {
|
||||
const questionIndex = state.questions.findIndex(q => q.id === questionId);
|
||||
if (questionIndex !== -1) state.questions.splice(
|
||||
questionIndex,
|
||||
1,
|
||||
rawQuestionToQuestion(createdQuestion)
|
||||
setProducedState(
|
||||
(state) => {
|
||||
const questionIndex = state.questions.findIndex(
|
||||
(q) => q.id === questionId
|
||||
);
|
||||
if (questionIndex !== -1)
|
||||
state.questions.splice(
|
||||
questionIndex,
|
||||
1,
|
||||
rawQuestionToQuestion(createdQuestion)
|
||||
);
|
||||
}, {
|
||||
type: "createTypedQuestion",
|
||||
question,
|
||||
});
|
||||
},
|
||||
{
|
||||
type: "createTypedQuestion",
|
||||
question,
|
||||
}
|
||||
);
|
||||
} catch (error) {
|
||||
devlog("Error creating question", error);
|
||||
enqueueSnackbar("Не удалось создать вопрос");
|
||||
devlog("Error creating question", error);
|
||||
enqueueSnackbar("Не удалось создать вопрос");
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
export const deleteQuestion = async (questionId: string) => requestQueue.enqueue(async () => {
|
||||
const question = useQuestionsStore.getState().questions.find(q => q.id === questionId);
|
||||
export const deleteQuestion = async (questionId: string) =>
|
||||
requestQueue.enqueue(async () => {
|
||||
const question = useQuestionsStore
|
||||
.getState()
|
||||
.questions.find((q) => q.id === questionId);
|
||||
if (!question) return;
|
||||
|
||||
if (question.type === null) {
|
||||
removeQuestion(questionId);
|
||||
return;
|
||||
removeQuestion(questionId);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
await questionApi.delete(question.backendId);
|
||||
await questionApi.delete(question.backendId);
|
||||
|
||||
removeQuestion(questionId);
|
||||
removeQuestion(questionId);
|
||||
} catch (error) {
|
||||
devlog("Error deleting question", error);
|
||||
enqueueSnackbar("Не удалось удалить вопрос");
|
||||
devlog("Error deleting question", error);
|
||||
enqueueSnackbar("Не удалось удалить вопрос");
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
export const copyQuestion = async (questionId: string, quizId: number) => requestQueue.enqueue(async () => {
|
||||
const question = useQuestionsStore.getState().questions.find(q => q.id === questionId);
|
||||
export const copyQuestion = async (questionId: string, quizId: number) =>
|
||||
requestQueue.enqueue(async () => {
|
||||
const question = useQuestionsStore
|
||||
.getState()
|
||||
.questions.find((q) => q.id === questionId);
|
||||
if (!question) return;
|
||||
|
||||
if (question.type === null) {
|
||||
const copiedQuestion = structuredClone(question);
|
||||
copiedQuestion.id = nanoid();
|
||||
const copiedQuestion = structuredClone(question);
|
||||
copiedQuestion.id = nanoid();
|
||||
|
||||
setProducedState(state => {
|
||||
state.questions.push(copiedQuestion);
|
||||
}, {
|
||||
type: "copyQuestion",
|
||||
questionId,
|
||||
quizId,
|
||||
});
|
||||
setProducedState(
|
||||
(state) => {
|
||||
state.questions.push(copiedQuestion);
|
||||
},
|
||||
{
|
||||
type: "copyQuestion",
|
||||
questionId,
|
||||
quizId,
|
||||
}
|
||||
);
|
||||
|
||||
return;
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const { updated: newQuestionId } = await questionApi.copy(question.backendId, quizId);
|
||||
const { updated: newQuestionId } = await questionApi.copy(
|
||||
question.backendId,
|
||||
quizId
|
||||
);
|
||||
|
||||
const copiedQuestion = structuredClone(question);
|
||||
copiedQuestion.backendId = newQuestionId;
|
||||
copiedQuestion.id = nanoid();
|
||||
const copiedQuestion = structuredClone(question);
|
||||
copiedQuestion.backendId = newQuestionId;
|
||||
copiedQuestion.id = nanoid();
|
||||
|
||||
setProducedState(state => {
|
||||
state.questions.push(copiedQuestion);
|
||||
}, {
|
||||
type: "copyQuestion",
|
||||
questionId,
|
||||
quizId,
|
||||
});
|
||||
setProducedState(
|
||||
(state) => {
|
||||
state.questions.push(copiedQuestion);
|
||||
},
|
||||
{
|
||||
type: "copyQuestion",
|
||||
questionId,
|
||||
quizId,
|
||||
}
|
||||
);
|
||||
} catch (error) {
|
||||
devlog("Error copying question", error);
|
||||
enqueueSnackbar("Не удалось скопировать вопрос");
|
||||
devlog("Error copying question", error);
|
||||
enqueueSnackbar("Не удалось скопировать вопрос");
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
function setProducedState<A extends string | { type: unknown; }>(
|
||||
recipe: (state: QuestionsStore) => void,
|
||||
action?: A,
|
||||
function setProducedState<A extends string | { type: unknown }>(
|
||||
recipe: (state: QuestionsStore) => void,
|
||||
action?: A
|
||||
) {
|
||||
useQuestionsStore.setState(state => produce(state, recipe), false, action);
|
||||
useQuestionsStore.setState((state) => produce(state, recipe), false, action);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user