From 327bb657f4de302a7ecf421ab44bd18329d7f26d Mon Sep 17 00:00:00 2001 From: IlyaDoronin Date: Thu, 28 Dec 2023 13:07:50 +0300 Subject: [PATCH 1/3] feat: replaceSpacesToEmptyLines --- src/api/question.ts | 3 ++- src/utils/replaceSpacesToEmptyLines.ts | 29 ++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 src/utils/replaceSpacesToEmptyLines.ts diff --git a/src/api/question.ts b/src/api/question.ts index 56983d76..74a46745 100644 --- a/src/api/question.ts +++ b/src/api/question.ts @@ -5,6 +5,7 @@ import { GetQuestionListRequest, GetQuestionListResponse } from "@model/question import { EditQuestionRequest, EditQuestionResponse } from "@model/question/edit"; import { DeleteQuestionRequest, DeleteQuestionResponse } from "@model/question/delete"; import { CopyQuestionRequest, CopyQuestionResponse } from "@model/question/copy"; +import { replaceSpacesToEmptyLines } from "../utils/replaceSpacesToEmptyLines"; const baseUrl = process.env.NODE_ENV === "production" ? "/squiz" : "https://squiz.pena.digital/squiz"; @@ -26,7 +27,7 @@ async function getQuestionList(body?: Partial) { method: "POST", }); - return response.items; + return replaceSpacesToEmptyLines(response.items); } function editQuestion(body: EditQuestionRequest, signal?: AbortSignal) { diff --git a/src/utils/replaceSpacesToEmptyLines.ts b/src/utils/replaceSpacesToEmptyLines.ts new file mode 100644 index 00000000..e6310b3b --- /dev/null +++ b/src/utils/replaceSpacesToEmptyLines.ts @@ -0,0 +1,29 @@ +export const replaceSpacesToEmptyLines = (object: T): T => { + if (Array.isArray(object)) { + return object.map(replaceSpacesToEmptyLines) as T; + } + + if (!object || typeof object !== "object") { + return object; + } + + const result: Record = {}; + + for (const [key, value] of Object.entries(object)) { + if (typeof value === "string") { + result[key] = value.replace(/ /g, ""); + + continue; + } + + if (typeof value === "object") { + result[key] = replaceSpacesToEmptyLines(value); + + continue; + } + + result[key] = value; + } + + return result as T; +}; From 5b29c42ac1c6fcbc61ab733c0c4bd122defb8689 Mon Sep 17 00:00:00 2001 From: IlyaDoronin Date: Thu, 28 Dec 2023 15:54:04 +0300 Subject: [PATCH 2/3] feat: replaceEmptyLinesToSpace --- src/stores/questions/actions.ts | 3 ++- src/utils/replaceEmptyLinesToSpace.ts | 33 +++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 src/utils/replaceEmptyLinesToSpace.ts 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; +}; From ceaab812a687d7e6935f502ef3c0f2876adb0def Mon Sep 17 00:00:00 2001 From: IlyaDoronin Date: Thu, 28 Dec 2023 17:10:21 +0300 Subject: [PATCH 3/3] fix: publication result logic --- src/pages/ViewPublicationPage/ResultForm.tsx | 113 ++++++++++--------- 1 file changed, 60 insertions(+), 53 deletions(-) diff --git a/src/pages/ViewPublicationPage/ResultForm.tsx b/src/pages/ViewPublicationPage/ResultForm.tsx index fffc3c18..8520f828 100644 --- a/src/pages/ViewPublicationPage/ResultForm.tsx +++ b/src/pages/ViewPublicationPage/ResultForm.tsx @@ -5,9 +5,9 @@ import { useCurrentQuiz } from "@root/quizes/hooks"; import { useQuestionsStore } from "@root/questions/store"; import type { AnyTypedQuizQuestion } from "../../model/questionTypes/shared"; -import YoutubeEmbedIframe from "../../ui_kit/StartPagePreview/YoutubeEmbedIframe.tsx" +import YoutubeEmbedIframe from "../../ui_kit/StartPagePreview/YoutubeEmbedIframe.tsx"; import { NameplateLogo } from "@icons/NameplateLogo"; -import {modes} from "../../utils/themes/Publication/themePublication"; +import { modes } from "../../utils/themes/Publication/themePublication"; type ResultFormProps = { currentQuestion: AnyTypedQuizQuestion; @@ -21,25 +21,25 @@ export const ResultForm = ({ showContactForm, setShowContactForm, setShowResultForm, - }: ResultFormProps) => { const quiz = useCurrentQuiz(); const mode = modes; const { questions } = useQuestionsStore(); - const resultQuestion = questions.find( + const resultQuestion = (questions.find( (question) => question.type === "result" && - (question.content.rule.parentId === "line" || currentQuestion.content.id) - ); - - - + question.content.rule.parentId === currentQuestion.content.id + ) || + questions.find( + (question) => + question.type === "result" && question.content.rule.parentId === "line" + )) as AnyTypedQuizQuestion; const followNextForm = () => { setShowResultForm(false); setShowContactForm(true); }; - if (resultQuestion === undefined) return <> + if (resultQuestion === undefined) return <>; return ( - - { - !resultQuestion?.content.useImage && - resultQuestion.content.video && + {!resultQuestion?.content.useImage && resultQuestion.content.video && ( - } - { - resultQuestion?.content.useImage && - resultQuestion.content.back && + )} + {resultQuestion?.content.useImage && resultQuestion.content.back && ( - - } - {resultQuestion.description !== "" && resultQuestion.description !== " " && {resultQuestion.description}} + > + )} + {resultQuestion.description !== "" && + resultQuestion.description !== " " && ( + + {resultQuestion.description} + + )} {resultQuestion.title || "Форма результатов"} + > + {resultQuestion.title || "Форма результатов"} - {resultQuestion.content.text !== "" && resultQuestion.content.text !== " " && {resultQuestion.content.text}} - - + {resultQuestion.content.text !== "" && + resultQuestion.content.text !== " " && ( + + {resultQuestion.content.text} + + )} @@ -117,24 +120,30 @@ export const ResultForm = ({ display: "flex", width: "100%", justifyContent: "end", - px: "20px" + px: "20px", }} > - Сделано на PenaQuiz + + Сделано на PenaQuiz + - - { - quiz?.config.resultInfo.when === "before" && + {quiz?.config.resultInfo.when === "before" && ( <> - } + )} - - ); };