analytica-frontend-lib 1.1.13 → 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
@@ -4725,6 +4725,8 @@ var CardAudio = (0, import_react14.forwardRef)(
4725
4725
  const [duration, setDuration] = (0, import_react14.useState)(0);
4726
4726
  const [volume, setVolume] = (0, import_react14.useState)(1);
4727
4727
  const [showVolumeControl, setShowVolumeControl] = (0, import_react14.useState)(false);
4728
+ const [showSpeedMenu, setShowSpeedMenu] = (0, import_react14.useState)(false);
4729
+ const [playbackRate, setPlaybackRate] = (0, import_react14.useState)(1);
4728
4730
  const audioRef = (0, import_react14.useRef)(null);
4729
4731
  const formatTime2 = (time) => {
4730
4732
  const minutes = Math.floor(time / 60);
@@ -4778,6 +4780,16 @@ var CardAudio = (0, import_react14.forwardRef)(
4778
4780
  const toggleVolumeControl = () => {
4779
4781
  setShowVolumeControl(!showVolumeControl);
4780
4782
  };
4783
+ const toggleSpeedMenu = () => {
4784
+ setShowSpeedMenu(!showSpeedMenu);
4785
+ };
4786
+ const handleSpeedChange = (speed) => {
4787
+ setPlaybackRate(speed);
4788
+ if (audioRef.current) {
4789
+ audioRef.current.playbackRate = speed;
4790
+ }
4791
+ setShowSpeedMenu(false);
4792
+ };
4781
4793
  const getVolumeIcon = () => {
4782
4794
  if (volume === 0) {
4783
4795
  return /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(import_phosphor_react12.SpeakerSimpleX, {});
@@ -4934,13 +4946,35 @@ var CardAudio = (0, import_react14.forwardRef)(
4934
4946
  }
4935
4947
  )
4936
4948
  ] }),
4937
- /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(
4938
- import_phosphor_react12.DotsThreeVertical,
4939
- {
4940
- size: 24,
4941
- className: "text-text-950 cursor-pointer hover:text-primary-600"
4942
- }
4943
- )
4949
+ /* @__PURE__ */ (0, import_jsx_runtime26.jsxs)("div", { className: "relative", children: [
4950
+ /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(
4951
+ "button",
4952
+ {
4953
+ type: "button",
4954
+ onClick: toggleSpeedMenu,
4955
+ className: "cursor-pointer text-text-950 hover:text-primary-600",
4956
+ "aria-label": "Op\xE7\xF5es de velocidade",
4957
+ children: /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(import_phosphor_react12.DotsThreeVertical, { size: 24 })
4958
+ }
4959
+ ),
4960
+ showSpeedMenu && /* @__PURE__ */ (0, import_jsx_runtime26.jsx)("div", { className: "absolute bottom-full right-0 mb-2 p-2 bg-background border border-border-100 rounded-lg shadow-lg min-w-24 z-10", children: /* @__PURE__ */ (0, import_jsx_runtime26.jsx)("div", { className: "flex flex-col gap-1", children: [
4961
+ { speed: 1, label: "1x" },
4962
+ { speed: 1.5, label: "1.5x" },
4963
+ { speed: 2, label: "2x" }
4964
+ ].map(({ speed, label }) => /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(
4965
+ "button",
4966
+ {
4967
+ type: "button",
4968
+ onClick: () => handleSpeedChange(speed),
4969
+ className: cn(
4970
+ "px-3 py-1 text-sm text-left rounded hover:bg-border-50 transition-colors",
4971
+ playbackRate === speed ? "bg-primary-950 text-secondary-100 font-medium" : "text-text-950"
4972
+ ),
4973
+ children: label
4974
+ },
4975
+ speed
4976
+ )) }) })
4977
+ ] })
4944
4978
  ]
4945
4979
  }
4946
4980
  );
@@ -8308,12 +8342,12 @@ var useQuizStore = (0, import_zustand7.create)()(
8308
8342
  return unansweredQuestions;
8309
8343
  },
