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.
package/dist/index.js CHANGED
@@ -8342,12 +8342,12 @@ var useQuizStore = (0, import_zustand7.create)()(
8342
8342
  return unansweredQuestions;
8343
8343
  },
8344
8344
  getQuestionsGroupedBySubject: () => {
8345
- const { getActiveQuiz } = get();
8346
- const activeQuiz = getActiveQuiz();
8347
- if (!activeQuiz) return {};
8345
+ const { getQuestionResult, getActiveQuiz, variant } = get();
8346
+ const questions = variant == "result" ? getQuestionResult()?.answers : getActiveQuiz()?.quiz.questions;
8347
+ if (!questions) return {};
8348
8348
  const groupedQuestions = {};
8349
- activeQuiz.quiz.questions.forEach((question) => {
8350
- const subjectId = question.knowledgeMatrix?.[0]?.subjectId || "Sem mat\xE9ria";
8349
+ questions.forEach((question) => {
8350
+ const subjectId = question.knowledgeMatrix?.[0]?.subject?.id || "Sem mat\xE9ria";
8351
8351
  if (!groupedQuestions[subjectId]) {
8352
8352
  groupedQuestions[subjectId] = [];
8353
8353
  }
@@ -8381,12 +8381,22 @@ var useQuizStore = (0, import_zustand7.create)()(
8381
8381
  return userAnswers;
8382
8382
  },
8383
8383
  setCurrentQuestion: (question) => {
8384
- const { getActiveQuiz } = get();
8384
+ const { getActiveQuiz, variant, questionsResult } = get();
8385
8385
  const activeQuiz = getActiveQuiz();
8386
8386
  if (!activeQuiz) return;
8387
- const questionIndex = activeQuiz.quiz.questions.findIndex(
8388
- (q) => q.id === question.id
8389
- );
8387
+ let questionIndex = 0;
8388
+ if (variant == "result") {
8389
+ if (!questionsResult) return;
8390
+ const questionResult = questionsResult.answers.find((q) => q.id === question.id) ?? questionsResult.answers.find((q) => q.questionId === question.id);
8391
+ if (!questionResult) return;
8392
+ questionIndex = activeQuiz.quiz.questions.findIndex(
8393
+ (q) => q.id === questionResult.questionId
8394
+ );
8395
+ } else {
8396
+ questionIndex = activeQuiz.quiz.questions.findIndex(
8397
+ (q) => q.id === question.id
8398
+ );
8399
+ }
8390
8400
  if (questionIndex === -1) {
8391
8401
  console.warn(
8392
8402
  `Question with id "${question.id}" not found in active quiz`
@@ -8417,20 +8427,23 @@ var useQuizStore = (0, import_zustand7.create)()(
8417
8427
  return userAnswer ? userAnswer.answerStatus : null;
8418
8428
  },
8419
8429
  getQuestionIndex: (questionId) => {
8420
- const { getActiveQuiz } = get();
8421
- const activeQuiz = getActiveQuiz();
8422
- if (!activeQuiz) return 0;
8423
- const questionIndex = activeQuiz.quiz.questions.findIndex(
8424
- (q) => q.id === questionId
8430
+ const { questionsResult } = get();
8431
+ if (!questionsResult) return 0;
8432
+ let idx = questionsResult.answers.findIndex(
8433
+ (q) => q.questionId === questionId
8425
8434
  );
8426
- return questionIndex + 1;
8435
+ if (idx === -1) {
8436
+ idx = questionsResult.answers.findIndex((q) => q.id === questionId);
8437
+ }
8438
+ return idx !== -1 ? idx + 1 : 0;
8427
8439
  },
8428
8440
  // Question Result
8429
8441
  getQuestionResultByQuestionId: (questionId) => {
8430
8442
  const { questionsResult } = get();
8431
- return questionsResult?.answers.find(
8443
+ const question = questionsResult?.answers.find(
8432
8444
  (answer) => answer.questionId === questionId
8433
- ) || null;
8445
+ );
8446
+ return question || null;
8434
8447
  },
8435
8448
  getQuestionResultStatistics: () => {
8436
8449
  const { questionsResult } = get();
@@ -8581,8 +8594,8 @@ var QuizHeader = () => {
8581
8594
  HeaderAlternative,
8582
8595
  {
8583
8596
  title: currentQuestion ? `Quest\xE3o ${currentQuestionIndex + 1}` : "Quest\xE3o",
8584
- subTitle: currentQuestion?.knowledgeMatrix?.[0]?.topicId ?? "",
8585
- content: currentQuestion?.questionText ?? ""
8597
+ subTitle: currentQuestion?.knowledgeMatrix?.[0]?.topic?.name ?? "",
8598
+ content: currentQuestion?.statement ?? ""
8586
8599
  }
8587
8600
  );
8588
8601
  };
@@ -8631,10 +8644,10 @@ var QuizAlternative = ({ paddingBottom }) => {
8631
8644
  const alternatives = currentQuestion?.options?.map((option) => {
8632
8645
  let status = "neutral" /* NEUTRAL */;
8633
8646
  if (variant === "result") {
8634
- const isCorrectOption = currentQuestion.correctOptionIds?.includes(
8635
- option.id
8647
+ const isCorrectOption = currentQuestionResult?.options?.find((op) => op.id === option.id)?.isCorrect || false;
8648
+ const isSelected = currentQuestionResult?.selectedOptions.some(
8649
+ (selectedOption) => selectedOption.optionId === option.id
8636
8650
  );
8637
- const isSelected = currentQuestionResult?.optionId === option.id;
8638
8651
  if (isCorrectOption) {
8639
8652
  status = "correct" /* CORRECT */;
8640
8653
  } else if (isSelected && !isCorrectOption) {
@@ -8660,8 +8673,8 @@ var QuizAlternative = ({ paddingBottom }) => {
8660
8673
  name: `question-${currentQuestion?.id || "1"}`,
8661
8674
  layout: "compact",
8662
8675
  alternatives,
8663
- value: variant === "result" ? currentQuestionResult?.optionId || "" : currentAnswer?.optionId || "",
8664
- selectedValue: variant === "result" ? currentQuestionResult?.optionId || "" : currentAnswer?.optionId || "",
8676
+ value: variant === "result" ? currentQuestionResult?.selectedOptions[0]?.optionId || "" : currentAnswer?.optionId || "",
8677
+ selectedValue: variant === "result" ? currentQuestionResult?.selectedOptions[0]?.optionId || "" : currentAnswer?.optionId || "",
8665
8678
  onValueChange: (value) => {
8666
8679
  if (currentQuestion) {
8667
8680
  selectAnswer(currentQuestion.id, value);
@@ -8706,15 +8719,16 @@ var QuizMultipleChoice = ({ paddingBottom }) => {
8706
8719
  prevSelectedValuesRef.current = selectedValues;
8707
8720
  return selectedValues;
8708
8721
  }
8709
- if (variant == "result" && currentQuestionResult?.options.length && currentQuestionResult?.options.length > 0) {
8710
- return currentQuestionResult?.options.map((op) => op.id) || [];
8722
+ if (variant == "result") {
8723
+ return currentQuestionResult?.selectedOptions.map((op) => op.optionId) || [];
8724
+ } else {
8725
+ return prevSelectedValuesRef.current;
8711
8726
  }
8712
- return prevSelectedValuesRef.current;
8713
8727
  }, [
8714
8728
  selectedValues,
8715
8729
  currentQuestion?.id,
8716
8730
  variant,
8717
- currentQuestionResult?.optionId
8731
+ currentQuestionResult?.selectedOptions
8718
8732
  ]);
8719
8733
  const handleSelectedValues = (0, import_react27.useCallback)(
8720
8734
  (values) => {
@@ -8731,11 +8745,9 @@ var QuizMultipleChoice = ({ paddingBottom }) => {
8731
8745
  const choices = currentQuestion?.options?.map((option) => {
8732
8746
  let status = "neutral" /* NEUTRAL */;
8733
8747
  if (variant === "result") {
8734
- const isCorrectOption = currentQuestion.correctOptionIds?.includes(
8735
- option.id
8736
- );
8737
- const isSelected = currentQuestionResult?.options.find(
8738
- (op) => op.id === option.id
8748
+ const isCorrectOption = currentQuestionResult?.options?.find((op) => op.id === option.id)?.isCorrect || false;
8749
+ const isSelected = currentQuestionResult?.selectedOptions?.some(
8750
+ (op) => op.optionId === option.id
8739
8751
  );
8740
8752
  if (isCorrectOption) {
8741
8753
  status = "correct" /* CORRECT */;
@@ -9011,7 +9023,7 @@ var QuizConnectDots = ({ paddingBottom }) => {
9011
9023
  }) }) })
9012
9024
  ] });
9013
9025
  };
9014
- var QuizFill = ({ paddingBottom = "pb-[80px]" }) => {
9026
+ var QuizFill = ({ paddingBottom }) => {
9015
9027
  const { variant } = useQuizStore();
9016
9028
  const options = [
9017
9029
  "ci\xEAncia",
@@ -9369,7 +9381,7 @@ var QuizQuestionList = ({
9369
9381
  ([subjectId, questions]) => /* @__PURE__ */ (0, import_jsx_runtime39.jsxs)("section", { className: "flex flex-col gap-2", children: [
9370
9382
  /* @__PURE__ */ (0, import_jsx_runtime39.jsxs)("span", { className: "pt-6 pb-4 flex flex-row gap-2", children: [
9371
9383
  /* @__PURE__ */ (0, import_jsx_runtime39.jsx)("div", { className: "bg-primary-500 p-1 rounded-sm flex items-center justify-center", children: /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(import_phosphor_react20.BookOpen, { size: 17, className: "text-white" }) }),
9372
- /* @__PURE__ */ (0, import_jsx_runtime39.jsx)("p", { className: "text-text-800 font-bold text-lg", children: subjectId })
9384
+ /* @__PURE__ */ (0, import_jsx_runtime39.jsx)("p", { className: "text-text-800 font-bold text-lg", children: questions?.[0]?.knowledgeMatrix?.[0]?.subject?.name ?? "Sem mat\xE9ria" })
9373
9385
  ] }),
9374
9386
  /* @__PURE__ */ (0, import_jsx_runtime39.jsx)("ul", { className: "flex flex-col gap-2", children: questions.map((question) => {
9375
9387
  const status = getQuestionStatus(question.id);
@@ -9800,28 +9812,24 @@ var QuizResultPerformance = (0, import_react27.forwardRef)(
9800
9812
  }
9801
9813
  );
9802
9814
  var QuizListResult = (0, import_react27.forwardRef)(({ className, onSubjectClick, ...props }, ref) => {
9803
- const {
9804
- getQuestionsGroupedBySubject,
9805
- isQuestionAnswered,
9806
- getUserAnswerByQuestionId
9807
- } = useQuizStore();
9815
+ const { getQuestionsGroupedBySubject } = useQuizStore();
9808
9816
  const groupedQuestions = getQuestionsGroupedBySubject();
9809
9817
  const subjectsStats = Object.entries(groupedQuestions).map(
9810
9818
  ([subjectId, questions]) => {
9811
9819
  let correct = 0;
9812
9820
  let incorrect = 0;
9813
9821
  questions.forEach((question) => {
9814
- if (isQuestionAnswered(question.id)) {
9815
- const userAnswerItem = getUserAnswerByQuestionId(question.id);
9816
- if (userAnswerItem?.answerStatus == "RESPOSTA_CORRETA" /* RESPOSTA_CORRETA */) {
9817
- correct++;
9818
- } else {
9819
- incorrect++;
9820
- }
9822
+ if (question.answerStatus == "RESPOSTA_CORRETA" /* RESPOSTA_CORRETA */) {
9823
+ correct++;
9824
+ } else {
9825
+ incorrect++;
9821
9826
  }
9822
9827
  });
9823
9828
  return {
9824
- subject: subjectId,
9829
+ subject: {
9830
+ name: questions?.[0]?.knowledgeMatrix?.[0]?.subject?.name ?? "Sem mat\xE9ria",
9831
+ id: subjectId
9832
+ },
9825
9833
  correct,
9826
9834
  incorrect,
9827
9835
  total: questions.length
@@ -9833,44 +9841,42 @@ var QuizListResult = (0, import_react27.forwardRef)(({ className, onSubjectClick
9833
9841
  /* @__PURE__ */ (0, import_jsx_runtime39.jsx)("ul", { className: "flex flex-col gap-2", children: subjectsStats.map((subject) => /* @__PURE__ */ (0, import_jsx_runtime39.jsx)("li", { children: /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(
9834
9842
  CardResults,
9835
9843
  {
9836
- onClick: () => onSubjectClick?.(subject.subject),
9844
+ onClick: () => onSubjectClick?.(subject.subject.id),
9837
9845
  className: "max-w-full",
9838
- header: subject.subject,
9846
+ header: subject.subject.name,
9839
9847
  correct_answers: subject.correct,
9840
9848
  incorrect_answers: subject.incorrect,
9841
9849
  icon: /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(import_phosphor_react20.Book, { size: 20 }),
9842
9850
  direction: "row"
9843
9851
  }
9844
- ) }, subject.subject)) })
9852
+ ) }, subject.subject.id)) })
9845
9853
  ] });
9846
9854
  });
9847
9855
  var QuizListResultByMateria = ({
9848
9856
  subject,
9849
9857
  onQuestionClick
9850
9858
  }) => {
9851
- const {
9852
- getQuestionsGroupedBySubject,
9853
- getUserAnswerByQuestionId,
9854
- getQuestionIndex
9855
- } = useQuizStore();
9859
+ const { getQuestionsGroupedBySubject, getQuestionIndex } = useQuizStore();
9856
9860
  const groupedQuestions = getQuestionsGroupedBySubject();
9857
9861
  const answeredQuestions = groupedQuestions[subject] || [];
9858
9862
  return /* @__PURE__ */ (0, import_jsx_runtime39.jsxs)("div", { className: "w-full max-w-[1000px] flex flex-col mx-auto h-full relative not-lg:px-6", children: [
9859
- /* @__PURE__ */ (0, import_jsx_runtime39.jsx)("div", { className: "flex flex-row pt-4 justify-between", children: /* @__PURE__ */ (0, import_jsx_runtime39.jsx)("p", { className: "text-text-950 font-bold text-2xl", children: subject }) }),
9863
+ /* @__PURE__ */ (0, import_jsx_runtime39.jsx)("div", { className: "flex flex-row pt-4 justify-between", children: /* @__PURE__ */ (0, import_jsx_runtime39.jsx)("p", { className: "text-text-950 font-bold text-2xl", children: answeredQuestions?.[0]?.knowledgeMatrix?.[0]?.subject?.name ?? "Sem mat\xE9ria" }) }),
9860
9864
  /* @__PURE__ */ (0, import_jsx_runtime39.jsxs)("section", { className: "flex flex-col ", children: [
9861
9865
  /* @__PURE__ */ (0, import_jsx_runtime39.jsx)("p", { className: "pt-6 pb-4 text-text-950 font-bold text-lg", children: "Resultado das quest\xF5es" }),
9862
9866
  /* @__PURE__ */ (0, import_jsx_runtime39.jsx)("ul", { className: "flex flex-col gap-2 pt-4", children: answeredQuestions.map((question) => {
9863
- const questionIndex = getQuestionIndex(question.id);
9867
+ const questionIndex = getQuestionIndex(
9868
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
9869
+ question.questionId ?? question.id
9870
+ );
9864
9871
  return /* @__PURE__ */ (0, import_jsx_runtime39.jsx)("li", { children: /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(
9865
9872
  CardStatus,
9866
9873
  {
9867
9874
  className: "max-w-full",
9868
9875
  header: `Quest\xE3o ${questionIndex.toString().padStart(2, "0")}`,
9869
9876
  status: (() => {
9870
- const userAnswer = getUserAnswerByQuestionId(question.id);
9871
- if (userAnswer?.answerStatus === "RESPOSTA_CORRETA" /* RESPOSTA_CORRETA */)
9877
+ if (question.answerStatus === "RESPOSTA_CORRETA" /* RESPOSTA_CORRETA */)
9872
9878
  return "correct";
9873
- if (userAnswer?.answerStatus === "RESPOSTA_INCORRETA" /* RESPOSTA_INCORRETA */)
9879
+ if (question.answerStatus === "RESPOSTA_INCORRETA" /* RESPOSTA_INCORRETA */)
9874
9880
  return "incorrect";
9875
9881
  return void 0;
9876
9882
  })(),