diff --git a/src/stores/questions/actions.ts b/src/stores/questions/actions.ts index a5dcd65c..eac65731 100644 --- a/src/stores/questions/actions.ts +++ b/src/stores/questions/actions.ts @@ -16,6 +16,7 @@ import { QuestionsStore, useQuestionsStore } from "./store"; import { useUiTools } from "../uiTools/store"; import { withErrorBoundary } from "react-error-boundary"; import { QuizQuestionResult } from "@model/questionTypes/result"; +import { replaceEmptyLinesToSpace } from "../../utils/replaceEmptyLinesToSpace"; export const setQuestions = (questions: RawQuestion[] | null) => setProducedState(state => { @@ -202,7 +203,7 @@ export const updateQuestion = async ( if (q.type === null) throw new Error("Cannot send update request for untyped question"); try { - const response = await questionApi.edit(questionToEditQuestionRequest(q)); + const response = await questionApi.edit(questionToEditQuestionRequest(replaceEmptyLinesToSpace(q))); //Если мы делаем листочек веточкой - удаляем созданный к нему результ const questionResult = useQuestionsStore.getState().questions.find(questionResult => questionResult.type === "result" && questionResult.content.rule.parentId === q.content.id); diff --git a/src/utils/replaceEmptyLinesToSpace.ts b/src/utils/replaceEmptyLinesToSpace.ts new file mode 100644 index 00000000..0ac97782 --- /dev/null +++ b/src/utils/replaceEmptyLinesToSpace.ts @@ -0,0 +1,33 @@ +export const replaceEmptyLinesToSpace = (object: T): T => { + if (Array.isArray(object)) { + return object.map(replaceEmptyLinesToSpace) as T; + } + + if (!object || typeof object !== "object") { + return object; + } + + const result: Record = {}; + + for (const [key, value] of Object.entries(object)) { + if (typeof value === "string") { + if (value === "") { + result[key] = " "; + } else { + result[key] = value; + } + + continue; + } + + if (typeof value === "object") { + result[key] = replaceEmptyLinesToSpace(value); + + continue; + } + + result[key] = value; + } + + return result as T; +};