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.mjs CHANGED
@@ -4655,6 +4655,8 @@ var CardAudio = forwardRef12(
4655
4655
  const [duration, setDuration] = useState8(0);
4656
4656
  const [volume, setVolume] = useState8(1);
4657
4657
  const [showVolumeControl, setShowVolumeControl] = useState8(false);
4658
+ const [showSpeedMenu, setShowSpeedMenu] = useState8(false);
4659
+ const [playbackRate, setPlaybackRate] = useState8(1);
4658
4660
  const audioRef = useRef6(null);
4659
4661
  const formatTime2 = (time) => {
4660
4662
  const minutes = Math.floor(time / 60);
@@ -4708,6 +4710,16 @@ var CardAudio = forwardRef12(
4708
4710
  const toggleVolumeControl = () => {
4709
4711
  setShowVolumeControl(!showVolumeControl);
4710
4712
  };
4713
+ const toggleSpeedMenu = () => {
4714
+ setShowSpeedMenu(!showSpeedMenu);
4715
+ };
4716
+ const handleSpeedChange = (speed) => {
4717
+ setPlaybackRate(speed);
4718
+ if (audioRef.current) {
4719
+ audioRef.current.playbackRate = speed;
4720
+ }
4721
+ setShowSpeedMenu(false);
4722
+ };
4711
4723
  const getVolumeIcon = () => {
4712
4724
  if (volume === 0) {
4713
4725
  return /* @__PURE__ */ jsx26(SpeakerSimpleX, {});
@@ -4864,13 +4876,35 @@ var CardAudio = forwardRef12(
4864
4876
  }
4865
4877
  )
4866
4878
  ] }),
4867
- /* @__PURE__ */ jsx26(
4868
- DotsThreeVertical,
4869
- {
4870
- size: 24,
4871
- className: "text-text-950 cursor-pointer hover:text-primary-600"
4872
- }
4873
- )
4879
+ /* @__PURE__ */ jsxs20("div", { className: "relative", children: [
4880
+ /* @__PURE__ */ jsx26(
4881
+ "button",
4882
+ {
4883
+ type: "button",
4884
+ onClick: toggleSpeedMenu,
4885
+ className: "cursor-pointer text-text-950 hover:text-primary-600",
4886
+ "aria-label": "Op\xE7\xF5es de velocidade",
4887
+ children: /* @__PURE__ */ jsx26(DotsThreeVertical, { size: 24 })
4888
+ }
4889
+ ),
4890
+ showSpeedMenu && /* @__PURE__ */ jsx26("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__ */ jsx26("div", { className: "flex flex-col gap-1", children: [
4891
+ { speed: 1, label: "1x" },
4892
+ { speed: 1.5, label: "1.5x" },
4893
+ { speed: 2, label: "2x" }
4894
+ ].map(({ speed, label }) => /* @__PURE__ */ jsx26(
4895
+ "button",
4896
+ {
4897
+ type: "button",
4898
+ onClick: () => handleSpeedChange(speed),
4899
+ className: cn(
4900
+ "px-3 py-1 text-sm text-left rounded hover:bg-border-50 transition-colors",
4901
+ playbackRate === speed ? "bg-primary-950 text-secondary-100 font-medium" : "text-text-950"
4902
+ ),
4903
+ children: label
4904
+ },
4905
+ speed
4906
+ )) }) })
4907
+ ] })
4874
4908
  ]
4875
4909
  }
4876
4910
  );
@@ -8295,12 +8329,12 @@ var useQuizStore = create7()(
8295
8329
  return unansweredQuestions;
8296
8330
  },
