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.
@@ -1349,12 +1349,12 @@ var useQuizStore = create2()(
1349
1349
  return unansweredQuestions;
1350
1350
  },
1351
1351
  getQuestionsGroupedBySubject: () => {
1352
- const { getActiveQuiz } = get();
1353
- const activeQuiz = getActiveQuiz();
1354
- if (!activeQuiz) return {};
1352
+ const { getQuestionResult, getActiveQuiz, variant } = get();
1353
+ const questions = variant == "result" ? getQuestionResult()?.answers : getActiveQuiz()?.quiz.questions;
1354
+ if (!questions) return {};
1355
1355
  const groupedQuestions = {};
1356
- activeQuiz.quiz.questions.forEach((question) => {
1357
- const subjectId = question.knowledgeMatrix?.[0]?.subjectId || "Sem mat\xE9ria";
1356
+ questions.forEach((question) => {
1357
+ const subjectId = question.knowledgeMatrix?.[0]?.subject?.id || "Sem mat\xE9ria";
1358
1358
  if (!groupedQuestions[subjectId]) {
1359
1359
  groupedQuestions[subjectId] = [];
1360
1360
  }
@@ -1388,12 +1388,22 @@ var useQuizStore = create2()(
1388
1388
  return userAnswers;
1389
1389
  },
1390
1390
  setCurrentQuestion: (question) => {
1391
- const { getActiveQuiz } = get();
1391
+ const { getActiveQuiz, variant, questionsResult } = get();
1392
1392
  const activeQuiz = getActiveQuiz();
1393
1393
  if (!activeQuiz) return;
1394
- const questionIndex = activeQuiz.quiz.questions.findIndex(
1395
- (q) => q.id === question.id
1396
- );
1394
+ let questionIndex = 0;
1395
+ if (variant == "result") {
1396
+ if (!questionsResult) return;
1397
+ const questionResult = questionsResult.answers.find((q) => q.id === question.id) ?? questionsResult.answers.find((q) => q.questionId === question.id);
1398
+ if (!questionResult) return;
1399
+ questionIndex = activeQuiz.quiz.questions.findIndex(
1400
+ (q) => q.id === questionResult.questionId
1401
+ );
1402
+ } else {
1403
+ questionIndex = activeQuiz.quiz.questions.findIndex(
1404
+ (q) => q.id === question.id
1405
+ );
1406
+ }
1397
1407
  if (questionIndex === -1) {
1398
1408
  console.warn(
1399
1409
  `Question with id "${question.id}" not found in active quiz`
@@ -1424,20 +1434,23 @@ var useQuizStore = create2()(
1424
1434
  return userAnswer ? userAnswer.answerStatus : null;
1425
1435
  },
1426
1436
  getQuestionIndex: (questionId) => {
1427
- const { getActiveQuiz } = get();
1428
- const activeQuiz = getActiveQuiz();
1429
- if (!activeQuiz) return 0;
1430
- const questionIndex = activeQuiz.quiz.questions.findIndex(
1431
- (q) => q.id === questionId
1437
+ const { questionsResult } = get();
1438
+ if (!questionsResult) return 0;
1439
+ let idx = questionsResult.answers.findIndex(
1440
+ (q) => q.questionId === questionId
1432
1441
  );
1433
- return questionIndex + 1;
1442
+ if (idx === -1) {
1443
+ idx = questionsResult.answers.findIndex((q) => q.id === questionId);
1444
+ }
1445
+ return idx !== -1 ? idx + 1 : 0;
1434
1446
  },
1435
1447
  // Question Result
1436
1448
  getQuestionResultByQuestionId: (questionId) => {
1437
1449
  const { questionsResult } = get();
1438
- return questionsResult?.answers.find(
1450
+ const question = questionsResult?.answers.find(
1439
1451
  (answer) => answer.questionId === questionId
1440
- ) || null;
1452
+ );
1453
+ return question || null;
1441
1454
  },
1442
1455
  getQuestionResultStatistics: () => {
1443
1456
  const { questionsResult } = get();
@@ -3225,6 +3238,8 @@ var CardAudio = forwardRef6(
3225
3238
  const [duration, setDuration] = useState3(0);
3226
3239
  const [volume, setVolume] = useState3(1);
3227
3240
  const [showVolumeControl, setShowVolumeControl] = useState3(false);
3241
+ const [showSpeedMenu, setShowSpeedMenu] = useState3(false);
3242
+ const [playbackRate, setPlaybackRate] = useState3(1);
3228
3243
  const audioRef = useRef3(null);
3229
3244
  const formatTime = (time) => {
3230
3245
  const minutes = Math.floor(time / 60);
@@ -3278,6 +3293,16 @@ var CardAudio = forwardRef6(
3278
3293
  const toggleVolumeControl = () => {
3279
3294
  setShowVolumeControl(!showVolumeControl);
3280
3295
  };
3296
+ const toggleSpeedMenu = () => {
3297
+ setShowSpeedMenu(!showSpeedMenu);
3298
+ };
3299
+ const handleSpeedChange = (speed) => {
3300
+ setPlaybackRate(speed);
3301
+ if (audioRef.current) {
3302
+ audioRef.current.playbackRate = speed;
3303
+ }
3304
+ setShowSpeedMenu(false);
3305
+ };
3281
3306
  const getVolumeIcon = () => {
3282
3307
  if (volume === 0) {
3283
3308
  return /* @__PURE__ */ jsx11(SpeakerSimpleX, {});
@@ -3434,13 +3459,35 @@ var CardAudio = forwardRef6(
3434
3459
  }
3435
3460
  )
3436
3461
  ] }),
3437
- /* @__PURE__ */ jsx11(
3438
- DotsThreeVertical,
3439
- {
3440
- size: 24,
3441
- className: "text-text-950 cursor-pointer hover:text-primary-600"
3442
- }
3443
- )
3462
+ /* @__PURE__ */ jsxs9("div", { className: "relative", children: [
3463
+ /* @__PURE__ */ jsx11(
3464
+ "button",
3465
+ {
3466
+ type: "button",
3467
+ onClick: toggleSpeedMenu,
3468
+ className: "cursor-pointer text-text-950 hover:text-primary-600",
3469
+ "aria-label": "Op\xE7\xF5es de velocidade",
3470
+ children: /* @__PURE__ */ jsx11(DotsThreeVertical, { size: 24 })
3471
+ }
3472
+ ),
3473
+ showSpeedMenu && /* @__PURE__ */ jsx11("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__ */ jsx11("div", { className: "flex flex-col gap-1", children: [
3474
+ { speed: 1, label: "1x" },
3475
+ { speed: 1.5, label: "1.5x" },
3476
+ { speed: 2, label: "2x" }
3477
+ ].map(({ speed, label }) => /* @__PURE__ */ jsx11(
3478
+ "button",
3479
+ {
3480
+ type: "button",
3481
+ onClick: () => handleSpeedChange(speed),
3482
+ className: cn(
3483
+ "px-3 py-1 text-sm text-left rounded hover:bg-border-50 transition-colors",
3484
+ playbackRate === speed ? "bg-primary-950 text-secondary-100 font-medium" : "text-text-950"
3485
+ ),
3486
+ children: label
3487
+ },
3488
+ speed
3489
+ )) }) })
3490
+ ] })
3444
3491
  ]
3445
3492
  }
3446
3493
  );
@@ -4656,8 +4703,8 @@ var QuizHeader = () => {
4656
4703
  HeaderAlternative,
4657
4704
  {
4658
4705
  title: currentQuestion ? `Quest\xE3o ${currentQuestionIndex + 1}` : "Quest\xE3o",
4659
- subTitle: currentQuestion?.knowledgeMatrix?.[0]?.topicId ?? "",
4660
- content: currentQuestion?.questionText ?? ""
4706
+ subTitle: currentQuestion?.knowledgeMatrix?.[0]?.topic?.name ?? "",
4707
+ content: currentQuestion?.statement ?? ""
4661
4708
  }
4662
4709
  );
4663
4710
  };
@@ -4706,10 +4753,10 @@ var QuizAlternative = ({ paddingBottom }) => {
4706
4753
  const alternatives = currentQuestion?.options?.map((option) => {
4707
4754
  let status = "neutral" /* NEUTRAL */;
4708
4755
  if (variant === "result") {
4709
- const isCorrectOption = currentQuestion.correctOptionIds?.includes(
4710
- option.id
4756
+ const isCorrectOption = currentQuestionResult?.options?.find((op) => op.id === option.id)?.isCorrect || false;
4757
+ const isSelected = currentQuestionResult?.selectedOptions.some(
4758
+ (selectedOption) => selectedOption.optionId === option.id
4711
4759
  );
4712
- const isSelected = currentQuestionResult?.optionId === option.id;
4713
4760
  if (isCorrectOption) {
4714
4761
  status = "correct" /* CORRECT */;
4715
4762
  } else if (isSelected && !isCorrectOption) {
@@ -4735,8 +4782,8 @@ var QuizAlternative = ({ paddingBottom }) => {
4735
4782
  name: `question-${currentQuestion?.id || "1"}`,
4736
4783
  layout: "compact",
4737
4784
  alternatives,
4738
- value: variant === "result" ? currentQuestionResult?.optionId || "" : currentAnswer?.optionId || "",
4739
- selectedValue: variant === "result" ? currentQuestionResult?.optionId || "" : currentAnswer?.optionId || "",
4785
+ value: variant === "result" ? currentQuestionResult?.selectedOptions[0]?.optionId || "" : currentAnswer?.optionId || "",
4786
+ selectedValue: variant === "result" ? currentQuestionResult?.selectedOptions[0]?.optionId || "" : currentAnswer?.optionId || "",
4740
4787
  onValueChange: (value) => {
4741
4788
  if (currentQuestion) {
4742
4789
  selectAnswer(currentQuestion.id, value);
@@ -4781,15 +4828,16 @@ var QuizMultipleChoice = ({ paddingBottom }) => {
4781
4828
  prevSelectedValuesRef.current = selectedValues;
4782
4829
  return selectedValues;
4783
4830
  }
4784
- if (variant == "result" && currentQuestionResult?.options.length && currentQuestionResult?.options.length > 0) {
4785
- return currentQuestionResult?.options.map((op) => op.id) || [];
4831
+ if (variant == "result") {
4832
+ return currentQuestionResult?.selectedOptions.map((op) => op.optionId) || [];
4833
+ } else {
4834
+ return prevSelectedValuesRef.current;
4786
4835
  }
4787
- return prevSelectedValuesRef.current;
4788
4836
  }, [
4789
4837
  selectedValues,
4790
4838
  currentQuestion?.id,
4791
4839
  variant,
4792
- currentQuestionResult?.optionId
4840
+ currentQuestionResult?.selectedOptions
4793
4841
  ]);
4794
4842
  const handleSelectedValues = useCallback(
4795
4843
  (values) => {
@@ -4806,11 +4854,9 @@ var QuizMultipleChoice = ({ paddingBottom }) => {
4806
4854
  const choices = currentQuestion?.options?.map((option) => {
4807
4855
  let status = "neutral" /* NEUTRAL */;
4808
4856
  if (variant === "result") {
4809
- const isCorrectOption = currentQuestion.correctOptionIds?.includes(
4810
- option.id
4811
- );
4812
- const isSelected = currentQuestionResult?.options.find(
4813
- (op) => op.id === option.id
4857
+ const isCorrectOption = currentQuestionResult?.options?.find((op) => op.id === option.id)?.isCorrect || false;
4858
+ const isSelected = currentQuestionResult?.selectedOptions?.some(
4859
+ (op) => op.optionId === option.id
4814
4860
  );
4815
4861
  if (isCorrectOption) {
4816
4862
  status = "correct" /* CORRECT */;
@@ -5086,7 +5132,7 @@ var QuizConnectDots = ({ paddingBottom }) => {
5086
5132
  }) }) })
5087
5133
  ] });
5088
5134
  };
5089
- var QuizFill = ({ paddingBottom = "pb-[80px]" }) => {
5135
+ var QuizFill = ({ paddingBottom }) => {
5090
5136
  const { variant } = useQuizStore();
5091
5137
  const options = [
5092
5138
  "ci\xEAncia",
@@ -5444,7 +5490,7 @@ var QuizQuestionList = ({
5444
5490
  ([subjectId, questions]) => /* @__PURE__ */ jsxs14("section", { className: "flex flex-col gap-2", children: [
5445
5491
  /* @__PURE__ */ jsxs14("span", { className: "pt-6 pb-4 flex flex-row gap-2", children: [
5446
5492
  /* @__PURE__ */ jsx17("div", { className: "bg-primary-500 p-1 rounded-sm flex items-center justify-center", children: /* @__PURE__ */ jsx17(BookOpen, { size: 17, className: "text-white" }) }),
5447
- /* @__PURE__ */ jsx17("p", { className: "text-text-800 font-bold text-lg", children: subjectId })
5493
+ /* @__PURE__ */ jsx17("p", { className: "text-text-800 font-bold text-lg", children: questions?.[0]?.knowledgeMatrix?.[0]?.subject?.name ?? "Sem mat\xE9ria" })
5448
5494
  ] }),
5449
5495
  /* @__PURE__ */ jsx17("ul", { className: "flex flex-col gap-2", children: questions.map((question) => {
5450
5496
  const status = getQuestionStatus(question.id);
@@ -5875,28 +5921,24 @@ var QuizResultPerformance = forwardRef10(
5875
5921
  }
5876
5922
  );
5877
5923
  var QuizListResult = forwardRef10(({ className, onSubjectClick, ...props }, ref) => {
5878
- const {
5879
- getQuestionsGroupedBySubject,
5880
- isQuestionAnswered,
5881
- getUserAnswerByQuestionId
5882
- } = useQuizStore();
5924
+ const { getQuestionsGroupedBySubject } = useQuizStore();
5883
5925
  const groupedQuestions = getQuestionsGroupedBySubject();
5884
5926
  const subjectsStats = Object.entries(groupedQuestions).map(
5885
5927
  ([subjectId, questions]) => {
5886
5928
  let correct = 0;
5887
5929
  let incorrect = 0;
5888
5930
  questions.forEach((question) => {
5889
- if (isQuestionAnswered(question.id)) {
5890
- const userAnswerItem = getUserAnswerByQuestionId(question.id);
5891
- if (userAnswerItem?.answerStatus == "RESPOSTA_CORRETA" /* RESPOSTA_CORRETA */) {
5892
- correct++;
5893
- } else {
5894
- incorrect++;
5895
- }
5931
+ if (question.answerStatus == "RESPOSTA_CORRETA" /* RESPOSTA_CORRETA */) {
5932
+ correct++;
5933
+ } else {
5934
+ incorrect++;
5896
5935
  }
5897
5936
  });
5898
5937
  return {
5899
- subject: subjectId,
5938
+ subject: {
5939
+ name: questions?.[0]?.knowledgeMatrix?.[0]?.subject?.name ?? "Sem mat\xE9ria",
5940
+ id: subjectId
5941
+ },
5900
5942
  correct,
5901
5943
  incorrect,
5902
5944
  total: questions.length
@@ -5908,44 +5950,42 @@ var QuizListResult = forwardRef10(({ className, onSubjectClick, ...props }, ref)
5908
5950
  /* @__PURE__ */ jsx17("ul", { className: "flex flex-col gap-2", children: subjectsStats.map((subject) => /* @__PURE__ */ jsx17("li", { children: /* @__PURE__ */ jsx17(
5909
5951
  CardResults,
5910
5952
  {
5911
- onClick: () => onSubjectClick?.(subject.subject),
5953
+ onClick: () => onSubjectClick?.(subject.subject.id),
5912
5954
  className: "max-w-full",
5913
- header: subject.subject,
5955
+ header: subject.subject.name,
5914
5956
  correct_answers: subject.correct,
5915
5957
  incorrect_answers: subject.incorrect,
5916
5958
  icon: /* @__PURE__ */ jsx17(Book, { size: 20 }),
5917
5959
  direction: "row"
5918
5960
  }
5919
- ) }, subject.subject)) })
5961
+ ) }, subject.subject.id)) })
5920
5962
  ] });
5921
5963
  });
5922
5964
  var QuizListResultByMateria = ({
5923
5965
  subject,
5924
5966
  onQuestionClick
5925
5967
  }) => {
5926
- const {
5927
- getQuestionsGroupedBySubject,
5928
- getUserAnswerByQuestionId,
5929
- getQuestionIndex
5930
- } = useQuizStore();
5968
+ const { getQuestionsGroupedBySubject, getQuestionIndex } = useQuizStore();
5931
5969
  const groupedQuestions = getQuestionsGroupedBySubject();
5932
5970
  const answeredQuestions = groupedQuestions[subject] || [];
5933
5971
  return /* @__PURE__ */ jsxs14("div", { className: "w-full max-w-[1000px] flex flex-col mx-auto h-full relative not-lg:px-6", children: [
5934
- /* @__PURE__ */ jsx17("div", { className: "flex flex-row pt-4 justify-between", children: /* @__PURE__ */ jsx17("p", { className: "text-text-950 font-bold text-2xl", children: subject }) }),
5972
+ /* @__PURE__ */ jsx17("div", { className: "flex flex-row pt-4 justify-between", children: /* @__PURE__ */ jsx17("p", { className: "text-text-950 font-bold text-2xl", children: answeredQuestions?.[0]?.knowledgeMatrix?.[0]?.subject?.name ?? "Sem mat\xE9ria" }) }),
5935
5973
  /* @__PURE__ */ jsxs14("section", { className: "flex flex-col ", children: [
5936
5974
  /* @__PURE__ */ jsx17("p", { className: "pt-6 pb-4 text-text-950 font-bold text-lg", children: "Resultado das quest\xF5es" }),
5937
5975
  /* @__PURE__ */ jsx17("ul", { className: "flex flex-col gap-2 pt-4", children: answeredQuestions.map((question) => {
5938
- const questionIndex = getQuestionIndex(question.id);
5976
+ const questionIndex = getQuestionIndex(
5977
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
5978
+ question.questionId ?? question.id
5979
+ );
5939
5980
  return /* @__PURE__ */ jsx17("li", { children: /* @__PURE__ */ jsx17(
5940
5981
  CardStatus,
5941
5982
  {
5942
5983
  className: "max-w-full",
5943
5984
  header: `Quest\xE3o ${questionIndex.toString().padStart(2, "0")}`,
5944
5985
  status: (() => {
5945
- const userAnswer = getUserAnswerByQuestionId(question.id);
5946
- if (userAnswer?.answerStatus === "RESPOSTA_CORRETA" /* RESPOSTA_CORRETA */)
5986
+ if (question.answerStatus === "RESPOSTA_CORRETA" /* RESPOSTA_CORRETA */)
5947
5987
  return "correct";
5948
- if (userAnswer?.answerStatus === "RESPOSTA_INCORRETA" /* RESPOSTA_INCORRETA */)
5988
+ if (question.answerStatus === "RESPOSTA_INCORRETA" /* RESPOSTA_INCORRETA */)
5949
5989
  return "incorrect";
5950
5990
  return void 0;
5951
5991
  })(),
@@ -5960,6 +6000,7 @@ export {
5960
6000
  Quiz,
5961
6001
  QuizAlternative,
5962
6002
  QuizConnectDots,
6003
+ QuizContainer,
5963
6004
  QuizContent,
5964
6005
  QuizDissertative,
5965
6006
  QuizFill,
@@ -5974,8 +6015,10 @@ export {
5974
6015
  QuizResultHeaderTitle,
5975
6016
  QuizResultPerformance,
5976
6017
  QuizResultTitle,
6018
+ QuizSubTitle,
5977
6019
  QuizTitle,
5978
6020
  QuizTrueOrFalse,
5979
- getStatusBadge
6021
+ getStatusBadge,
6022
+ getStatusStyles
5980
6023
  };
5981
6024
  //# sourceMappingURL=index.mjs.map