analytica-frontend-lib 1.1.14 → 1.1.16

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
@@ -7926,6 +7926,35 @@ import {
7926
7926
  // src/components/Quiz/useQuizStore.ts
7927
7927
  import { create as create7 } from "zustand";
7928
7928
  import { devtools } from "zustand/middleware";
7929
+ var QUESTION_DIFFICULTY = /* @__PURE__ */ ((QUESTION_DIFFICULTY2) => {
7930
+ QUESTION_DIFFICULTY2["FACIL"] = "FACIL";
7931
+ QUESTION_DIFFICULTY2["MEDIO"] = "MEDIO";
7932
+ QUESTION_DIFFICULTY2["DIFICIL"] = "DIFICIL";
7933
+ return QUESTION_DIFFICULTY2;
7934
+ })(QUESTION_DIFFICULTY || {});
7935
+ var QUESTION_TYPE = /* @__PURE__ */ ((QUESTION_TYPE2) => {
7936
+ QUESTION_TYPE2["ALTERNATIVA"] = "ALTERNATIVA";
7937
+ QUESTION_TYPE2["DISSERTATIVA"] = "DISSERTATIVA";
7938
+ QUESTION_TYPE2["MULTIPLA_CHOICE"] = "MULTIPLA_CHOICE";
7939
+ QUESTION_TYPE2["VERDADEIRO_FALSO"] = "VERDADEIRO_FALSO";
7940
+ QUESTION_TYPE2["LIGAR_PONTOS"] = "LIGAR_PONTOS";
7941
+ QUESTION_TYPE2["PREENCHER"] = "PREENCHER";
7942
+ QUESTION_TYPE2["IMAGEM"] = "IMAGEM";
7943
+ return QUESTION_TYPE2;
7944
+ })(QUESTION_TYPE || {});
7945
+ var QUESTION_STATUS = /* @__PURE__ */ ((QUESTION_STATUS2) => {
7946
+ QUESTION_STATUS2["PENDENTE_AVALIACAO"] = "PENDENTE_AVALIACAO";
7947
+ QUESTION_STATUS2["RESPOSTA_CORRETA"] = "RESPOSTA_CORRETA";
7948
+ QUESTION_STATUS2["RESPOSTA_INCORRETA"] = "RESPOSTA_INCORRETA";
7949
+ QUESTION_STATUS2["NAO_RESPONDIDO"] = "NAO_RESPONDIDO";
7950
+ return QUESTION_STATUS2;
7951
+ })(QUESTION_STATUS || {});
7952
+ var ANSWER_STATUS = /* @__PURE__ */ ((ANSWER_STATUS2) => {
7953
+ ANSWER_STATUS2["RESPOSTA_CORRETA"] = "RESPOSTA_CORRETA";
7954
+ ANSWER_STATUS2["RESPOSTA_INCORRETA"] = "RESPOSTA_INCORRETA";
7955
+ ANSWER_STATUS2["PENDENTE_AVALIACAO"] = "PENDENTE_AVALIACAO";
7956
+ return ANSWER_STATUS2;
7957
+ })(ANSWER_STATUS || {});
7929
7958
  var useQuizStore = create7()(
7930
7959
  devtools(
7931
7960
  (set, get) => {
@@ -7961,9 +7990,9 @@ var useQuizStore = create7()(
7961
7990
  questionsResult: null,
7962
7991
  currentQuestionResult: null,
7963
7992
  // Setters
7964
- setBySimulated: (simulado) => set({ bySimulated: simulado }),
7965
- setByActivity: (atividade) => set({ byActivity: atividade }),
7966
- setByQuestionary: (aula) => set({ byQuestionary: aula }),
7993
+ setBySimulated: (simulated) => set({ bySimulated: simulated }),
7994
+ setByActivity: (activity) => set({ byActivity: activity }),
7995
+ setByQuestionary: (lesson) => set({ byQuestionary: lesson }),
7967
7996
  setUserId: (userId) => set({ userId }),
7968
7997
  setUserAnswers: (userAnswers) => set({ userAnswers }),
7969
7998
  getUserId: () => get().userId,
@@ -8329,12 +8358,12 @@ var useQuizStore = create7()(
8329
8358
  return unansweredQuestions;
8330
8359
  },
8331
8360
  getQuestionsGroupedBySubject: () => {
8332
- const { getActiveQuiz } = get();
8333
- const activeQuiz = getActiveQuiz();
8334
- if (!activeQuiz) return {};
8361
+ const { getQuestionResult, getActiveQuiz, variant } = get();
8362
+ const questions = variant == "result" ? getQuestionResult()?.answers : getActiveQuiz()?.quiz.questions;
8363
+ if (!questions) return {};
8335
8364
  const groupedQuestions = {};
8336
- activeQuiz.quiz.questions.forEach((question) => {
8337
- const subjectId = question.knowledgeMatrix?.[0]?.subjectId || "Sem mat\xE9ria";
8365
+ questions.forEach((question) => {
8366
+ const subjectId = question.knowledgeMatrix?.[0]?.subject?.id || "Sem mat\xE9ria";
8338
8367
  if (!groupedQuestions[subjectId]) {
8339
8368
  groupedQuestions[subjectId] = [];
8340
8369
  }
@@ -8368,12 +8397,22 @@ var useQuizStore = create7()(
8368
8397
  return userAnswers;
8369
8398
  },
8370
8399
  setCurrentQuestion: (question) => {
8371
- const { getActiveQuiz } = get();
8400
+ const { getActiveQuiz, variant, questionsResult } = get();
8372
8401
  const activeQuiz = getActiveQuiz();
8373
8402
  if (!activeQuiz) return;
8374
- const questionIndex = activeQuiz.quiz.questions.findIndex(
8375
- (q) => q.id === question.id
8376
- );
8403
+ let questionIndex = 0;
8404
+ if (variant == "result") {
8405
+ if (!questionsResult) return;
8406
+ const questionResult = questionsResult.answers.find((q) => q.id === question.id) ?? questionsResult.answers.find((q) => q.questionId === question.id);
8407
+ if (!questionResult) return;
8408
+ questionIndex = activeQuiz.quiz.questions.findIndex(
8409
+ (q) => q.id === questionResult.questionId
8410
+ );
8411
+ } else {
8412
+ questionIndex = activeQuiz.quiz.questions.findIndex(
8413
+ (q) => q.id === question.id
8414
+ );
8415
+ }
8377
8416
  if (questionIndex === -1) {
8378
8417
  console.warn(
8379
8418
  `Question with id "${question.id}" not found in active quiz`
@@ -8404,20 +8443,23 @@ var useQuizStore = create7()(
8404
8443
  return userAnswer ? userAnswer.answerStatus : null;
8405
8444
  },
8406
8445
  getQuestionIndex: (questionId) => {
8407
- const { getActiveQuiz } = get();
8408
- const activeQuiz = getActiveQuiz();
8409
- if (!activeQuiz) return 0;
8410
- const questionIndex = activeQuiz.quiz.questions.findIndex(
8411
- (q) => q.id === questionId
8446
+ const { questionsResult } = get();
8447
+ if (!questionsResult) return 0;
8448
+ let idx = questionsResult.answers.findIndex(
8449
+ (q) => q.questionId === questionId
8412
8450
  );
8413
- return questionIndex + 1;
8451
+ if (idx === -1) {
8452
+ idx = questionsResult.answers.findIndex((q) => q.id === questionId);
8453
+ }
8454
+ return idx !== -1 ? idx + 1 : 0;
8414
8455
  },
8415
8456
  // Question Result
8416
8457
  getQuestionResultByQuestionId: (questionId) => {
8417
8458
  const { questionsResult } = get();
8418
- return questionsResult?.answers.find(
8459
+ const question = questionsResult?.answers.find(
8419
8460
  (answer) => answer.questionId === questionId
8420
- ) || null;
8461
+ );
8462
+ return question || null;
8421
8463
  },
8422
8464
  getQuestionResultStatistics: () => {
8423
8465
  const { questionsResult } = get();
@@ -8568,8 +8610,8 @@ var QuizHeader = () => {
8568
8610
  HeaderAlternative,
8569
8611
  {
8570
8612
  title: currentQuestion ? `Quest\xE3o ${currentQuestionIndex + 1}` : "Quest\xE3o",
8571
- subTitle: currentQuestion?.knowledgeMatrix?.[0]?.topicId ?? "",
8572
- content: currentQuestion?.questionText ?? ""
8613
+ subTitle: currentQuestion?.knowledgeMatrix?.[0]?.topic?.name ?? "",
8614
+ content: currentQuestion?.statement ?? ""
8573
8615
  }
8574
8616
  );
8575
8617
  };
@@ -8618,10 +8660,10 @@ var QuizAlternative = ({ paddingBottom }) => {
8618
8660
  const alternatives = currentQuestion?.options?.map((option) => {
8619
8661
  let status = "neutral" /* NEUTRAL */;
8620
8662
  if (variant === "result") {
8621
- const isCorrectOption = currentQuestion.correctOptionIds?.includes(
8622
- option.id
8663
+ const isCorrectOption = currentQuestionResult?.options?.find((op) => op.id === option.id)?.isCorrect || false;
8664
+ const isSelected = currentQuestionResult?.selectedOptions.some(
8665
+ (selectedOption) => selectedOption.optionId === option.id
8623
8666
  );
8624
- const isSelected = currentQuestionResult?.optionId === option.id;
8625
8667
  if (isCorrectOption) {
8626
8668
  status = "correct" /* CORRECT */;
8627
8669
  } else if (isSelected && !isCorrectOption) {
@@ -8647,8 +8689,8 @@ var QuizAlternative = ({ paddingBottom }) => {
8647
8689
  name: `question-${currentQuestion?.id || "1"}`,
8648
8690
  layout: "compact",
8649
8691
  alternatives,
8650
- value: variant === "result" ? currentQuestionResult?.optionId || "" : currentAnswer?.optionId || "",
8651
- selectedValue: variant === "result" ? currentQuestionResult?.optionId || "" : currentAnswer?.optionId || "",
8692
+ value: variant === "result" ? currentQuestionResult?.selectedOptions[0]?.optionId || "" : currentAnswer?.optionId || "",
8693
+ selectedValue: variant === "result" ? currentQuestionResult?.selectedOptions[0]?.optionId || "" : currentAnswer?.optionId || "",
8652
8694
  onValueChange: (value) => {
8653
8695
  if (currentQuestion) {
8654
8696
  selectAnswer(currentQuestion.id, value);
@@ -8693,15 +8735,16 @@ var QuizMultipleChoice = ({ paddingBottom }) => {
8693
8735
  prevSelectedValuesRef.current = selectedValues;
8694
8736
  return selectedValues;
8695
8737
  }
8696
- if (variant == "result" && currentQuestionResult?.options.length && currentQuestionResult?.options.length > 0) {
8697
- return currentQuestionResult?.options.map((op) => op.id) || [];
8738
+ if (variant == "result") {
8739
+ return currentQuestionResult?.selectedOptions.map((op) => op.optionId) || [];
8740
+ } else {
8741
+ return prevSelectedValuesRef.current;
8698
8742
  }
8699
- return prevSelectedValuesRef.current;
8700
8743
  }, [
8701
8744
  selectedValues,
8702
8745
  currentQuestion?.id,
8703
8746
  variant,
8704
- currentQuestionResult?.optionId
8747
+ currentQuestionResult?.selectedOptions
8705
8748
  ]);
8706
8749
  const handleSelectedValues = useCallback4(
8707
8750
  (values) => {
@@ -8718,11 +8761,9 @@ var QuizMultipleChoice = ({ paddingBottom }) => {
8718
8761
  const choices = currentQuestion?.options?.map((option) => {
8719
8762
  let status = "neutral" /* NEUTRAL */;
8720
8763
  if (variant === "result") {
8721
- const isCorrectOption = currentQuestion.correctOptionIds?.includes(
8722
- option.id
8723
- );
8724
- const isSelected = currentQuestionResult?.options.find(
8725
- (op) => op.id === option.id
8764
+ const isCorrectOption = currentQuestionResult?.options?.find((op) => op.id === option.id)?.isCorrect || false;
8765
+ const isSelected = currentQuestionResult?.selectedOptions?.some(
8766
+ (op) => op.optionId === option.id
8726
8767
  );
8727
8768
  if (isCorrectOption) {
8728
8769
  status = "correct" /* CORRECT */;
@@ -8998,7 +9039,7 @@ var QuizConnectDots = ({ paddingBottom }) => {
8998
9039
  }) }) })
8999
9040
  ] });
9000
9041
  };
9001
- var QuizFill = ({ paddingBottom = "pb-[80px]" }) => {
9042
+ var QuizFill = ({ paddingBottom }) => {
9002
9043
  const { variant } = useQuizStore();
9003
9044
  const options = [
9004
9045
  "ci\xEAncia",
@@ -9356,7 +9397,7 @@ var QuizQuestionList = ({
9356
9397
  ([subjectId, questions]) => /* @__PURE__ */ jsxs32("section", { className: "flex flex-col gap-2", children: [
9357
9398
  /* @__PURE__ */ jsxs32("span", { className: "pt-6 pb-4 flex flex-row gap-2", children: [
9358
9399
  /* @__PURE__ */ jsx39("div", { className: "bg-primary-500 p-1 rounded-sm flex items-center justify-center", children: /* @__PURE__ */ jsx39(BookOpen, { size: 17, className: "text-white" }) }),
9359
- /* @__PURE__ */ jsx39("p", { className: "text-text-800 font-bold text-lg", children: subjectId })
9400
+ /* @__PURE__ */ jsx39("p", { className: "text-text-800 font-bold text-lg", children: questions?.[0]?.knowledgeMatrix?.[0]?.subject?.name ?? "Sem mat\xE9ria" })
9360
9401
  ] }),
9361
9402
  /* @__PURE__ */ jsx39("ul", { className: "flex flex-col gap-2", children: questions.map((question) => {
9362
9403
  const status = getQuestionStatus(question.id);
@@ -9787,28 +9828,24 @@ var QuizResultPerformance = forwardRef19(
9787
9828
  }
9788
9829
  );
9789
9830
  var QuizListResult = forwardRef19(({ className, onSubjectClick, ...props }, ref) => {
9790
- const {
9791
- getQuestionsGroupedBySubject,
9792
- isQuestionAnswered,
9793
- getUserAnswerByQuestionId
9794
- } = useQuizStore();
9831
+ const { getQuestionsGroupedBySubject } = useQuizStore();
9795
9832
  const groupedQuestions = getQuestionsGroupedBySubject();
9796
9833
  const subjectsStats = Object.entries(groupedQuestions).map(
9797
9834
  ([subjectId, questions]) => {
9798
9835
  let correct = 0;
9799
9836
  let incorrect = 0;
9800
9837
  questions.forEach((question) => {
9801
- if (isQuestionAnswered(question.id)) {
9802
- const userAnswerItem = getUserAnswerByQuestionId(question.id);
9803
- if (userAnswerItem?.answerStatus == "RESPOSTA_CORRETA" /* RESPOSTA_CORRETA */) {
9804
- correct++;
9805
- } else {
9806
- incorrect++;
9807
- }
9838
+ if (question.answerStatus == "RESPOSTA_CORRETA" /* RESPOSTA_CORRETA */) {
9839
+ correct++;
9840
+ } else {
9841
+ incorrect++;
9808
9842
  }
9809
9843
  });
9810
9844
  return {
9811
- subject: subjectId,
9845
+ subject: {
9846
+ name: questions?.[0]?.knowledgeMatrix?.[0]?.subject?.name ?? "Sem mat\xE9ria",
9847
+ id: subjectId
9848
+ },
9812
9849
  correct,
9813
9850
  incorrect,
9814
9851
  total: questions.length
@@ -9820,44 +9857,42 @@ var QuizListResult = forwardRef19(({ className, onSubjectClick, ...props }, ref)
9820
9857
  /* @__PURE__ */ jsx39("ul", { className: "flex flex-col gap-2", children: subjectsStats.map((subject) => /* @__PURE__ */ jsx39("li", { children: /* @__PURE__ */ jsx39(
9821
9858
  CardResults,
9822
9859
  {
9823
- onClick: () => onSubjectClick?.(subject.subject),
9860
+ onClick: () => onSubjectClick?.(subject.subject.id),
9824
9861
  className: "max-w-full",
9825
- header: subject.subject,
9862
+ header: subject.subject.name,
9826
9863
  correct_answers: subject.correct,
9827
9864
  incorrect_answers: subject.incorrect,
9828
9865
  icon: /* @__PURE__ */ jsx39(Book, { size: 20 }),
9829
9866
  direction: "row"
9830
9867
  }
9831
- ) }, subject.subject)) })
9868
+ ) }, subject.subject.id)) })
9832
9869
  ] });
9833
9870
  });
9834
9871
  var QuizListResultByMateria = ({
9835
9872
  subject,
9836
9873
  onQuestionClick
9837
9874
  }) => {
9838
- const {
9839
- getQuestionsGroupedBySubject,
9840
- getUserAnswerByQuestionId,
9841
- getQuestionIndex
9842
- } = useQuizStore();
9875
+ const { getQuestionsGroupedBySubject, getQuestionIndex } = useQuizStore();
9843
9876
  const groupedQuestions = getQuestionsGroupedBySubject();
9844
9877
  const answeredQuestions = groupedQuestions[subject] || [];
9845
9878
  return /* @__PURE__ */ jsxs32("div", { className: "w-full max-w-[1000px] flex flex-col mx-auto h-full relative not-lg:px-6", children: [
9846
- /* @__PURE__ */ jsx39("div", { className: "flex flex-row pt-4 justify-between", children: /* @__PURE__ */ jsx39("p", { className: "text-text-950 font-bold text-2xl", children: subject }) }),
9879
+ /* @__PURE__ */ jsx39("div", { className: "flex flex-row pt-4 justify-between", children: /* @__PURE__ */ jsx39("p", { className: "text-text-950 font-bold text-2xl", children: answeredQuestions?.[0]?.knowledgeMatrix?.[0]?.subject?.name ?? "Sem mat\xE9ria" }) }),
9847
9880
  /* @__PURE__ */ jsxs32("section", { className: "flex flex-col ", children: [
9848
9881
  /* @__PURE__ */ jsx39("p", { className: "pt-6 pb-4 text-text-950 font-bold text-lg", children: "Resultado das quest\xF5es" }),
9849
9882
  /* @__PURE__ */ jsx39("ul", { className: "flex flex-col gap-2 pt-4", children: answeredQuestions.map((question) => {
9850
- const questionIndex = getQuestionIndex(question.id);
9883
+ const questionIndex = getQuestionIndex(
9884
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
9885
+ question.questionId ?? question.id
9886
+ );
9851
9887
  return /* @__PURE__ */ jsx39("li", { children: /* @__PURE__ */ jsx39(
9852
9888
  CardStatus,
9853
9889
  {
9854
9890
  className: "max-w-full",
9855
9891
  header: `Quest\xE3o ${questionIndex.toString().padStart(2, "0")}`,
9856
9892
  status: (() => {
9857
- const userAnswer = getUserAnswerByQuestionId(question.id);
9858
- if (userAnswer?.answerStatus === "RESPOSTA_CORRETA" /* RESPOSTA_CORRETA */)
9893
+ if (question.answerStatus === "RESPOSTA_CORRETA" /* RESPOSTA_CORRETA */)
9859
9894
  return "correct";
9860
- if (userAnswer?.answerStatus === "RESPOSTA_INCORRETA" /* RESPOSTA_INCORRETA */)
9895
+ if (question.answerStatus === "RESPOSTA_INCORRETA" /* RESPOSTA_INCORRETA */)
9861
9896
  return "incorrect";
9862
9897
  return void 0;
9863
9898
  })(),
@@ -9869,6 +9904,7 @@ var QuizListResultByMateria = ({
9869
9904
  ] });
9870
9905
  };
9871
9906
  export {
9907
+ ANSWER_STATUS,
9872
9908
  Alert_default as Alert,
9873
9909
  AlertDialog,
9874
9910
  AlternativesList,
@@ -9919,6 +9955,9 @@ export {
9919
9955
  ProgressCircle_default as ProgressCircle,
9920
9956
  ProtectedRoute,
9921
9957
  PublicRoute,
9958
+ QUESTION_DIFFICULTY,
9959
+ QUESTION_STATUS,
9960
+ QUESTION_TYPE,
9922
9961
  Quiz,
9923
9962
  QuizAlternative,
9924
9963
  QuizConnectDots,