diff --git a/lib/api/hooks.ts b/lib/api/hooks.ts index 46f124d..41341f6 100644 --- a/lib/api/hooks.ts +++ b/lib/api/hooks.ts @@ -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); } } }, diff --git a/lib/api/quizRelase.ts b/lib/api/quizRelase.ts index b71883b..1101644 100644 --- a/lib/api/quizRelase.ts +++ b/lib/api/quizRelase.ts @@ -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 }) diff --git a/lib/model/api/getQuizData.ts b/lib/model/api/getQuizData.ts index c701641..5ebf629 100644 --- a/lib/model/api/getQuizData.ts +++ b/lib/model/api/getQuizData.ts @@ -27,6 +27,7 @@ export interface GetQuizDataResponse { } export function parseQuizData(quizDataResponse: GetQuizDataResponse): Omit { + console.log(quizDataResponse); const readyData = { cnt: quizDataResponse.cnt, show_badge: quizDataResponse.show_badge, @@ -35,8 +36,22 @@ export function parseQuizData(quizDataResponse: GetQuizDataResponse): Omit { - 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 { if (currentQuestion.type === "result") showResult(); if (currentQuestion) changeNextLoading(false); + console.log("questions"); + console.log(questions); }, [currentQuestion, questions]); //Показать визуалом юзеру результат