обработка пустышек в вопросах АИ
This commit is contained in:
parent
b43ef6d219
commit
b671a85505
@ -2,7 +2,7 @@ import useSWR from "swr";
|
||||
import { getAndParceData } from "./quizRelase";
|
||||
import { useEffect, useState } from "react";
|
||||
import { initDataManager, statusOfQuiz } from "@/utils/hooks/useQuestionFlowControl";
|
||||
import { addQuestions, setQuizData, useQuizStore } from "@/stores/useQuizStore";
|
||||
import { addQuestions, changeNextLoading, setQuizData, useQuizStore } from "@/stores/useQuizStore";
|
||||
|
||||
/*
|
||||
У хука есть три режмиа работы: "line" | "branch" | "ai"
|
||||
@ -74,10 +74,17 @@ export function useQuizData(quizId: string, preview: boolean = false) {
|
||||
limit: 1,
|
||||
needConfig: false,
|
||||
});
|
||||
console.log(
|
||||
"AI RESPONSE AI RESPONSE AI RESPONSE AI RESPONSE AI RESPONSE AI RESPONSE AI RESPONSE AI RESPONSE AI RESPONSE AI RESPONSE AI RESPONSE AI RESPONSE AI RESPONSE AI RESPONSE AI RESPONSE AI RESPONSE AI RESPONSE AI RESPONSE AI RESPONSE AI RESPONSE AI RESPONSE AI RESPONSE AI RESPONSE AI RESPONSE AI RESPONSE AI RESPONSE AI RESPONSE AI RESPONSE AI RESPONSE AI RESPONSE "
|
||||
);
|
||||
console.log(data);
|
||||
addQuestions(data.questions);
|
||||
changeNextLoading(false);
|
||||
return data;
|
||||
} catch (_) {
|
||||
} catch (p) {
|
||||
console.log(p);
|
||||
setPage(questions.length);
|
||||
changeNextLoading(false);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -168,8 +168,10 @@ export async function getAndParceData(props: GetDataProps) {
|
||||
}
|
||||
|
||||
//Парсим строки в строках
|
||||
console.log("до парса_______________________");
|
||||
const quizSettings = replaceSpacesToEmptyLines(parseQuizData(quizDataResponse));
|
||||
|
||||
console.log("после парса_______________________");
|
||||
console.log(quizSettings);
|
||||
//Единоразово стрингифаим ВСЁ распаршенное и удаляем лишние пробелы
|
||||
const res = JSON.parse(
|
||||
JSON.stringify({ data: quizSettings })
|
||||
|
@ -27,6 +27,7 @@ export interface GetQuizDataResponse {
|
||||
}
|
||||
|
||||
export function parseQuizData(quizDataResponse: GetQuizDataResponse): Omit<QuizSettings, "recentlyCompleted"> {
|
||||
console.log(quizDataResponse);
|
||||
const readyData = {
|
||||
cnt: quizDataResponse.cnt,
|
||||
show_badge: quizDataResponse.show_badge,
|
||||
@ -35,8 +36,22 @@ export function parseQuizData(quizDataResponse: GetQuizDataResponse): Omit<QuizS
|
||||
} as QuizSettings;
|
||||
|
||||
const items: QuizSettings["questions"] = quizDataResponse.items.map((item) => {
|
||||
const content = JSON.parse(item.c);
|
||||
|
||||
const content = item.c
|
||||
? JSON.parse(item.c)
|
||||
: {
|
||||
hint: { text: "", video: "" },
|
||||
rule: { children: [], main: [], parentId: "", default: "" },
|
||||
back: "",
|
||||
originalBack: "",
|
||||
autofill: false,
|
||||
placeholder: "",
|
||||
innerNameCheck: false,
|
||||
innerName: "",
|
||||
required: false,
|
||||
answerType: "single",
|
||||
onlyNumbers: false,
|
||||
};
|
||||
if (item.c) content.id = Math.floor(Math.random() * 9999999999) + 1;
|
||||
return {
|
||||
description: item.desc,
|
||||
id: item.id,
|
||||
@ -51,6 +66,7 @@ export function parseQuizData(quizDataResponse: GetQuizDataResponse): Omit<QuizS
|
||||
readyData.questions = items;
|
||||
|
||||
if (quizDataResponse?.settings !== undefined) {
|
||||
console.log("попытка парсануть сеттингс", quizDataResponse.settings);
|
||||
readyData.settings = {
|
||||
fp: quizDataResponse.settings.fp,
|
||||
rep: quizDataResponse.settings.rep,
|
||||
|
@ -13,5 +13,6 @@ const isProduction = !(
|
||||
|
||||
//туризм больше не в исключениях
|
||||
if (!isProduction) domain = "https://s.hbpn.link";
|
||||
domain = "https://hbpn.link";
|
||||
|
||||
export { domain, isProduction };
|
||||
|
@ -44,6 +44,8 @@ export function useAIQuiz() {
|
||||
useEffect(() => {
|
||||
if (currentQuestion.type === "result") showResult();
|
||||
if (currentQuestion) changeNextLoading(false);
|
||||
console.log("questions");
|
||||
console.log(questions);
|
||||
}, [currentQuestion, questions]);
|
||||
|
||||
//Показать визуалом юзеру результат
|
||||
|
Loading…
Reference in New Issue
Block a user