8310
8344
  getQuestionsGroupedBySubject: () => {
8311
- const { getActiveQuiz } = get();
8312
- const activeQuiz = getActiveQuiz();
8313
- if (!activeQuiz) return {};
8345
+ const { getQuestionResult, getActiveQuiz, variant } = get();
8346
+ const questions = variant == "result" ? getQuestionResult()?.answers : getActiveQuiz()?.quiz.questions;
8347
+ if (!questions) return {};
8314
8348
  const groupedQuestions = {};
8315
- activeQuiz.quiz.questions.forEach((question) => {
8316
- const subjectId = question.knowledgeMatrix?.[0]?.subjectId || "Sem mat\xE9ria";
8349
+ questions.forEach((question) => {
8350
+ const subjectId = question.knowledgeMatrix?.[0]?.subject?.id || "Sem mat\xE9ria";
8317
8351
  if (!groupedQuestions[subjectId]) {
8318
8352
  groupedQuestions[subjectId] = [];
8319
8353
  }
@@ -8347,12 +8381,22 @@ var useQuizStore = (0, import_zustand7.create)()(
8347
8381
  return userAnswers;
8348
8382
  },
8349
8383
  setCurrentQuestion: (question) => {
8350
- const { getActiveQuiz } = get();
8384
+ const { getActiveQuiz, variant, questionsResult } = get();
8351
8385
  const activeQuiz = getActiveQuiz();
8352
8386
  if (!activeQuiz) return;
8353
- const questionIndex = activeQuiz.quiz.questions.findIndex(
8354
- (q) => q.id === question.id
8355
- );
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
+ }
8356
8400
  if (questionIndex === -1) {
8357
8401
  console.warn(
8358
8402
  `Question with id "${question.id}" not found in active quiz`
@@ -8383,20 +8427,23 @@ var useQuizStore = (0, import_zustand7.create)()(
8383
8427
  return userAnswer ? userAnswer.answerStatus : null;
8384
8428
  },
8385
8429
  getQuestionIndex: (questionId) => {
8386
- const { getActiveQuiz } = get();
8387
- const activeQuiz = getActiveQuiz();
8388
- if (!activeQuiz) return 0;
8389
- const questionIndex = activeQuiz.quiz.questions.findIndex(
8390
- (q) => q.id === questionId
8430
+ const { questionsResult } = get();
8431
+ if (!questionsResult) return 0;
8432
+ let idx = questionsResult.answers.findIndex(
8433
+ (q) => q.questionId === questionId
8391
8434
  );
8392
- return questionIndex + 1;
8435
+ if (idx === -1) {
8436
+ idx = questionsResult.answers.findIndex((q) => q.id === questionId);
8437
+ }
8438
+ return idx !== -1 ? idx + 1 : 0;
8393
8439
  },
8394
8440
  // Question Result
8395
8441
  getQuestionResultByQuestionId: (questionId) => {
8396
8442
  const { questionsResult } = get();
8397
- return questionsResult?.answers.find(
8443
+ const question = questionsResult?.answers.find(
8398
8444
  (answer) => answer.questionId === questionId
8399
- ) || null;
8445
+ );
8446
+ return question || null;
8400
8447
  },
8401
8448
  getQuestionResultStatistics: () => {
8402
8449
  const { questionsResult } = get();
@@ -8547,8 +8594,8 @@ var QuizHeader = () => {
8547
8594
  HeaderAlternative,
8548
8595
  {
8549
8596
  title: currentQuestion ? `Quest\xE3o ${currentQuestionIndex + 1}` : "Quest\xE3o",
8550
- subTitle: currentQuestion?.knowledgeMatrix?.[0]?.topicId ?? "",
8551
- content: currentQuestion?.questionText ?? ""
8597
+ subTitle: currentQuestion?.knowledgeMatrix?.[0]?.topic?.name ?? "",
8598
+ content: currentQuestion?.statement ?? ""
8552
8599
  }
8553
8600
  );
8554
8601
  };
@@ -8597,10 +8644,10 @@ var QuizAlternative = ({ paddingBottom }) => {
8597
8644
  const alternatives = currentQuestion?.options?.map((option) => {
8598
8645
  let status = "neutral" /* NEUTRAL */;
8599
8646
  if (variant === "result") {
8600
- const isCorrectOption = currentQuestion.correctOptionIds?.includes(
8601
- 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
8602
8650
  );
8603
- const isSelected = currentQuestionResult?.optionId === option.id;
8604
8651
  if (isCorrectOption) {
8605
8652
  status = "correct" /* CORRECT */;
8606
8653
  } else if (isSelected && !isCorrectOption) {
@@ -8626,8 +8673,8 @@ var QuizAlternative = ({ paddingBottom }) => {
8626
8673
  name: `question-${currentQuestion?.id || "1"}`,
8627
8674
  layout: "compact",
8628
8675
  alternatives,
8629
- value: variant === "result" ? currentQuestionResult?.optionId || "" : currentAnswer?.optionId || "",
8630
- 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 || "",
8631
8678
  onValueChange: (value) => {
8632
8679
  if (currentQuestion) {
8633
8680
  selectAnswer(currentQuestion.id, value);
@@ -8672,15 +8719,16 @@ var QuizMultipleChoice = ({ paddingBottom }) => {
8672
8719
  prevSelectedValuesRef.current = selectedValues;
8673
8720
  return selectedValues;
8674
8721
  }
8675
- if (variant == "result" && currentQuestionResult?.options.length && currentQuestionResult?.options.length > 0) {
8676
- 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;
8677
8726
  }
8678
- return prevSelectedValuesRef.current;
8679
8727
  }, [
8680
8728
  selectedValues,
8681
8729
  currentQuestion?.id,
8682
8730
  variant,
8683
- currentQuestionResult?.optionId
8731
+ currentQuestionResult?.selectedOptions
8684
8732
  ]);
8685
8733
  const handleSelectedValues = (0, import_react27.useCallback)(
8686
8734
  (values) => {
@@ -8697,11 +8745,9 @@ var QuizMultipleChoice = ({ paddingBottom }) => {
8697
8745
  const choices = currentQuestion?.options?.map((option) => {
8698
8746
  let status = "neutral" /* NEUTRAL */;
8699
8747
  if (variant === "result") {
8700
- const isCorrectOption = currentQuestion.correctOptionIds?.includes(
8701
- option.id
8702
- );
8703
- const isSelected = currentQuestionResult?.options.find(
8704
- (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
8705
8751
  );
8706
8752
  if (isCorrectOption) {
8707
8753
  status = "correct" /* CORRECT */;
@@ -8977,7 +9023,7 @@ var QuizConnectDots = ({ paddingBottom }) => {
8977
9023
  }) }) })
8978
9024
  ] });
8979
9025
  };
8980
- var QuizFill = ({ paddingBottom = "pb-[80px]" }) => {
9026
+ var QuizFill = ({ paddingBottom }) => {
8981
9027
  const { variant } = useQuizStore();
8982
9028
  const options = [
8983
9029
  "ci\xEAncia",
@@ -9335,7 +9381,7 @@ var QuizQuestionList = ({
9335
9381
  ([subjectId, questions]) => /* @__PURE__ */ (0, import_jsx_runtime39.jsxs)("section", { className: "flex flex-col gap-2", children: [
9336
9382
  /* @__PURE__ */ (0, import_jsx_runtime39.jsxs)("span", { className: "pt-6 pb-4 flex flex-row gap-2", children: [
9337
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" }) }),
9338
- /* @__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" })
9339
9385
  ] }),
9340
9386
  /* @__PURE__ */ (0, import_jsx_runtime39.jsx)("ul", { className: "flex flex-col gap-2", children: questions.map((question) => {
9341
9387
  const status = getQuestionStatus(question.id);
@@ -9766,28 +9812,24 @@ var QuizResultPerformance = (0, import_react27.forwardRef)(
9766
9812
  }
9767
9813
  );
9768
9814
  var QuizListResult = (0, import_react27.forwardRef)(({ className, onSubjectClick, ...props }, ref) => {
9769
- const {
9770
- getQuestionsGroupedBySubject,
9771
- isQuestionAnswered,
9772
- getUserAnswerByQuestionId
9773
- } = useQuizStore();
9815
+ const { getQuestionsGroupedBySubject } = useQuizStore();
9774
9816
  const groupedQuestions = getQuestionsGroupedBySubject();
9775
9817
  const subjectsStats = Object.entries(groupedQuestions).map(
9776
9818
  ([subjectId, questions]) => {
9777
9819
  let correct = 0;
9778
9820
  let incorrect = 0;
9779
9821
  questions.forEach((question) => {
9780
- if (isQuestionAnswered(question.id)) {
9781
- const userAnswerItem = getUserAnswerByQuestionId(question.id);
9782
- if (userAnswerItem?.answerStatus == "RESPOSTA_CORRETA" /* RESPOSTA_CORRETA */) {
9783
- correct++;
9784
- } else {
9785
- incorrect++;
9786
- }
9822
+ if (question.answerStatus == "RESPOSTA_CORRETA" /* RESPOSTA_CORRETA */) {
9823
+ correct++;
9824
+ } else {
9825
+ incorrect++;
9787
9826
  }
9788
9827
  });
9789
9828
  return {
9790
- subject: subjectId,
9829
+ subject: {
9830
+ name: questions?.[0]?.knowledgeMatrix?.[0]?.subject?.name ?? "Sem mat\xE9ria",
9831
+ id: subjectId
9832
+ },
9791
9833
  correct,
9792
9834
  incorrect,
9793
9835
  total: questions.length
@@ -9799,44 +9841,42 @@ var QuizListResult = (0, import_react27.forwardRef)(({ className, onSubjectClick
9799
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)(
9800
9842
  CardResults,
9801
9843
  {
9802
- onClick: () => onSubjectClick?.(subject.subject),
9844
+ onClick: () => onSubjectClick?.(subject.subject.id),
9803
9845
  className: "max-w-full",
9804
- header: subject.subject,
9846
+ header: subject.subject.name,
9805
9847
  correct_answers: subject.correct,
9806
9848
  incorrect_answers: subject.incorrect,
9807
9849
  icon: /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(import_phosphor_react20.Book, { size: 20 }),
9808
9850
  direction: "row"
9809
9851
  }
9810
- ) }, subject.subject)) })
9852
+ ) }, subject.subject.id)) })
9811
9853
  ] });
9812
9854
  });
9813
9855
  var QuizListResultByMateria = ({
9814
9856
  subject,
9815
9857
  onQuestionClick
9816
9858
  }) => {
9817
- const {
9818
- getQuestionsGroupedBySubject,
9819
- getUserAnswerByQuestionId,
9820
- getQuestionIndex
9821
- } = useQuizStore();
9859
+ const { getQuestionsGroupedBySubject, getQuestionIndex } = useQuizStore();
9822
9860
  const groupedQuestions = getQuestionsGroupedBySubject();
9823
9861
  const answeredQuestions = groupedQuestions[subject] || [];
9824
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: [
9825
- /* @__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" }) }),
9826
9864
  /* @__PURE__ */ (0, import_jsx_runtime39.jsxs)("section", { className: "flex flex-col ", children: [
9827
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" }),
9828
9866
  /* @__PURE__ */ (0, import_jsx_runtime39.jsx)("ul", { className: "flex flex-col gap-2 pt-4", children: answeredQuestions.map((question) => {
9829
- 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
+ );
9830
9871
  return /* @__PURE__ */ (0, import_jsx_runtime39.jsx)("li", { children: /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(
9831
9872
  CardStatus,
9832
9873
  {
9833
9874
  className: "max-w-full",
9834
9875
  header: `Quest\xE3o ${questionIndex.toString().padStart(2, "0")}`,
9835
9876
  status: (() => {
9836
- const userAnswer = getUserAnswerByQuestionId(question.id);
9837
- if (userAnswer?.answerStatus === "RESPOSTA_CORRETA" /* RESPOSTA_CORRETA */)
9877
+ if (question.answerStatus === "RESPOSTA_CORRETA" /* RESPOSTA_CORRETA */)
9838
9878
  return "correct";
9839
- if (userAnswer?.answerStatus === "RESPOSTA_INCORRETA" /* RESPOSTA_INCORRETA */)
9879
+ if (question.answerStatus === "RESPOSTA_INCORRETA" /* RESPOSTA_INCORRETA */)
9840
9880
  return "incorrect";
9841
9881
  return void 0;
9842
9882
  })(),