analytica-frontend-lib 1.1.14 → 1.1.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1349,12 +1349,12 @@ var useQuizStore = create2()(
1349
1349
  return unansweredQuestions;
1350
1350
  },
1351
1351
  getQuestionsGroupedBySubject: () => {
1352
- const { getActiveQuiz } = get();
1353
- const activeQuiz = getActiveQuiz();
1354
- if (!activeQuiz) return {};
1352
+ const { getQuestionResult, getActiveQuiz, variant } = get();
1353
+ const questions = variant == "result" ? getQuestionResult()?.answers : getActiveQuiz()?.quiz.questions;
1354
+ if (!questions) return {};
1355
1355
  const groupedQuestions = {};
1356
- activeQuiz.quiz.questions.forEach((question) => {
1357
- const subjectId = question.knowledgeMatrix?.[0]?.subjectId || "Sem mat\xE9ria";
1356
+ questions.forEach((question) => {
1357
+ const subjectId = question.knowledgeMatrix?.[0]?.subject?.id || "Sem mat\xE9ria";
1358
1358
  if (!groupedQuestions[subjectId]) {
1359
1359
  groupedQuestions[subjectId] = [];
1360
1360
  }
@@ -1388,12 +1388,22 @@ var useQuizStore = create2()(
1388
1388
  return userAnswers;
1389
1389
  },
1390
1390
  setCurrentQuestion: (question) => {
1391
- const { getActiveQuiz } = get();
1391
+ const { getActiveQuiz, variant, questionsResult } = get();
1392
1392
  const activeQuiz = getActiveQuiz();
1393
1393
  if (!activeQuiz) return;
1394
- const questionIndex = activeQuiz.quiz.questions.findIndex(
1395
- (q) => q.id === question.id
1396
- );
1394
+ let questionIndex = 0;
1395
+ if (variant == "result") {
1396
+ if (!questionsResult) return;
1397
+ const questionResult = questionsResult.answers.find((q) => q.id === question.id) ?? questionsResult.answers.find((q) => q.questionId === question.id);
1398
+ if (!questionResult) return;
1399
+ questionIndex = activeQuiz.quiz.questions.findIndex(
1400
+ (q) => q.id === questionResult.questionId
1401
+ );
1402
+ } else {
1403
+ questionIndex = activeQuiz.quiz.questions.findIndex(
1404
+ (q) => q.id === question.id
1405
+ );
1406
+ }
1397
1407
  if (questionIndex === -1) {
1398
1408
  console.warn(
1399
1409
  `Question with id "${question.id}" not found in active quiz`
@@ -1424,20 +1434,23 @@ var useQuizStore = create2()(
1424
1434
  return userAnswer ? userAnswer.answerStatus : null;
1425
1435
  },
1426
1436
  getQuestionIndex: (questionId) => {
1427
- const { getActiveQuiz } = get();
1428
- const activeQuiz = getActiveQuiz();
1429
- if (!activeQuiz) return 0;
1430
- const questionIndex = activeQuiz.quiz.questions.findIndex(
1431
- (q) => q.id === questionId
1437
+ const { questionsResult } = get();
1438
+ if (!questionsResult) return 0;
1439
+ let idx = questionsResult.answers.findIndex(
1440
+ (q) => q.questionId === questionId
1432
1441
  );
1433
- return questionIndex + 1;
1442
+ if (idx === -1) {
1443
+ idx = questionsResult.answers.findIndex((q) => q.id === questionId);
1444
+ }
1445
+ return idx !== -1 ? idx + 1 : 0;
1434
1446
  },
1435
1447
  // Question Result
1436
1448
  getQuestionResultByQuestionId: (questionId) => {
1437
1449
  const { questionsResult } = get();
1438
- return questionsResult?.answers.find(
1450
+ const question = questionsResult?.answers.find(
1439
1451
  (answer) => answer.questionId === questionId
1440
- ) || null;
1452
+ );
1453
+ return question || null;
1441
1454
  },
1442
1455
  getQuestionResultStatistics: () => {
1443
1456
  const { questionsResult } = get();
@@ -4690,8 +4703,8 @@ var QuizHeader = () => {
4690
4703
  HeaderAlternative,
4691
4704
  {
4692
4705
  title: currentQuestion ? `Quest\xE3o ${currentQuestionIndex + 1}` : "Quest\xE3o",
4693
- subTitle: currentQuestion?.knowledgeMatrix?.[0]?.topicId ?? "",
4694
- content: currentQuestion?.questionText ?? ""
4706
+ subTitle: currentQuestion?.knowledgeMatrix?.[0]?.topic?.name ?? "",
4707
+ content: currentQuestion?.statement ?? ""
4695
4708
  }
4696
4709
  );
4697
4710
  };
@@ -4740,10 +4753,10 @@ var QuizAlternative = ({ paddingBottom }) => {
4740
4753
  const alternatives = currentQuestion?.options?.map((option) => {
4741
4754
  let status = "neutral" /* NEUTRAL */;
4742
4755
  if (variant === "result") {
4743
- const isCorrectOption = currentQuestion.correctOptionIds?.includes(
4744
- option.id
4756
+ const isCorrectOption = currentQuestionResult?.options?.find((op) => op.id === option.id)?.isCorrect || false;
4757
+ const isSelected = currentQuestionResult?.selectedOptions.some(
4758
+ (selectedOption) => selectedOption.optionId === option.id
4745
4759
  );
4746
- const isSelected = currentQuestionResult?.optionId === option.id;
4747
4760
  if (isCorrectOption) {
4748
4761
  status = "correct" /* CORRECT */;
4749
4762
  } else if (isSelected && !isCorrectOption) {
@@ -4769,8 +4782,8 @@ var QuizAlternative = ({ paddingBottom }) => {
4769
4782
  name: `question-${currentQuestion?.id || "1"}`,
4770
4783
  layout: "compact",
4771
4784
  alternatives,
4772
- value: variant === "result" ? currentQuestionResult?.optionId || "" : currentAnswer?.optionId || "",
4773
- selectedValue: variant === "result" ? currentQuestionResult?.optionId || "" : currentAnswer?.optionId || "",
4785
+ value: variant === "result" ? currentQuestionResult?.selectedOptions[0]?.optionId || "" : currentAnswer?.optionId || "",
4786
+ selectedValue: variant === "result" ? currentQuestionResult?.selectedOptions[0]?.optionId || "" : currentAnswer?.optionId || "",
4774
4787
  onValueChange: (value) => {
4775
4788
  if (currentQuestion) {
4776
4789
  selectAnswer(currentQuestion.id, value);
@@ -4815,15 +4828,16 @@ var QuizMultipleChoice = ({ paddingBottom }) => {
4815
4828
  prevSelectedValuesRef.current = selectedValues;
4816
4829
  return selectedValues;
4817
4830
  }
4818
- if (variant == "result" && currentQuestionResult?.options.length && currentQuestionResult?.options.length > 0) {
4819
- return currentQuestionResult?.options.map((op) => op.id) || [];
4831
+ if (variant == "result") {
4832
+ return currentQuestionResult?.selectedOptions.map((op) => op.optionId) || [];
4833
+ } else {
4834
+ return prevSelectedValuesRef.current;
4820
4835
  }
4821
- return prevSelectedValuesRef.current;
4822
4836
  }, [
4823
4837
  selectedValues,
4824
4838
  currentQuestion?.id,
4825
4839
  variant,
4826
- currentQuestionResult?.optionId
4840
+ currentQuestionResult?.selectedOptions
4827
4841
  ]);
4828
4842
  const handleSelectedValues = useCallback(
4829
4843
  (values) => {
@@ -4840,11 +4854,9 @@ var QuizMultipleChoice = ({ paddingBottom }) => {
4840
4854
  const choices = currentQuestion?.options?.map((option) => {
4841
4855
  let status = "neutral" /* NEUTRAL */;
4842
4856
  if (variant === "result") {
4843
- const isCorrectOption = currentQuestion.correctOptionIds?.includes(
4844
- option.id
4845
- );
4846
- const isSelected = currentQuestionResult?.options.find(
4847
- (op) => op.id === option.id
4857
+ const isCorrectOption = currentQuestionResult?.options?.find((op) => op.id === option.id)?.isCorrect || false;
4858
+ const isSelected = currentQuestionResult?.selectedOptions?.some(
4859
+ (op) => op.optionId === option.id
4848
4860
  );
4849
4861
  if (isCorrectOption) {
4850
4862
  status = "correct" /* CORRECT */;
@@ -5120,7 +5132,7 @@ var QuizConnectDots = ({ paddingBottom }) => {
5120
5132
  }) }) })
5121
5133
  ] });
5122
5134
  };
5123
- var QuizFill = ({ paddingBottom = "pb-[80px]" }) => {
5135
+ var QuizFill = ({ paddingBottom }) => {
5124
5136
  const { variant } = useQuizStore();
5125
5137
  const options = [
5126
5138
  "ci\xEAncia",
@@ -5478,7 +5490,7 @@ var QuizQuestionList = ({
5478
5490
  ([subjectId, questions]) => /* @__PURE__ */ jsxs14("section", { className: "flex flex-col gap-2", children: [
5479
5491
  /* @__PURE__ */ jsxs14("span", { className: "pt-6 pb-4 flex flex-row gap-2", children: [
5480
5492
  /* @__PURE__ */ jsx17("div", { className: "bg-primary-500 p-1 rounded-sm flex items-center justify-center", children: /* @__PURE__ */ jsx17(BookOpen, { size: 17, className: "text-white" }) }),
5481
- /* @__PURE__ */ jsx17("p", { className: "text-text-800 font-bold text-lg", children: subjectId })
5493
+ /* @__PURE__ */ jsx17("p", { className: "text-text-800 font-bold text-lg", children: questions?.[0]?.knowledgeMatrix?.[0]?.subject?.name ?? "Sem mat\xE9ria" })
5482
5494
  ] }),
5483
5495
  /* @__PURE__ */ jsx17("ul", { className: "flex flex-col gap-2", children: questions.map((question) => {
5484
5496
  const status = getQuestionStatus(question.id);
@@ -5909,28 +5921,24 @@ var QuizResultPerformance = forwardRef10(
5909
5921
  }
5910
5922
  );
5911
5923
  var QuizListResult = forwardRef10(({ className, onSubjectClick, ...props }, ref) => {
5912
- const {
5913
- getQuestionsGroupedBySubject,
5914
- isQuestionAnswered,
5915
- getUserAnswerByQuestionId
5916
- } = useQuizStore();
5924
+ const { getQuestionsGroupedBySubject } = useQuizStore();
5917
5925
  const groupedQuestions = getQuestionsGroupedBySubject();
5918
5926
  const subjectsStats = Object.entries(groupedQuestions).map(
5919
5927
  ([subjectId, questions]) => {
5920
5928
  let correct = 0;
5921
5929
  let incorrect = 0;
5922
5930
  questions.forEach((question) => {
5923
- if (isQuestionAnswered(question.id)) {
5924
- const userAnswerItem = getUserAnswerByQuestionId(question.id);
5925
- if (userAnswerItem?.answerStatus == "RESPOSTA_CORRETA" /* RESPOSTA_CORRETA */) {
5926
- correct++;
5927
- } else {
5928
- incorrect++;
5929
- }
5931
+ if (question.answerStatus == "RESPOSTA_CORRETA" /* RESPOSTA_CORRETA */) {
5932
+ correct++;
5933
+ } else {
5934
+ incorrect++;
5930
5935
  }
5931
5936
  });
5932
5937
  return {
5933
- subject: subjectId,
5938
+ subject: {
5939
+ name: questions?.[0]?.knowledgeMatrix?.[0]?.subject?.name ?? "Sem mat\xE9ria",
5940
+ id: subjectId
5941
+ },
5934
5942
  correct,
5935
5943
  incorrect,
5936
5944
  total: questions.length
@@ -5942,44 +5950,42 @@ var QuizListResult = forwardRef10(({ className, onSubjectClick, ...props }, ref)
5942
5950
  /* @__PURE__ */ jsx17("ul", { className: "flex flex-col gap-2", children: subjectsStats.map((subject) => /* @__PURE__ */ jsx17("li", { children: /* @__PURE__ */ jsx17(
5943
5951
  CardResults,
5944
5952
  {
5945
- onClick: () => onSubjectClick?.(subject.subject),
5953
+ onClick: () => onSubjectClick?.(subject.subject.id),
5946
5954
  className: "max-w-full",
5947
- header: subject.subject,
5955
+ header: subject.subject.name,
5948
5956
  correct_answers: subject.correct,
5949
5957
  incorrect_answers: subject.incorrect,
5950
5958
  icon: /* @__PURE__ */ jsx17(Book, { size: 20 }),
5951
5959
  direction: "row"
5952
5960
  }
5953
- ) }, subject.subject)) })
5961
+ ) }, subject.subject.id)) })
5954
5962
  ] });
5955
5963
  });
5956
5964
  var QuizListResultByMateria = ({
5957
5965
  subject,
5958
5966
  onQuestionClick
5959
5967
  }) => {
5960
- const {
5961
- getQuestionsGroupedBySubject,
5962
- getUserAnswerByQuestionId,
5963
- getQuestionIndex
5964
- } = useQuizStore();
5968
+ const { getQuestionsGroupedBySubject, getQuestionIndex } = useQuizStore();
5965
5969
  const groupedQuestions = getQuestionsGroupedBySubject();
5966
5970
  const answeredQuestions = groupedQuestions[subject] || [];
5967
5971
  return /* @__PURE__ */ jsxs14("div", { className: "w-full max-w-[1000px] flex flex-col mx-auto h-full relative not-lg:px-6", children: [
5968
- /* @__PURE__ */ jsx17("div", { className: "flex flex-row pt-4 justify-between", children: /* @__PURE__ */ jsx17("p", { className: "text-text-950 font-bold text-2xl", children: subject }) }),
5972
+ /* @__PURE__ */ jsx17("div", { className: "flex flex-row pt-4 justify-between", children: /* @__PURE__ */ jsx17("p", { className: "text-text-950 font-bold text-2xl", children: answeredQuestions?.[0]?.knowledgeMatrix?.[0]?.subject?.name ?? "Sem mat\xE9ria" }) }),
5969
5973
  /* @__PURE__ */ jsxs14("section", { className: "flex flex-col ", children: [
5970
5974
  /* @__PURE__ */ jsx17("p", { className: "pt-6 pb-4 text-text-950 font-bold text-lg", children: "Resultado das quest\xF5es" }),
5971
5975
  /* @__PURE__ */ jsx17("ul", { className: "flex flex-col gap-2 pt-4", children: answeredQuestions.map((question) => {
5972
- const questionIndex = getQuestionIndex(question.id);
5976
+ const questionIndex = getQuestionIndex(
5977
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
5978
+ question.questionId ?? question.id
5979
+ );
5973
5980
  return /* @__PURE__ */ jsx17("li", { children: /* @__PURE__ */ jsx17(
5974
5981
  CardStatus,
5975
5982
  {
5976
5983
  className: "max-w-full",
5977
5984
  header: `Quest\xE3o ${questionIndex.toString().padStart(2, "0")}`,
5978
5985
  status: (() => {
5979
- const userAnswer = getUserAnswerByQuestionId(question.id);
5980
- if (userAnswer?.answerStatus === "RESPOSTA_CORRETA" /* RESPOSTA_CORRETA */)
5986
+ if (question.answerStatus === "RESPOSTA_CORRETA" /* RESPOSTA_CORRETA */)
5981
5987
  return "correct";
5982
- if (userAnswer?.answerStatus === "RESPOSTA_INCORRETA" /* RESPOSTA_INCORRETA */)
5988
+ if (question.answerStatus === "RESPOSTA_INCORRETA" /* RESPOSTA_INCORRETA */)
5983
5989
  return "incorrect";
5984
5990
  return void 0;
5985
5991
  })(),
@@ -5994,6 +6000,7 @@ export {
5994
6000
  Quiz,
5995
6001
  QuizAlternative,
5996
6002
  QuizConnectDots,
6003
+ QuizContainer,
5997
6004
  QuizContent,
5998
6005
  QuizDissertative,
5999
6006
  QuizFill,
@@ -6008,8 +6015,10 @@ export {
6008
6015
  QuizResultHeaderTitle,
6009
6016
  QuizResultPerformance,
6010
6017
  QuizResultTitle,
6018
+ QuizSubTitle,
6011
6019
  QuizTitle,
6012
6020
  QuizTrueOrFalse,
6013
- getStatusBadge
6021
+ getStatusBadge,
6022
+ getStatusStyles
6014
6023
  };
6015
6024
  //# sourceMappingURL=index.mjs.map