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.mjs CHANGED
@@ -11248,10 +11248,15 @@ var QuizAlternative = ({ paddingBottom }) => {
11248
11248
  const isSelected = currentQuestionResult?.selectedOptions.some(
11249
11249
  (selectedOption) => selectedOption.optionId === option.id
11250
11250
  );
11251
- if (isCorrectOption) {
11252
- status = "correct" /* CORRECT */;
11253
- } else if (isSelected && !isCorrectOption) {
11254
- status = "incorrect" /* INCORRECT */;
11251
+ const shouldShowCorrectAnswers = currentQuestionResult?.answerStatus !== "PENDENTE_AVALIACAO" /* PENDENTE_AVALIACAO */ && currentQuestionResult?.answerStatus !== "NAO_RESPONDIDO" /* NAO_RESPONDIDO */;
11252
+ if (shouldShowCorrectAnswers) {
11253
+ if (isCorrectOption) {
11254
+ status = "correct" /* CORRECT */;
11255
+ } else if (isSelected && !isCorrectOption) {
11256
+ status = "incorrect" /* INCORRECT */;
11257
+ } else {
11258
+ status = "neutral" /* NEUTRAL */;
11259
+ }
11255
11260
  } else {
11256
11261
  status = "neutral" /* NEUTRAL */;
11257
11262
  }
@@ -11349,10 +11354,15 @@ var QuizMultipleChoice = ({ paddingBottom }) => {
11349
11354
  const isSelected = currentQuestionResult?.selectedOptions?.some(
11350
11355
  (op) => op.optionId === option.id
11351
11356
  );
11352
- if (isCorrectOption) {
11353
- status = "correct" /* CORRECT */;
11354
- } else if (isSelected && !isCorrectOption) {
11355
- status = "incorrect" /* INCORRECT */;
11357
+ const shouldShowCorrectAnswers = currentQuestionResult?.answerStatus !== "PENDENTE_AVALIACAO" /* PENDENTE_AVALIACAO */ && currentQuestionResult?.answerStatus !== "NAO_RESPONDIDO" /* NAO_RESPONDIDO */;
11358
+ if (shouldShowCorrectAnswers) {
11359
+ if (isCorrectOption) {
11360
+ status = "correct" /* CORRECT */;
11361
+ } else if (isSelected && !isCorrectOption) {
11362
+ status = "incorrect" /* INCORRECT */;
11363
+ } else {
11364
+ status = "neutral" /* NEUTRAL */;
11365
+ }
11356
11366
  } else {
11357
11367
  status = "neutral" /* NEUTRAL */;
11358
11368
  }
@@ -11455,8 +11465,8 @@ var QuizTrueOrFalse = ({ paddingBottom }) => {
11455
11465
  isCorrect: false
11456
11466
  }
11457
11467
  ];
11458
- const getLetterByIndex = (index) => String.fromCharCode(97 + index);
11459
- const isDefaultVariant = variant == "default";
11468
+ const getLetterByIndex = (index) => String.fromCodePoint(97 + index);
11469
+ const isDefaultVariant = variant === "default";
11460
11470
  return /* @__PURE__ */ jsxs37(Fragment11, { children: [
11461
11471
  /* @__PURE__ */ jsx52(QuizSubTitle, { subTitle: "Alternativas" }),
11462
11472
  /* @__PURE__ */ jsx52(QuizContainer, { className: cn("", paddingBottom), children: /* @__PURE__ */ jsx52("div", { className: "flex flex-col gap-3.5", children: options.map((option, index) => {
@@ -11471,7 +11481,7 @@ var QuizTrueOrFalse = ({ paddingBottom }) => {
11471
11481
  {
11472
11482
  className: cn(
11473
11483
  "flex flex-row justify-between items-center gap-2 p-2 rounded-md",
11474
- !isDefaultVariant ? getStatusStyles(variantCorrect) : ""
11484
+ isDefaultVariant ? "" : getStatusStyles(variantCorrect)
11475
11485
  ),
11476
11486
  children: [
11477
11487
  /* @__PURE__ */ jsx52("p", { className: "text-text-900 text-sm", children: getLetterByIndex(index).concat(") ").concat(option.label) }),
@@ -11572,7 +11582,7 @@ var QuizConnectDots = ({ paddingBottom }) => {
11572
11582
  return next;
11573
11583
  });
11574
11584
  };
11575
- const getLetterByIndex = (index) => String.fromCharCode(97 + index);
11585
+ const getLetterByIndex = (index) => String.fromCodePoint(97 + index);
11576
11586
  const isDefaultVariant = variant === "default";
11577
11587
  const assignedDots = new Set(
11578
11588
  userAnswers.map((a) => a.dotOption).filter(Boolean)
@@ -11588,7 +11598,7 @@ var QuizConnectDots = ({ paddingBottom }) => {
11588
11598
  {
11589
11599
  className: cn(
11590
11600
  "flex flex-row justify-between items-center gap-2 p-2 rounded-md",
11591
- !isDefaultVariant ? getStatusStyles(variantCorrect) : ""
11601
+ isDefaultVariant ? "" : getStatusStyles(variantCorrect)
11592
11602
  ),
11593
11603
  children: [
11594
11604
  /* @__PURE__ */ jsx52("p", { className: "text-text-900 text-sm", children: getLetterByIndex(index) + ") " + option.label }),
@@ -11670,8 +11680,10 @@ var QuizFill = ({ paddingBottom }) => {
11670
11680
  const [answers, setAnswers] = useState21({});
11671
11681
  const baseId = useId11();
11672
11682
  const getAvailableOptionsForSelect = (selectId) => {
11673
- const usedOptions = Object.entries(answers).filter(([key]) => key !== selectId).map(([, value]) => value);
11674
- return options.filter((option) => !usedOptions.includes(option));
11683
+ const usedOptions = new Set(
11684
+ Object.entries(answers).filter(([key]) => key !== selectId).map(([, value]) => value)
11685
+ );
11686
+ return options.filter((option) => !usedOptions.has(option));
11675
11687
  };
11676
11688
  const handleSelectChange = (selectId, value) => {
11677
11689
  const newAnswers = { ...answers, [selectId]: value };
@@ -12556,7 +12568,11 @@ var QuizBadge = ({
12556
12568
  };
12557
12569
  var QuizHeaderResult = forwardRef23(
12558
12570
  ({ className, ...props }, ref) => {
12559
- const { getQuestionResultByQuestionId, getCurrentQuestion } = useQuizStore();
12571
+ const {
12572
+ getQuestionResultByQuestionId,
12573
+ getCurrentQuestion,
12574
+ questionsResult
12575
+ } = useQuizStore();
12560
12576
  const [status, setStatus] = useState23(void 0);
12561
12577
  useEffect23(() => {
12562
12578
  const cq = getCurrentQuestion();
@@ -12569,9 +12585,13 @@ var QuizHeaderResult = forwardRef23(
12569
12585
  }, [
12570
12586
  getCurrentQuestion,
12571
12587
  getQuestionResultByQuestionId,
12572
- getCurrentQuestion()?.id
12588
+ getCurrentQuestion()?.id,
12589
+ questionsResult
12573
12590
  ]);
12574
12591
  const getClassesByAnswersStatus = () => {
12592
+ if (status === void 0) {
12593
+ return "bg-gray-100";
12594
+ }
12575
12595
  switch (status) {
12576
12596
  case "RESPOSTA_CORRETA" /* RESPOSTA_CORRETA */:
12577
12597
  return "bg-success-background";
@@ -12584,6 +12604,9 @@ var QuizHeaderResult = forwardRef23(
12584
12604
  }
12585
12605
  };
12586
12606
  const getLabelByAnswersStatus = () => {
12607
+ if (status === void 0) {
12608
+ return "Carregando...";
12609
+ }
12587
12610
  switch (status) {
12588
12611
  case "RESPOSTA_CORRETA" /* RESPOSTA_CORRETA */:
12589
12612
  return "\u{1F389} Parab\xE9ns!!";
@@ -12592,6 +12615,7 @@ var QuizHeaderResult = forwardRef23(
12592
12615
  case "PENDENTE_AVALIACAO" /* PENDENTE_AVALIACAO */:
12593
12616
  return "Avalia\xE7\xE3o pendente";
12594
12617
  case "NAO_RESPONDIDO" /* NAO_RESPONDIDO */:
12618
+ return "N\xE3o foi dessa vez...voc\xEA deixou a resposta em branco";
12595
12619
  default:
12596
12620
  return "N\xE3o foi dessa vez...voc\xEA deixou a resposta em branco";
12597
12621
  }
@@ -12657,6 +12681,37 @@ var QuizResultTitle = forwardRef23(({ className, ...props }, ref) => {
12657
12681
  }
12658
12682
  );
12659
12683
  });
12684
+ var updateDifficultyStats = (stats, difficulty, isCorrect) => {
12685
+ if (difficulty === "FACIL" /* FACIL */) {
12686
+ stats.totalEasyQuestions++;
12687
+ if (isCorrect) stats.correctEasyAnswers++;
12688
+ } else if (difficulty === "MEDIO" /* MEDIO */) {
12689
+ stats.totalMediumQuestions++;
12690
+ if (isCorrect) stats.correctMediumAnswers++;
12691
+ } else if (difficulty === "DIFICIL" /* DIFICIL */) {
12692
+ stats.totalDifficultQuestions++;
12693
+ if (isCorrect) stats.correctDifficultAnswers++;
12694
+ }
12695
+ };
12696
+ var calculateAnswerStatistics = (answers) => {
12697
+ const stats = {
12698
+ correctAnswers: 0,
12699
+ correctEasyAnswers: 0,
12700
+ correctMediumAnswers: 0,
12701
+ correctDifficultAnswers: 0,
12702
+ totalEasyQuestions: 0,
12703
+ totalMediumQuestions: 0,
12704
+ totalDifficultQuestions: 0
12705
+ };
12706
+ for (const answer of answers) {
12707
+ const isCorrect = answer.answerStatus === "RESPOSTA_CORRETA" /* RESPOSTA_CORRETA */;
12708
+ if (isCorrect) {
12709
+ stats.correctAnswers++;
12710
+ }
12711
+ updateDifficultyStats(stats, answer.difficultyLevel, isCorrect);
12712
+ }
12713
+ return stats;
12714
+ };
12660
12715
  var QuizResultPerformance = forwardRef23(({ showDetails = true, ...props }, ref) => {
12661
12716
  const {
12662
12717
  getTotalQuestions,
@@ -12666,38 +12721,16 @@ var QuizResultPerformance = forwardRef23(({ showDetails = true, ...props }, ref)
12666
12721
  } = useQuizStore();
12667
12722
  const totalQuestions = getTotalQuestions();
12668
12723
  const questionResult = getQuestionResult();
12669
- let correctAnswers = 0;
12670
- let correctEasyAnswers = 0;
12671
- let correctMediumAnswers = 0;
12672
- let correctDifficultAnswers = 0;
12673
- let totalEasyQuestions = 0;
12674
- let totalMediumQuestions = 0;
12675
- let totalDifficultQuestions = 0;
12676
- if (questionResult) {
12677
- questionResult.answers.forEach((answer) => {
12678
- const isCorrect = answer.answerStatus == "RESPOSTA_CORRETA" /* RESPOSTA_CORRETA */;
12679
- if (isCorrect) {
12680
- correctAnswers++;
12681
- }
12682
- if (answer.difficultyLevel === "FACIL" /* FACIL */) {
12683
- totalEasyQuestions++;
12684
- if (isCorrect) {
12685
- correctEasyAnswers++;
12686
- }
12687
- } else if (answer.difficultyLevel === "MEDIO" /* MEDIO */) {
12688
- totalMediumQuestions++;
12689
- if (isCorrect) {
12690
- correctMediumAnswers++;
12691
- }
12692
- } else if (answer.difficultyLevel === "DIFICIL" /* DIFICIL */) {
12693
- totalDifficultQuestions++;
12694
- if (isCorrect) {
12695
- correctDifficultAnswers++;
12696
- }
12697
- }
12698
- });
12699
- }
12700
- const percentage = totalQuestions > 0 ? Math.round(correctAnswers / totalQuestions * 100) : 0;
12724
+ const stats = questionResult ? calculateAnswerStatistics(questionResult.answers) : {
12725
+ correctAnswers: 0,
12726
+ correctEasyAnswers: 0,
12727
+ correctMediumAnswers: 0,
12728
+ correctDifficultAnswers: 0,
12729
+ totalEasyQuestions: 0,
12730
+ totalMediumQuestions: 0,
12731
+ totalDifficultQuestions: 0
12732
+ };
12733
+ const percentage = totalQuestions > 0 ? Math.round(stats.correctAnswers / totalQuestions * 100) : 0;
12701
12734
  const classesJustifyBetween = showDetails ? "justify-between" : "justify-center";
12702
12735
  return /* @__PURE__ */ jsxs39(
12703
12736
  "div",
@@ -12743,8 +12776,8 @@ var QuizResultPerformance = forwardRef23(({ showDetails = true, ...props }, ref)
12743
12776
  className: "w-full",
12744
12777
  layout: "stacked",
12745
12778
  variant: "green",
12746
- value: correctEasyAnswers,
12747
- max: totalEasyQuestions,
12779
+ value: stats.correctEasyAnswers,
12780
+ max: stats.totalEasyQuestions,
12748
12781
  label: "F\xE1ceis",
12749
12782
  showHitCount: true,
12750
12783
  labelClassName: "text-base font-medium text-text-800 leading-none",
@@ -12757,8 +12790,8 @@ var QuizResultPerformance = forwardRef23(({ showDetails = true, ...props }, ref)
12757
12790
  className: "w-full",
12758
12791
  layout: "stacked",
12759
12792
  variant: "green",
12760
- value: correctMediumAnswers,
12761
- max: totalMediumQuestions,
12793
+ value: stats.correctMediumAnswers,
12794
+ max: stats.totalMediumQuestions,
12762
12795
  label: "M\xE9dias",
12763
12796
  showHitCount: true,
12764
12797
  labelClassName: "text-base font-medium text-text-800 leading-none",
@@ -12771,8 +12804,8 @@ var QuizResultPerformance = forwardRef23(({ showDetails = true, ...props }, ref)
12771
12804
  className: "w-full",
12772
12805
  layout: "stacked",
12773
12806
  variant: "green",
12774
- value: correctDifficultAnswers,
12775
- max: totalDifficultQuestions,
12807
+ value: stats.correctDifficultAnswers,
12808
+ max: stats.totalDifficultQuestions,
12776
12809
  label: "Dif\xEDceis",
12777
12810
  showHitCount: true,
12778
12811
  labelClassName: "text-base font-medium text-text-800 leading-none",
@@ -12792,13 +12825,13 @@ var QuizListResult = forwardRef23(({ className, onSubjectClick, ...props }, ref)
12792
12825
  ([subjectId, questions]) => {
12793
12826
  let correct = 0;
12794
12827
  let incorrect = 0;
12795
- questions.forEach((question) => {
12796
- if (question.answerStatus == "RESPOSTA_CORRETA" /* RESPOSTA_CORRETA */) {
12828
+ for (const question of questions) {
12829
+ if (question.answerStatus === "RESPOSTA_CORRETA" /* RESPOSTA_CORRETA */) {
12797
12830
  correct++;
12798
12831
  } else {
12799
12832
  incorrect++;
12800
12833
  }
12801
- });
12834
+ }
12802
12835
  return {
12803
12836
  subject: {
12804
12837
  name: questions?.[0]?.knowledgeMatrix?.[0]?.subject?.name ?? "Sem mat\xE9ria",