feat: replaceEmptyLinesToSpace
This commit is contained in:
parent
327bb657f4
commit
5b29c42ac1
@ -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 <T = AnyTypedQuizQuestion>(
|
||||
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);
|
||||
|
||||
33
src/utils/replaceEmptyLinesToSpace.ts
Normal file
33
src/utils/replaceEmptyLinesToSpace.ts
Normal file
@ -0,0 +1,33 @@
|
||||
export const replaceEmptyLinesToSpace = <T = unknown>(object: T): T => {
|
||||
if (Array.isArray(object)) {
|
||||
return object.map(replaceEmptyLinesToSpace) as T;
|
||||
}
|
||||
|
||||
if (!object || typeof object !== "object") {
|
||||
return object;
|
||||
}
|
||||
|
||||
const result: Record<string, unknown> = {};
|
||||
|
||||
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;
|
||||
};
|
||||
Loading…
Reference in New Issue
Block a user