analytica-frontend-lib 1.2.1 → 1.2.2

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.
package/dist/index.js CHANGED
@@ -11286,10 +11286,15 @@ var QuizAlternative = ({ paddingBottom }) => {
11286
11286
  const isSelected = currentQuestionResult?.selectedOptions.some(
11287
11287
  (selectedOption) => selectedOption.optionId === option.id
11288
11288
  );
11289
- if (isCorrectOption) {
11290
- status = "correct" /* CORRECT */;
11291
- } else if (isSelected && !isCorrectOption) {
11292
- status = "incorrect" /* INCORRECT */;
11289
+ const shouldShowCorrectAnswers = currentQuestionResult?.answerStatus !== "PENDENTE_AVALIACAO" /* PENDENTE_AVALIACAO */ && currentQuestionResult?.answerStatus !== "NAO_RESPONDIDO" /* NAO_RESPONDIDO */;
11290
+ if (shouldShowCorrectAnswers) {
11291
+ if (isCorrectOption) {
11292
+ status = "correct" /* CORRECT */;
11293
+ } else if (isSelected && !isCorrectOption) {
11294
+ status = "incorrect" /* INCORRECT */;
11295
+ } else {
11296
+ status = "neutral" /* NEUTRAL */;
11297
+ }
11293
11298
  } else {
11294
11299
  status = "neutral" /* NEUTRAL */;
11295
11300
  }
@@ -11387,10 +11392,15 @@ var QuizMultipleChoice = ({ paddingBottom }) => {
11387
11392
  const isSelected = currentQuestionResult?.selectedOptions?.some(
11388
11393
  (op) => op.optionId === option.id
11389
11394
  );
11390
- if (isCorrectOption) {
11391
- status = "correct" /* CORRECT */;
11392
- } else if (isSelected && !isCorrectOption) {
11393
- status = "incorrect" /* INCORRECT */;
11395
+ const shouldShowCorrectAnswers = currentQuestionResult?.answerStatus !== "PENDENTE_AVALIACAO" /* PENDENTE_AVALIACAO */ && currentQuestionResult?.answerStatus !== "NAO_RESPONDIDO" /* NAO_RESPONDIDO */;
11396
+ if (shouldShowCorrectAnswers) {
11397
+ if (isCorrectOption) {
11398
+ status = "correct" /* CORRECT */;
11399
+ } else if (isSelected && !isCorrectOption) {
11400
+ status = "incorrect" /* INCORRECT */;
11401
+ } else {
11402
+ status = "neutral" /* NEUTRAL */;
11403
+ }
11394
11404
  } else {
11395
11405
  status = "neutral" /* NEUTRAL */;
11396
11406
  }
@@ -11493,8 +11503,8 @@ var QuizTrueOrFalse = ({ paddingBottom }) => {
11493
11503
  isCorrect: false
11494
11504
  }
11495
11505
  ];
11496
- const getLetterByIndex = (index) => String.fromCharCode(97 + index);
11497
- const isDefaultVariant = variant == "default";
11506
+ const getLetterByIndex = (index) => String.fromCodePoint(97 + index);
11507
+ const isDefaultVariant = variant === "default";
11498
11508
  return /* @__PURE__ */ (0, import_jsx_runtime52.jsxs)(import_jsx_runtime52.Fragment, { children: [
11499
11509
  /* @__PURE__ */ (0, import_jsx_runtime52.jsx)(QuizSubTitle, { subTitle: "Alternativas" }),
11500
11510
  /* @__PURE__ */ (0, import_jsx_runtime52.jsx)(QuizContainer, { className: cn("", paddingBottom), children: /* @__PURE__ */ (0, import_jsx_runtime52.jsx)("div", { className: "flex flex-col gap-3.5", children: options.map((option, index) => {
@@ -11509,7 +11519,7 @@ var QuizTrueOrFalse = ({ paddingBottom }) => {
11509
11519
  {
11510
11520
  className: cn(
11511
11521
  "flex flex-row justify-between items-center gap-2 p-2 rounded-md",
11512
- !isDefaultVariant ? getStatusStyles(variantCorrect) : ""
11522
+ isDefaultVariant ? "" : getStatusStyles(variantCorrect)
11513
11523
  ),
11514
11524
  children: [
11515
11525
  /* @__PURE__ */ (0, import_jsx_runtime52.jsx)("p", { className: "text-text-900 text-sm", children: getLetterByIndex(index).concat(") ").concat(option.label) }),
@@ -11610,7 +11620,7 @@ var QuizConnectDots = ({ paddingBottom }) => {
11610
11620
  return next;
11611
11621
  });
11612
11622
  };
11613
- const getLetterByIndex = (index) => String.fromCharCode(97 + index);
11623
+ const getLetterByIndex = (index) => String.fromCodePoint(97 + index);
11614
11624
  const isDefaultVariant = variant === "default";
11615
11625
  const assignedDots = new Set(
11616
11626
  userAnswers.map((a) => a.dotOption).filter(Boolean)
@@ -11626,7 +11636,7 @@ var QuizConnectDots = ({ paddingBottom }) => {
11626
11636
  {
11627
11637
  className: cn(
11628
11638
  "flex flex-row justify-between items-center gap-2 p-2 rounded-md",
11629
- !isDefaultVariant ? getStatusStyles(variantCorrect) : ""
11639
+ isDefaultVariant ? "" : getStatusStyles(variantCorrect)
11630
11640
  ),
11631
11641
  children: [
11632
11642
  /* @__PURE__ */ (0, import_jsx_runtime52.jsx)("p", { className: "text-text-900 text-sm", children: getLetterByIndex(index) + ") " + option.label }),
@@ -11708,8 +11718,10 @@ var QuizFill = ({ paddingBottom }) => {
11708
11718
  const [answers, setAnswers] = (0, import_react36.useState)({});
11709
11719
  const baseId = (0, import_react36.useId)();
11710
11720
  const getAvailableOptionsForSelect = (selectId) => {
11711
- const usedOptions = Object.entries(answers).filter(([key]) => key !== selectId).map(([, value]) => value);
11712
- return options.filter((option) => !usedOptions.includes(option));
11721
+ const usedOptions = new Set(
11722
+ Object.entries(answers).filter(([key]) => key !== selectId).map(([, value]) => value)
11723
+ );
11724
+ return options.filter((option) => !usedOptions.has(option));
11713
11725
  };
11714
11726
  const handleSelectChange = (selectId, value) => {
11715
11727
  const newAnswers = { ...answers, [selectId]: value };
@@ -12594,7 +12606,11 @@ var QuizBadge = ({
12594
12606
  };
12595
12607
  var QuizHeaderResult = (0, import_react38.forwardRef)(
12596
12608
  ({ className, ...props }, ref) => {
12597
- const { getQuestionResultByQuestionId, getCurrentQuestion } = useQuizStore();
12609
+ const {
12610
+ getQuestionResultByQuestionId,
12611
+ getCurrentQuestion,
12612
+ questionsResult
12613
+ } = useQuizStore();
12598
12614
  const [status, setStatus] = (0, import_react38.useState)(void 0);
12599
12615
  (0, import_react38.useEffect)(() => {
12600
12616
  const cq = getCurrentQuestion();
@@ -12607,9 +12623,13 @@ var QuizHeaderResult = (0, import_react38.forwardRef)(
12607
12623
  }, [
12608
12624
  getCurrentQuestion,
12609
12625
  getQuestionResultByQuestionId,
12610
- getCurrentQuestion()?.id
12626
+ getCurrentQuestion()?.id,
12627
+ questionsResult
12611
12628
  ]);
12612
12629
  const getClassesByAnswersStatus = () => {
12630
+ if (status === void 0) {
12631
+ return "bg-gray-100";
12632
+ }
12613
12633
  switch (status) {
12614
12634
  case "RESPOSTA_CORRETA" /* RESPOSTA_CORRETA */:
12615
12635
  return "bg-success-background";
@@ -12622,6 +12642,9 @@ var QuizHeaderResult = (0, import_react38.forwardRef)(
12622
12642
  }
12623
12643
  };
12624
12644
  const getLabelByAnswersStatus = () => {
12645
+ if (status === void 0) {
12646
+ return "Carregando...";
12647
+ }
12625
12648
  switch (status) {
12626
12649
  case "RESPOSTA_CORRETA" /* RESPOSTA_CORRETA */:
12627
12650
  return "\u{1F389} Parab\xE9ns!!";
@@ -12630,6 +12653,7 @@ var QuizHeaderResult = (0, import_react38.forwardRef)(
12630
12653
  case "PENDENTE_AVALIACAO" /* PENDENTE_AVALIACAO */:
12631
12654
  return "Avalia\xE7\xE3o pendente";
12632
12655
  case "NAO_RESPONDIDO" /* NAO_RESPONDIDO */:
12656
+ return "N\xE3o foi dessa vez...voc\xEA deixou a resposta em branco";
12633
12657
  default:
12634
12658
  return "N\xE3o foi dessa vez...voc\xEA deixou a resposta em branco";
12635
12659
  }
@@ -12695,6 +12719,37 @@ var QuizResultTitle = (0, import_react38.forwardRef)(({ className, ...props }, r
12695
12719
  }
12696
12720
  );
12697
12721
  });
12722
+ var updateDifficultyStats = (stats, difficulty, isCorrect) => {
12723
+ if (difficulty === "FACIL" /* FACIL */) {
12724
+ stats.totalEasyQuestions++;
12725
+ if (isCorrect) stats.correctEasyAnswers++;
12726
+ } else if (difficulty === "MEDIO" /* MEDIO */) {
12727
+ stats.totalMediumQuestions++;
12728
+ if (isCorrect) stats.correctMediumAnswers++;
12729
+ } else if (difficulty === "DIFICIL" /* DIFICIL */) {
12730
+ stats.totalDifficultQuestions++;
12731
+ if (isCorrect) stats.correctDifficultAnswers++;
12732
+ }
12733
+ };
12734
+ var calculateAnswerStatistics = (answers) => {
12735
+ const stats = {
12736
+ correctAnswers: 0,
12737
+ correctEasyAnswers: 0,
12738
+ correctMediumAnswers: 0,
12739
+ correctDifficultAnswers: 0,
12740
+ totalEasyQuestions: 0,
12741
+ totalMediumQuestions: 0,
12742
+ totalDifficultQuestions: 0
12743
+ };
12744
+ for (const answer of answers) {
12745
+ const isCorrect = answer.answerStatus === "RESPOSTA_CORRETA" /* RESPOSTA_CORRETA */;
12746
+ if (isCorrect) {
12747
+ stats.correctAnswers++;
12748
+ }
12749
+ updateDifficultyStats(stats, answer.difficultyLevel, isCorrect);
12750
+ }
12751
+ return stats;
12752
+ };
12698
12753
  var QuizResultPerformance = (0, import_react38.forwardRef)(({ showDetails = true, ...props }, ref) => {
12699
12754
  const {
12700
12755
  getTotalQuestions,
@@ -12704,38 +12759,16 @@ var QuizResultPerformance = (0, import_react38.forwardRef)(({ showDetails = true
12704
12759
  } = useQuizStore();
12705
12760
  const totalQuestions = getTotalQuestions();
12706
12761
  const questionResult = getQuestionResult();
12707
- let correctAnswers = 0;
12708
- let correctEasyAnswers = 0;
12709
- let correctMediumAnswers = 0;
12710
- let correctDifficultAnswers = 0;
12711
- let totalEasyQuestions = 0;
12712
- let totalMediumQuestions = 0;
12713
- let totalDifficultQuestions = 0;
12714
- if (questionResult) {
12715
- questionResult.answers.forEach((answer) => {
12716
- const isCorrect = answer.answerStatus == "RESPOSTA_CORRETA" /* RESPOSTA_CORRETA */;
12717
- if (isCorrect) {
12718
- correctAnswers++;
12719
- }
12720
- if (answer.difficultyLevel === "FACIL" /* FACIL */) {
12721
- totalEasyQuestions++;
12722
- if (isCorrect) {
12723
- correctEasyAnswers++;
12724
- }
12725
- } else if (answer.difficultyLevel === "MEDIO" /* MEDIO */) {
12726
- totalMediumQuestions++;
12727
- if (isCorrect) {
12728
- correctMediumAnswers++;
12729
- }
12730
- } else if (answer.difficultyLevel === "DIFICIL" /* DIFICIL */) {
12731
- totalDifficultQuestions++;
12732
- if (isCorrect) {
12733
- correctDifficultAnswers++;
12734
- }
12735
- }
12736
- });
12737
- }
12738
- const percentage = totalQuestions > 0 ? Math.round(correctAnswers / totalQuestions * 100) : 0;
12762
+ const stats = questionResult ? calculateAnswerStatistics(questionResult.answers) : {
12763
+ correctAnswers: 0,
12764
+ correctEasyAnswers: 0,
12765
+ correctMediumAnswers: 0,
12766
+ correctDifficultAnswers: 0,
12767
+ totalEasyQuestions: 0,
12768
+ totalMediumQuestions: 0,
12769
+ totalDifficultQuestions: 0
12770
+ };
12771
+ const percentage = totalQuestions > 0 ? Math.round(stats.correctAnswers / totalQuestions * 100) : 0;
12739
12772
  const classesJustifyBetween = showDetails ? "justify-between" : "justify-center";
12740
12773
  return /* @__PURE__ */ (0, import_jsx_runtime54.jsxs)(
12741
12774
  "div",
@@ -12781,8 +12814,8 @@ var QuizResultPerformance = (0, import_react38.forwardRef)(({ showDetails = true
12781
12814
  className: "w-full",
12782
12815
  layout: "stacked",
12783
12816
  variant: "green",
12784
- value: correctEasyAnswers,
12785
- max: totalEasyQuestions,
12817
+ value: stats.correctEasyAnswers,
12818
+ max: stats.totalEasyQuestions,
12786
12819
  label: "F\xE1ceis",
12787
12820
  showHitCount: true,
12788
12821
  labelClassName: "text-base font-medium text-text-800 leading-none",
@@ -12795,8 +12828,8 @@ var QuizResultPerformance = (0, import_react38.forwardRef)(({ showDetails = true
12795
12828
  className: "w-full",
12796
12829
  layout: "stacked",
12797
12830
  variant: "green",
12798
- value: correctMediumAnswers,
12799
- max: totalMediumQuestions,
12831
+ value: stats.correctMediumAnswers,
12832
+ max: stats.totalMediumQuestions,
12800
12833
  label: "M\xE9dias",
12801
12834
  showHitCount: true,
12802
12835
  labelClassName: "text-base font-medium text-text-800 leading-none",
@@ -12809,8 +12842,8 @@ var QuizResultPerformance = (0, import_react38.forwardRef)(({ showDetails = true
12809
12842
  className: "w-full",
12810
12843
  layout: "stacked",
12811
12844
  variant: "green",
12812
- value: correctDifficultAnswers,
12813
- max: totalDifficultQuestions,
12845
+ value: stats.correctDifficultAnswers,
12846
+ max: stats.totalDifficultQuestions,
12814
12847
  label: "Dif\xEDceis",
12815
12848
  showHitCount: true,
12816
12849
  labelClassName: "text-base font-medium text-text-800 leading-none",
@@ -12830,13 +12863,13 @@ var QuizListResult = (0, import_react38.forwardRef)(({ className, onSubjectClick
12830
12863
  ([subjectId, questions]) => {
12831
12864
  let correct = 0;
12832
12865
  let incorrect = 0;
12833
- questions.forEach((question) => {
12834
- if (question.answerStatus == "RESPOSTA_CORRETA" /* RESPOSTA_CORRETA */) {
12866
+ for (const question of questions) {
12867
+ if (question.answerStatus === "RESPOSTA_CORRETA" /* RESPOSTA_CORRETA */) {
12835
12868
  correct++;
12836
12869
  } else {
12837
12870
  incorrect++;
12838
12871
  }
12839
- });
12872
+ }
12840
12873
  return {
12841
12874
  subject: {
12842
12875
  name: questions?.[0]?.knowledgeMatrix?.[0]?.subject?.name ?? "Sem mat\xE9ria",