8297
8331
  getQuestionsGroupedBySubject: () => {
8298
- const { getActiveQuiz } = get();
8299
- const activeQuiz = getActiveQuiz();
8300
- if (!activeQuiz) return {};
8332
+ const { getQuestionResult, getActiveQuiz, variant } = get();
8333
+ const questions = variant == "result" ? getQuestionResult()?.answers : getActiveQuiz()?.quiz.questions;
8334
+ if (!questions) return {};
8301
8335
  const groupedQuestions = {};
8302
- activeQuiz.quiz.questions.forEach((question) => {
8303
- const subjectId = question.knowledgeMatrix?.[0]?.subjectId || "Sem mat\xE9ria";
8336
+ questions.forEach((question) => {
8337
+ const subjectId = question.knowledgeMatrix?.[0]?.subject?.id || "Sem mat\xE9ria";
8304
8338
  if (!groupedQuestions[subjectId]) {
8305
8339
  groupedQuestions[subjectId] = [];
8306
8340
  }
@@ -8334,12 +8368,22 @@ var useQuizStore = create7()(
8334
8368
  return userAnswers;
8335
8369
  },
8336
8370
  setCurrentQuestion: (question) => {
8337
- const { getActiveQuiz } = get();
8371
+ const { getActiveQuiz, variant, questionsResult } = get();
8338
8372
  const activeQuiz = getActiveQuiz();
8339
8373
  if (!activeQuiz) return;
8340
- const questionIndex = activeQuiz.quiz.questions.findIndex(
8341
- (q) => q.id === question.id
8342
- );
8374
+ let questionIndex = 0;
8375
+ if (variant == "result") {
8376
+ if (!questionsResult) return;
8377
+ const questionResult = questionsResult.answers.find((q) => q.id === question.id) ?? questionsResult.answers.find((q) => q.questionId === question.id);
8378
+ if (!questionResult) return;
8379
+ questionIndex = activeQuiz.quiz.questions.findIndex(
8380
+ (q) => q.id === questionResult.questionId
8381
+ );
8382
+ } else {
8383
+ questionIndex = activeQuiz.quiz.questions.findIndex(
8384
+ (q) => q.id === question.id
8385
+ );
8386
+ }
8343
8387
  if (questionIndex === -1) {
8344
8388
  console.warn(
8345
8389
  `Question with id "${question.id}" not found in active quiz`
@@ -8370,20 +8414,23 @@ var useQuizStore = create7()(
8370
8414
  return userAnswer ? userAnswer.answerStatus : null;
8371
8415
  },
8372
8416
  getQuestionIndex: (questionId) => {
8373
- const { getActiveQuiz } = get();
8374
- const activeQuiz = getActiveQuiz();
8375
- if (!activeQuiz) return 0;
8376
- const questionIndex = activeQuiz.quiz.questions.findIndex(
8377
- (q) => q.id === questionId
8417
+ const { questionsResult } = get();
8418
+ if (!questionsResult) return 0;
8419
+ let idx = questionsResult.answers.findIndex(
8420
+ (q) => q.questionId === questionId
8378
8421
  );
8379
- return questionIndex + 1;
8422
+ if (idx === -1) {
8423
+ idx = questionsResult.answers.findIndex((q) => q.id === questionId);
8424
+ }
8425
+ return idx !== -1 ? idx + 1 : 0;
8380
8426
  },
8381
8427
  // Question Result
8382
8428
  getQuestionResultByQuestionId: (questionId) => {
8383
8429
  const { questionsResult } = get();
8384
- return questionsResult?.answers.find(
8430
+ const question = questionsResult?.answers.find(
8385
8431
  (answer) => answer.questionId === questionId
8386
- ) || null;
8432
+ );
8433
+ return question || null;
8387
8434
  },
8388
8435
  getQuestionResultStatistics: () => {
8389
8436
  const { questionsResult } = get();
@@ -8534,8 +8581,8 @@ var QuizHeader = () => {
8534
8581
  HeaderAlternative,
8535
8582
  {
8536
8583
  title: currentQuestion ? `Quest\xE3o ${currentQuestionIndex + 1}` : "Quest\xE3o",
8537
- subTitle: currentQuestion?.knowledgeMatrix?.[0]?.topicId ?? "",
8538
- content: currentQuestion?.questionText ?? ""
8584
+ subTitle: currentQuestion?.knowledgeMatrix?.[0]?.topic?.name ?? "",
8585
+ content: currentQuestion?.statement ?? ""
8539
8586
  }
8540
8587
  );
8541
8588
  };
@@ -8584,10 +8631,10 @@ var QuizAlternative = ({ paddingBottom }) => {
8584
8631
  const alternatives = currentQuestion?.options?.map((option) => {
8585
8632
  let status = "neutral" /* NEUTRAL */;
8586
8633
  if (variant === "result") {
8587
- const isCorrectOption = currentQuestion.correctOptionIds?.includes(
8588
- option.id
8634
+ const isCorrectOption = currentQuestionResult?.options?.find((op) => op.id === option.id)?.isCorrect || false;
8635
+ const isSelected = currentQuestionResult?.selectedOptions.some(
8636
+ (selectedOption) => selectedOption.optionId === option.id
8589
8637
  );
8590
- const isSelected = currentQuestionResult?.optionId === option.id;
8591
8638
  if (isCorrectOption) {
8592
8639
  status = "correct" /* CORRECT */;
8593
8640
  } else if (isSelected && !isCorrectOption) {
@@ -8613,8 +8660,8 @@ var QuizAlternative = ({ paddingBottom }) => {
8613
8660
  name: `question-${currentQuestion?.id || "1"}`,
8614
8661
  layout: "compact",
8615
8662
  alternatives,
8616
- value: variant === "result" ? currentQuestionResult?.optionId || "" : currentAnswer?.optionId || "",
8617
- selectedValue: variant === "result" ? currentQuestionResult?.optionId || "" : currentAnswer?.optionId || "",
8663
+ value: variant === "result" ? currentQuestionResult?.selectedOptions[0]?.optionId || "" : currentAnswer?.optionId || "",
8664
+ selectedValue: variant === "result" ? currentQuestionResult?.selectedOptions[0]?.optionId || "" : currentAnswer?.optionId || "",
8618
8665
  onValueChange: (value) => {
8619
8666
  if (currentQuestion) {
8620
8667
  selectAnswer(currentQuestion.id, value);
@@ -8659,15 +8706,16 @@ var QuizMultipleChoice = ({ paddingBottom }) => {
8659
8706
  prevSelectedValuesRef.current = selectedValues;
8660
8707
  return selectedValues;
8661
8708
  }
8662
- if (variant == "result" && currentQuestionResult?.options.length && currentQuestionResult?.options.length > 0) {
8663
- return currentQuestionResult?.options.map((op) => op.id) || [];
8709
+ if (variant == "result") {
8710
+ return currentQuestionResult?.selectedOptions.map((op) => op.optionId) || [];
8711
+ } else {
8712
+ return prevSelectedValuesRef.current;
8664
8713
  }
8665
- return prevSelectedValuesRef.current;
8666
8714
  }, [
8667
8715
  selectedValues,
8668
8716
  currentQuestion?.id,
8669
8717
  variant,
8670
- currentQuestionResult?.optionId
8718
+ currentQuestionResult?.selectedOptions
8671
8719
  ]);
8672
8720
  const handleSelectedValues = useCallback4(
8673
8721
  (values) => {
@@ -8684,11 +8732,9 @@ var QuizMultipleChoice = ({ paddingBottom }) => {
8684
8732
  const choices = currentQuestion?.options?.map((option) => {
8685
8733
  let status = "neutral" /* NEUTRAL */;
8686
8734
  if (variant === "result") {
8687
- const isCorrectOption = currentQuestion.correctOptionIds?.includes(
8688
- option.id
8689
- );
8690
- const isSelected = currentQuestionResult?.options.find(
8691
- (op) => op.id === option.id
8735
+ const isCorrectOption = currentQuestionResult?.options?.find((op) => op.id === option.id)?.isCorrect || false;
8736
+ const isSelected = currentQuestionResult?.selectedOptions?.some(
8737
+ (op) => op.optionId === option.id
8692
8738
  );
8693
8739
  if (isCorrectOption) {
8694
8740
  status = "correct" /* CORRECT */;
@@ -8964,7 +9010,7 @@ var QuizConnectDots = ({ paddingBottom }) => {
8964
9010
  }) }) })
8965
9011
  ] });
8966
9012
  };
8967
- var QuizFill = ({ paddingBottom = "pb-[80px]" }) => {
9013
+ var QuizFill = ({ paddingBottom }) => {
8968
9014
  const { variant } = useQuizStore();
8969
9015
  const options = [
8970
9016
  "ci\xEAncia",
@@ -9322,7 +9368,7 @@ var QuizQuestionList = ({
9322
9368
  ([subjectId, questions]) => /* @__PURE__ */ jsxs32("section", { className: "flex flex-col gap-2", children: [
9323
9369
  /* @__PURE__ */ jsxs32("span", { className: "pt-6 pb-4 flex flex-row gap-2", children: [
9324
9370
  /* @__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" }) }),
9325
- /* @__PURE__ */ jsx39("p", { className: "text-text-800 font-bold text-lg", children: subjectId })
9371
+ /* @__PURE__ */ jsx39("p", { className: "text-text-800 font-bold text-lg", children: questions?.[0]?.knowledgeMatrix?.[0]?.subject?.name ?? "Sem mat\xE9ria" })
9326
9372
  ] }),
9327
9373
  /* @__PURE__ */ jsx39("ul", { className: "flex flex-col gap-2", children: questions.map((question) => {
9328
9374
  const status = getQuestionStatus(question.id);
@@ -9753,28 +9799,24 @@ var QuizResultPerformance = forwardRef19(
9753
9799
  }
9754
9800
  );
9755
9801
  var QuizListResult = forwardRef19(({ className, onSubjectClick, ...props }, ref) => {
9756
- const {
9757
- getQuestionsGroupedBySubject,
9758
- isQuestionAnswered,
9759
- getUserAnswerByQuestionId
9760
- } = useQuizStore();
9802
+ const { getQuestionsGroupedBySubject } = useQuizStore();
9761
9803
  const groupedQuestions = getQuestionsGroupedBySubject();
9762
9804
  const subjectsStats = Object.entries(groupedQuestions).map(
9763
9805
  ([subjectId, questions]) => {
9764
9806
  let correct = 0;
9765
9807
  let incorrect = 0;
9766
9808
  questions.forEach((question) => {
9767
- if (isQuestionAnswered(question.id)) {
9768
- const userAnswerItem = getUserAnswerByQuestionId(question.id);
9769
- if (userAnswerItem?.answerStatus == "RESPOSTA_CORRETA" /* RESPOSTA_CORRETA */) {
9770
- correct++;
9771
- } else {
9772
- incorrect++;
9773
- }
9809
+ if (question.answerStatus == "RESPOSTA_CORRETA" /* RESPOSTA_CORRETA */) {
9810
+ correct++;
9811
+ } else {
9812
+ incorrect++;
9774
9813
  }
9775
9814
  });
9776
9815
  return {
9777
- subject: subjectId,
9816
+ subject: {
9817
+ name: questions?.[0]?.knowledgeMatrix?.[0]?.subject?.name ?? "Sem mat\xE9ria",
9818
+ id: subjectId
9819
+ },
9778
9820
  correct,
9779
9821
  incorrect,
9780
9822
  total: questions.length
@@ -9786,44 +9828,42 @@ var QuizListResult = forwardRef19(({ className, onSubjectClick, ...props }, ref)
9786
9828
  /* @__PURE__ */ jsx39("ul", { className: "flex flex-col gap-2", children: subjectsStats.map((subject) => /* @__PURE__ */ jsx39("li", { children: /* @__PURE__ */ jsx39(
9787
9829
  CardResults,
9788
9830
  {
9789
- onClick: () => onSubjectClick?.(subject.subject),
9831
+ onClick: () => onSubjectClick?.(subject.subject.id),
9790
9832
  className: "max-w-full",
9791
- header: subject.subject,
9833
+ header: subject.subject.name,
9792
9834
  correct_answers: subject.correct,
9793
9835
  incorrect_answers: subject.incorrect,
9794
9836
  icon: /* @__PURE__ */ jsx39(Book, { size: 20 }),
9795
9837
  direction: "row"
9796
9838
  }
9797
- ) }, subject.subject)) })
9839
+ ) }, subject.subject.id)) })
9798
9840
  ] });
9799
9841
  });
9800
9842
  var QuizListResultByMateria = ({
9801
9843
  subject,
9802
9844
  onQuestionClick
9803
9845
  }) => {
9804
- const {
9805
- getQuestionsGroupedBySubject,
9806
- getUserAnswerByQuestionId,
9807
- getQuestionIndex
9808
- } = useQuizStore();
9846
+ const { getQuestionsGroupedBySubject, getQuestionIndex } = useQuizStore();
9809
9847
  const groupedQuestions = getQuestionsGroupedBySubject();
9810
9848
  const answeredQuestions = groupedQuestions[subject] || [];
9811
9849
  return /* @__PURE__ */ jsxs32("div", { className: "w-full max-w-[1000px] flex flex-col mx-auto h-full relative not-lg:px-6", children: [
9812
- /* @__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 }) }),
9850
+ /* @__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" }) }),
9813
9851
  /* @__PURE__ */ jsxs32("section", { className: "flex flex-col ", children: [
9814
9852
  /* @__PURE__ */ jsx39("p", { className: "pt-6 pb-4 text-text-950 font-bold text-lg", children: "Resultado das quest\xF5es" }),
9815
9853
  /* @__PURE__ */ jsx39("ul", { className: "flex flex-col gap-2 pt-4", children: answeredQuestions.map((question) => {
9816
- const questionIndex = getQuestionIndex(question.id);
9854
+ const questionIndex = getQuestionIndex(
9855
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
9856
+ question.questionId ?? question.id
9857
+ );
9817
9858
  return /* @__PURE__ */ jsx39("li", { children: /* @__PURE__ */ jsx39(
9818
9859
  CardStatus,
9819
9860
  {
9820
9861
  className: "max-w-full",
9821
9862
  header: `Quest\xE3o ${questionIndex.toString().padStart(2, "0")}`,
9822
9863
  status: (() => {
9823
- const userAnswer = getUserAnswerByQuestionId(question.id);
9824
- if (userAnswer?.answerStatus === "RESPOSTA_CORRETA" /* RESPOSTA_CORRETA */)
9864
+ if (question.answerStatus === "RESPOSTA_CORRETA" /* RESPOSTA_CORRETA */)
9825
9865
  return "correct";
9826
- if (userAnswer?.answerStatus === "RESPOSTA_INCORRETA" /* RESPOSTA_INCORRETA */)
9866
+ if (question.answerStatus === "RESPOSTA_INCORRETA" /* RESPOSTA_INCORRETA */)
9827
9867
  return "incorrect";
9828
9868
  return void 0;
9829
9869
  })(),