11import { Box , Divider , Text } from "@chakra-ui/react" ;
22import { QuizQuestion } from "@freecodecamp/ui" ;
3- import { useEffect , useRef } from "react" ;
3+ import { SyntheticEvent , useEffect , useRef } from "react" ;
44
55import { Answers , FullQuestion , UserExamAttempt } from "../utils/types" ;
66import { AudioPlayer } from "./audio-player" ;
77import { parseMarkdown } from "../utils/markdown" ;
88import { PrismFormatted } from "./prism-formatted" ;
9- import { logger } from "@sentry/react " ;
9+ import { captureEvent , createEvent , EventKind } from "../utils/superbase " ;
1010
1111type QuestionTypeFormProps = {
1212 fullQuestion : FullQuestion ;
@@ -21,16 +21,17 @@ export function QuestionSetForm({
2121 setNewSelectedAnswers,
2222 examAttempt,
2323} : QuestionTypeFormProps ) {
24- const captionsRef = useRef < HTMLDetailsElement > ( null ) ;
24+ const lastTrackedId = useRef < string | null > ( null ) ;
2525
26- useEffect ( ( ) => {
27- if ( captionsRef . current ?. open ) {
28- logger . info ( "captions opened" , {
29- exam : examAttempt . examId ,
30- question : fullQuestion . id ,
31- } ) ;
26+ function captionsToggled ( e : SyntheticEvent < HTMLDetailsElement , Event > ) {
27+ if ( e . currentTarget . open ) {
28+ captureEvent (
29+ createEvent ( EventKind . CAPTIONS_OPENED , examAttempt . id , {
30+ question : fullQuestion . id ,
31+ } )
32+ ) ;
3233 }
33- } , [ captionsRef . current ?. open ] ) ;
34+ }
3435
3536 useEffect ( ( ) => {
3637 setNewSelectedAnswers (
@@ -42,6 +43,15 @@ export function QuestionSetForm({
4243 )
4344 . map ( ( a ) => a . id )
4445 ) ;
46+
47+ if ( lastTrackedId . current !== fullQuestion . id ) {
48+ captureEvent (
49+ createEvent ( EventKind . QUESTION_VISIT , examAttempt . id , {
50+ question : fullQuestion . id ,
51+ } )
52+ ) ;
53+ lastTrackedId . current = fullQuestion . id ;
54+ }
4555 } , [ fullQuestion ] ) ;
4656
4757 return (
@@ -56,13 +66,13 @@ export function QuestionSetForm({
5666 < Divider />
5767 </ >
5868 ) }
59- { fullQuestion . audio && (
69+ { ! ! fullQuestion . audio ?. url && (
6070 < Box mb = { "2em" } mt = { "2em" } >
6171 < Text > Please listen to the following audio fragment:</ Text >
6272 { /* NOTE: `fullQuestion` is passed to cause the whole component to rerender - correctly resetting the audio */ }
6373 < AudioPlayer fullQuestion = { fullQuestion } />
6474 { fullQuestion . audio . captions && (
65- < details style = { { cursor : "pointer" } } ref = { captionsRef } >
75+ < details style = { { cursor : "pointer" } } onToggle = { captionsToggled } >
6676 < summary > Show captions</ summary >
6777 < Box marginTop = "1em" >
6878 < PrismFormatted
0 commit comments